def test_s3_location(self): serverless_func = Function("SomeHandler", Handler="index.handler", Runtime="nodejs", CodeUri=S3Location( Bucket="mybucket", Key="mykey", )) t = Template() t.add_resource(serverless_func) t.to_json()
def test_exactly_one_code(self): serverless_func = Function( "SomeHandler", Handler="index.handler", Runtime="nodejs", CodeUri=S3Location( Bucket="mybucket", Key="mykey", ), InlineCode="", ) t = Template() t.add_resource(serverless_func) with self.assertRaises(ValueError): t.to_json()
"Statement": [{ "Action": ['lambda:InvokeFunction'], "Resource": '*', "Effect": "Allow", }], })], )) upvote_function = template.add_resource(Function( 'UpvoteFunction', Description='Creates an upvote event.', Runtime='python3.7', Handler='index.handler', Role=GetAtt(upvote_role, 'Arn'), CodeUri=S3Location( Bucket=ImportValue(Join('-', [Ref(core_stack), 'LambdaCodeBucket-Ref'])), Key=Ref(upvote_lambda_code_key), ), Environment=Environment( Variables={ 'VIDEO_EVENTS_TABLE': ImportValue(Join('-', [Ref(core_stack), 'VideoEventsTable', 'Ref'])), } ) )) template.add_resource(LogGroup( "UpvoteFunctionLogGroup", LogGroupName=Join('/', ['/aws/lambda', Ref(upvote_function)]), RetentionInDays=7, )) upvote_method = template.add_resource(Method(
"Action": ['logs:CreateLogGroup', "logs:CreateLogStream", "logs:PutLogEvents"], "Resource": "arn:aws:logs:*:*:*", "Effect": "Allow", }], })], )) rewrite_assets_function = template.add_resource(Function( 'RewriteAssetsFunction', Description='Rewrite assets based on CloudFront headers.', Runtime='nodejs10.x', Handler='index.handler', Role=GetAtt(readonly_function_role, 'Arn'), AutoPublishAlias='live', CodeUri=S3Location( Bucket=ImportValue(Join('-', [Ref(core_stack), 'LambdaCodeBucket-Ref'])), Key=Ref(rewrite_assets_lambda_code_key), ), )) public_distribution = template.add_resource(Distribution( "CloudFrontDistribution", DistributionConfig=DistributionConfig( Aliases=[Ref(domain_name)], Comment=Ref(AWS_STACK_NAME), DefaultCacheBehavior=DefaultCacheBehavior( TargetOriginId='S3', ViewerProtocolPolicy='redirect-to-https', ForwardedValues=ForwardedValues( QueryString=False, ), MinTTL=120, # 2 minutes
}, { "Action": ['lambda:InvokeFunction'], "Resource": '*', "Effect": "Allow", }], })], )) all_videos_function = template.add_resource(Function( 'AllVideosFunction', Handler='index.handler', Runtime='nodejs10.x', Role=GetAtt(readonly_function_role, 'Arn'), Description='Returns list of videos for the admin api.', CodeUri=S3Location( Bucket=ImportValue(Join('-', [Ref(core_stack), 'LambdaCodeBucket-Ref'])), Key=Ref(all_videos_lambda_code_key), ), Events={ 'ApiEvent': { 'Properties': { 'Method': 'get', 'Path': '/videos', 'RestApiId': Ref(admin_api), }, 'Type': 'Api', } }, Environment=Environment( Variables={ 'VIDEO_TABLE': Ref(video_table), }