diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index 502bb3ba1c..75499e7d2d 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -216,7 +216,7 @@ def _construct_deployment(self, rest_api): return deployment - def _construct_stage(self, deployment, swagger): + def _construct_stage(self, deployment, swagger, redeploy_restapi_parameters): """Constructs and returns the ApiGateway Stage. :param model.apigateway.ApiGatewayDeployment deployment: the Deployment for this Stage @@ -245,7 +245,9 @@ def _construct_stage(self, deployment, swagger): stage.TracingEnabled = self.tracing_enabled if swagger is not None: - deployment.make_auto_deployable(stage, self.remove_extra_stage, swagger, self.domain) + deployment.make_auto_deployable( + stage, self.remove_extra_stage, swagger, self.domain, redeploy_restapi_parameters + ) if self.tags is not None: stage.Tags = get_tag_list(self.tags) @@ -372,7 +374,7 @@ def _construct_alias_target(self, domain): alias_target["DNSName"] = route53.get("DistributionDomainName") return alias_target - def to_cloudformation(self): + def to_cloudformation(self, redeploy_restapi_parameters): """Generates CloudFormation resources from a SAM API resource :returns: a tuple containing the RestApi, Deployment, and Stage for an empty Api. @@ -388,7 +390,7 @@ def to_cloudformation(self): elif rest_api.BodyS3Location is not None: swagger = rest_api.BodyS3Location - stage = self._construct_stage(deployment, swagger) + stage = self._construct_stage(deployment, swagger, redeploy_restapi_parameters) permissions = self._construct_authorizer_lambda_permission() return rest_api, deployment, stage, permissions, domain, basepath_mapping, route53 diff --git a/samtranslator/model/apigateway.py b/samtranslator/model/apigateway.py index d767e4adcc..aeb9f37ae1 100644 --- a/samtranslator/model/apigateway.py +++ b/samtranslator/model/apigateway.py @@ -68,7 +68,9 @@ class ApiGatewayDeployment(Resource): runtime_attrs = {"deployment_id": lambda self: ref(self.logical_id)} - def make_auto_deployable(self, stage, openapi_version=None, swagger=None, domain=None): + def make_auto_deployable( + self, stage, openapi_version=None, swagger=None, domain=None, redeploy_restapi_parameters=None + ): """ Sets up the resource such that it will trigger a re-deployment when Swagger changes or the openapi version changes or a domain resource changes. @@ -76,6 +78,7 @@ def make_auto_deployable(self, stage, openapi_version=None, swagger=None, domain :param swagger: Dictionary containing the Swagger definition of the API :param openapi_version: string containing value of OpenApiVersion flag in the template :param domain: Dictionary containing the custom domain configuration for the API + :param redeploy_restapi_parameters: Dictionary containing the properties for which rest api will be redeployed """ if not swagger: return @@ -91,7 +94,14 @@ def make_auto_deployable(self, stage, openapi_version=None, swagger=None, domain hash_input.append(str(openapi_version)) if domain: hash_input.append(json.dumps(domain)) - + if redeploy_restapi_parameters: + function_names = redeploy_restapi_parameters.get("function_names") + else: + function_names = None + # The deployment logical id is + "Deployment" + # The keyword "Deployment" is removed and all the function names associated with api is obtained + if function_names and function_names.get(self.logical_id[:-10], None): + hash_input.append(function_names.get(self.logical_id[:-10], "")) data = self._X_HASH_DELIMITER.join(hash_input) generator = logical_id_generator.LogicalIdGenerator(self.logical_id, data) self.logical_id = generator.gen() diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index ae290e6475..f219fd8077 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -760,6 +760,7 @@ def to_cloudformation(self, **kwargs): intrinsics_resolver = kwargs["intrinsics_resolver"] self.BinaryMediaTypes = intrinsics_resolver.resolve_parameter_refs(self.BinaryMediaTypes) self.Domain = intrinsics_resolver.resolve_parameter_refs(self.Domain) + redeploy_restapi_parameters = kwargs.get("redeploy_restapi_parameters") api_generator = ApiGenerator( self.logical_id, @@ -789,7 +790,9 @@ def to_cloudformation(self, **kwargs): domain=self.Domain, ) - rest_api, deployment, stage, permissions, domain, basepath_mapping, route53 = api_generator.to_cloudformation() + rest_api, deployment, stage, permissions, domain, basepath_mapping, route53 = api_generator.to_cloudformation( + redeploy_restapi_parameters + ) resources.extend([rest_api, deployment, stage]) resources.extend(permissions) diff --git a/samtranslator/translator/translator.py b/samtranslator/translator/translator.py index c47e1095cc..2df080b4d8 100644 --- a/samtranslator/translator/translator.py +++ b/samtranslator/translator/translator.py @@ -36,6 +36,35 @@ def __init__(self, managed_policy_map, sam_parser, plugins=None): self.plugins = plugins self.sam_parser = sam_parser + def _get_function_names(self, resource_dict, intrinsics_resolver): + """ + :param resource_dict: AWS::Serverless::Function resource is provided as input + :param intrinsics_resolver: to resolve intrinsics for function_name + :return: a dictionary containing api_logical_id as the key and concatenated String of all function_names + associated with this api as the value + """ + if resource_dict.get("Type") and resource_dict.get("Type").strip() == "AWS::Serverless::Function": + if resource_dict.get("Properties") and resource_dict.get("Properties").get("Events"): + events = list(resource_dict.get("Properties").get("Events").values()) + for item in events: + # If the function event type is `Api` then gets the function name and + # adds to the function_names dict with key as the api_name and value as the function_name + if item.get("Type") == "Api" and item.get("Properties") and item.get("Properties").get("RestApiId"): + rest_api = item.get("Properties").get("RestApiId") + if type(rest_api) == dict: + api_name = item.get("Properties").get("RestApiId").get("Ref") + else: + api_name = item.get("Properties").get("RestApiId") + if api_name: + function_name = intrinsics_resolver.resolve_parameter_refs( + resource_dict.get("Properties").get("FunctionName") + ) + if function_name: + self.function_names[api_name] = self.function_names.get(api_name, "") + str( + function_name + ) + return self.function_names + def translate(self, sam_template, parameter_values): """Loads the SAM resources from the given SAM manifest, replaces them with their corresponding CloudFormation resources, and returns the resulting CloudFormation template. @@ -51,6 +80,8 @@ def translate(self, sam_template, parameter_values): :returns: a copy of the template with SAM resources replaced with the corresponding CloudFormation, which may \ be dumped into a valid CloudFormation JSON or YAML template """ + self.function_names = dict() + self.redeploy_restapi_parameters = dict() sam_parameter_values = SamParameterValues(parameter_values) sam_parameter_values.add_default_parameter_values(sam_template) sam_parameter_values.add_pseudo_parameter_values() @@ -70,7 +101,6 @@ def translate(self, sam_template, parameter_values): supported_resource_refs = SupportedResourceReferences() document_errors = [] changed_logical_ids = {} - for logical_id, resource_dict in self._get_resources_to_iterate(sam_template, macro_resolver): try: macro = macro_resolver.resolve_resource_type(resource_dict).from_dict( @@ -83,7 +113,11 @@ def translate(self, sam_template, parameter_values): kwargs["mappings_resolver"] = mappings_resolver kwargs["deployment_preference_collection"] = deployment_preference_collection kwargs["conditions"] = template.get("Conditions") - + # add the value of FunctionName property if the function is referenced with the api resource + self.redeploy_restapi_parameters["function_names"] = self._get_function_names( + resource_dict, intrinsics_resolver + ) + kwargs["redeploy_restapi_parameters"] = self.redeploy_restapi_parameters translated = macro.to_cloudformation(**kwargs) supported_resource_refs = macro.get_resource_references(translated, supported_resource_refs) diff --git a/tests/translator/input/intrinsic_functions.yaml b/tests/translator/input/intrinsic_functions.yaml index a17a2378c1..723cb273b1 100644 --- a/tests/translator/input/intrinsic_functions.yaml +++ b/tests/translator/input/intrinsic_functions.yaml @@ -28,7 +28,7 @@ Resources: Type: 'AWS::Serverless::Function' Properties: FunctionName: - Ref: FunctionName + Fn::Sub: ${FunctionName} CodeUri: Bucket: Ref: CodeBucket diff --git a/tests/translator/output/aws-cn/intrinsic_functions.json b/tests/translator/output/aws-cn/intrinsic_functions.json index f07ac52bf6..16c6f3f1e4 100644 --- a/tests/translator/output/aws-cn/intrinsic_functions.json +++ b/tests/translator/output/aws-cn/intrinsic_functions.json @@ -31,141 +31,141 @@ }, "Resources": { "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "BodyS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "swagger.yaml" - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" - }, + }, "Name": { "Ref": "MyExplicitApiName" } } - }, + }, "MyTable": { - "Type": "AWS::DynamoDB::Table", + "Type": "AWS::DynamoDB::Table", "Properties": { "KeySchema": [ { - "KeyType": "HASH", + "KeyType": "HASH", "AttributeName": "id" } - ], + ], "StreamSpecification": { "StreamViewType": "NEW_IMAGE" - }, + }, "AttributeDefinitions": [ { - "AttributeName": "id", + "AttributeName": "id", "AttributeType": "S" } - ], + ], "ProvisionedThroughput": { - "WriteCapacityUnits": 5, + "WriteCapacityUnits": 5, "ReadCapacityUnits": 5 } } - }, + }, "SnsDlqQueue": { "Type": "AWS::SNS::Topic" - }, + }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, "DeadLetterConfig": { "TargetArn": { "Fn::GetAtt": [ - "SqsDlqQueue", + "SqsDlqQueue", "Arn" ] } - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "index.handler", + ], + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", + "MySqsDlqLambdaFunctionRole", "Arn" ] - }, + }, "Runtime": "python2.7" } - }, + }, "SqsDlqQueue": { "Type": "AWS::SQS::Queue" - }, + }, "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", + "Version": "myversion", + "Bucket": "mybucket", "Key": "mykey" - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, + }, "Condition": "TrueCondition" - }, - "MyExplicitApiDeployment31ec20c228": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyExplicitApiDeployment7145dd00ce": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyExplicitApi" - }, - "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + }, + "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", "StageName": "Stage" } - }, + }, "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "stream.ddb_handler", + "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", + "S3Bucket": "mybucket", + "S3Key": "mykey", "S3ObjectVersion": "MyVersion" - }, + }, "Role": { "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", + "FunctionWithExplicitS3UriRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -178,29 +178,29 @@ ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", + "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "sns:Publish", + "Action": "sns:Publish", "Resource": { "Ref": "SnsDlqQueue" - }, + }, "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -210,68 +210,68 @@ ] } } - }, + }, "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "TracingConfig": { "Mode": { "Ref": "TracingConfigParam" } - }, + }, "Code": { "S3Bucket": { "Ref": "CodeBucket" - }, + }, "S3Key": { "Fn::Sub": "code.zip.${CodeKey}" - }, + }, "S3ObjectVersion": { "Fn::Join": [ - "", + "", [ - "some", + "some", "version" ] ] } - }, + }, "FunctionName": { - "Ref": "FunctionName" - }, + "Fn::Sub": "MySuperFunctionName" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], + ], "Handler": { "Fn::Sub": [ - "${filename}.handler", + "${filename}.handler", { "filename": "index" } ] - }, + }, "Role": { "Fn::GetAtt": [ - "MyNewRole", + "MyNewRole", "Arn" ] - }, + }, "Runtime": { "Fn::Join": [ - "", + "", [ - "nodejs", + "nodejs", "4.3" ] ] } } - }, + }, "FunctionWithExplicitS3UriRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -283,13 +283,13 @@ } ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -299,12 +299,12 @@ ] } } - }, + }, "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" ], "Tags": [ @@ -314,13 +314,13 @@ } ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -330,64 +330,64 @@ ] } } - }, + }, "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, "DeadLetterConfig": { "TargetArn": { "Ref": "SnsDlqQueue" } - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "index.handler", + ], + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MySnsDlqLambdaFunctionRole", + "MySnsDlqLambdaFunctionRole", "Arn" ] - }, + }, "Runtime": "python2.7" } }, "MyNewRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "Policies": [ { - "PolicyName": "lambdaRole", + "PolicyName": "lambdaRole", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ - "cloudwatch:*", + "cloudwatch:*", "logs:*" - ], - "Resource": "*", + ], + "Resource": "*", "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -397,72 +397,72 @@ ] } } - }, + }, "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "stream.ddb_handler", + "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "streams.zip" - }, + }, "Role": { "Fn::GetAtt": [ - "DynamoDBFunctionRole", + "DynamoDBFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" - }, + }, "RestApiId": { "Ref": "ApiWithExplicitS3Uri" - }, + }, "StageName": "dev" - }, + }, "Condition": "TrueCondition" - }, + }, "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "Type": "AWS::Lambda::EventSourceMapping", "Properties": { - "BatchSize": 200, + "BatchSize": 200, "EventSourceArn": { "Fn::GetAtt": [ - "MyTable", + "MyTable", "StreamArn" ] - }, + }, "FunctionName": { "Ref": "DynamoDBFunction" - }, + }, "StartingPosition": "LATEST" } - }, + }, "ApiWithExplicitS3UriDeploymenta227798f00": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", + }, + "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", "StageName": "Stage" - }, + }, "Condition": "TrueCondition" - }, + }, "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -475,32 +475,32 @@ ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", + "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", "Resource": { "Fn::GetAtt": [ - "SqsDlqQueue", + "SqsDlqQueue", "Arn" ] - }, + }, "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -510,44 +510,44 @@ ] } } - }, + }, "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyExplicitApiDeployment31ec20c228" - }, + "Ref": "MyExplicitApiDeployment7145dd00ce" + }, "RestApiId": { "Ref": "MyExplicitApi" - }, + }, "Variables": { "FunctionName": { "Fn::Sub": "${MyFunction}" - }, + }, "Var2": { "Fn::Join": [ - "join ", + "join ", [ - "some value ", + "some value ", "with some other value" ] ] } - }, + }, "StageName": "dev" } - }, + }, "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__Stage__": "*", "__ApiId__": { diff --git a/tests/translator/output/aws-us-gov/intrinsic_functions.json b/tests/translator/output/aws-us-gov/intrinsic_functions.json index acc163e9c8..fdd5353a60 100644 --- a/tests/translator/output/aws-us-gov/intrinsic_functions.json +++ b/tests/translator/output/aws-us-gov/intrinsic_functions.json @@ -31,141 +31,141 @@ }, "Resources": { "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "BodyS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "swagger.yaml" - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" - }, + }, "Name": { "Ref": "MyExplicitApiName" } } - }, + }, "MyTable": { - "Type": "AWS::DynamoDB::Table", + "Type": "AWS::DynamoDB::Table", "Properties": { "KeySchema": [ { - "KeyType": "HASH", + "KeyType": "HASH", "AttributeName": "id" } - ], + ], "StreamSpecification": { "StreamViewType": "NEW_IMAGE" - }, + }, "AttributeDefinitions": [ { - "AttributeName": "id", + "AttributeName": "id", "AttributeType": "S" } - ], + ], "ProvisionedThroughput": { - "WriteCapacityUnits": 5, + "WriteCapacityUnits": 5, "ReadCapacityUnits": 5 } } - }, + }, "SnsDlqQueue": { "Type": "AWS::SNS::Topic" - }, + }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, "DeadLetterConfig": { "TargetArn": { "Fn::GetAtt": [ - "SqsDlqQueue", + "SqsDlqQueue", "Arn" ] } - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "index.handler", + ], + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", + "MySqsDlqLambdaFunctionRole", "Arn" ] - }, + }, "Runtime": "python2.7" } - }, + }, "SqsDlqQueue": { "Type": "AWS::SQS::Queue" - }, + }, "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", + "Version": "myversion", + "Bucket": "mybucket", "Key": "mykey" - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, + }, "Condition": "TrueCondition" - }, - "MyExplicitApiDeployment31ec20c228": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyExplicitApiDeployment7145dd00ce": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyExplicitApi" - }, - "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + }, + "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", "StageName": "Stage" } - }, + }, "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "stream.ddb_handler", + "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", + "S3Bucket": "mybucket", + "S3Key": "mykey", "S3ObjectVersion": "MyVersion" - }, + }, "Role": { "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", + "FunctionWithExplicitS3UriRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -178,29 +178,29 @@ ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", + "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "sns:Publish", + "Action": "sns:Publish", "Resource": { "Ref": "SnsDlqQueue" - }, + }, "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -210,68 +210,68 @@ ] } } - }, + }, "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "TracingConfig": { "Mode": { "Ref": "TracingConfigParam" } - }, + }, "Code": { "S3Bucket": { "Ref": "CodeBucket" - }, + }, "S3Key": { "Fn::Sub": "code.zip.${CodeKey}" - }, + }, "S3ObjectVersion": { "Fn::Join": [ - "", + "", [ - "some", + "some", "version" ] ] } - }, + }, "FunctionName": { - "Ref": "FunctionName" - }, + "Fn::Sub": "MySuperFunctionName" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], + ], "Handler": { "Fn::Sub": [ - "${filename}.handler", + "${filename}.handler", { "filename": "index" } ] - }, + }, "Role": { "Fn::GetAtt": [ - "MyNewRole", + "MyNewRole", "Arn" ] - }, + }, "Runtime": { "Fn::Join": [ - "", + "", [ - "nodejs", + "nodejs", "4.3" ] ] } } - }, + }, "FunctionWithExplicitS3UriRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -283,13 +283,13 @@ } ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -299,12 +299,12 @@ ] } } - }, + }, "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" ], "Tags": [ @@ -314,13 +314,13 @@ } ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -330,64 +330,64 @@ ] } } - }, + }, "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, "DeadLetterConfig": { "TargetArn": { "Ref": "SnsDlqQueue" } - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "index.handler", + ], + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MySnsDlqLambdaFunctionRole", + "MySnsDlqLambdaFunctionRole", "Arn" ] - }, + }, "Runtime": "python2.7" } }, "MyNewRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "Policies": [ { - "PolicyName": "lambdaRole", + "PolicyName": "lambdaRole", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ - "cloudwatch:*", + "cloudwatch:*", "logs:*" - ], - "Resource": "*", + ], + "Resource": "*", "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -397,72 +397,72 @@ ] } } - }, + }, "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "stream.ddb_handler", + "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "streams.zip" - }, + }, "Role": { "Fn::GetAtt": [ - "DynamoDBFunctionRole", + "DynamoDBFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" - }, + }, "RestApiId": { "Ref": "ApiWithExplicitS3Uri" - }, + }, "StageName": "dev" - }, + }, "Condition": "TrueCondition" - }, + }, "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "Type": "AWS::Lambda::EventSourceMapping", "Properties": { - "BatchSize": 200, + "BatchSize": 200, "EventSourceArn": { "Fn::GetAtt": [ - "MyTable", + "MyTable", "StreamArn" ] - }, + }, "FunctionName": { "Ref": "DynamoDBFunction" - }, + }, "StartingPosition": "LATEST" } - }, + }, "ApiWithExplicitS3UriDeploymenta227798f00": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", + }, + "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", "StageName": "Stage" - }, + }, "Condition": "TrueCondition" - }, + }, "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -475,32 +475,32 @@ ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", + "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", "Resource": { "Fn::GetAtt": [ - "SqsDlqQueue", + "SqsDlqQueue", "Arn" ] - }, + }, "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -510,44 +510,44 @@ ] } } - }, + }, "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyExplicitApiDeployment31ec20c228" - }, + "Ref": "MyExplicitApiDeployment7145dd00ce" + }, "RestApiId": { "Ref": "MyExplicitApi" - }, + }, "Variables": { "FunctionName": { "Fn::Sub": "${MyFunction}" - }, + }, "Var2": { "Fn::Join": [ - "join ", + "join ", [ - "some value ", + "some value ", "with some other value" ] ] } - }, + }, "StageName": "dev" } - }, + }, "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__Stage__": "*", "__ApiId__": { diff --git a/tests/translator/output/intrinsic_functions.json b/tests/translator/output/intrinsic_functions.json index bdf3acb8e0..744c6bec53 100644 --- a/tests/translator/output/intrinsic_functions.json +++ b/tests/translator/output/intrinsic_functions.json @@ -31,125 +31,125 @@ }, "Resources": { "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "BodyS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "swagger.yaml" - }, + }, "Name": { "Ref": "MyExplicitApiName" } } - }, + }, "MyTable": { - "Type": "AWS::DynamoDB::Table", + "Type": "AWS::DynamoDB::Table", "Properties": { "KeySchema": [ { - "KeyType": "HASH", + "KeyType": "HASH", "AttributeName": "id" } - ], + ], "StreamSpecification": { "StreamViewType": "NEW_IMAGE" - }, + }, "AttributeDefinitions": [ { - "AttributeName": "id", + "AttributeName": "id", "AttributeType": "S" } - ], + ], "ProvisionedThroughput": { - "WriteCapacityUnits": 5, + "WriteCapacityUnits": 5, "ReadCapacityUnits": 5 } } - }, + }, "SnsDlqQueue": { "Type": "AWS::SNS::Topic" - }, + }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, "DeadLetterConfig": { "TargetArn": { "Fn::GetAtt": [ - "SqsDlqQueue", + "SqsDlqQueue", "Arn" ] } - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "index.handler", + ], + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", + "MySqsDlqLambdaFunctionRole", "Arn" ] - }, + }, "Runtime": "python2.7" } - }, + }, "SqsDlqQueue": { "Type": "AWS::SQS::Queue" - }, + }, "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", + "Type": "AWS::ApiGateway::RestApi", "Properties": { "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", + "Version": "myversion", + "Bucket": "mybucket", "Key": "mykey" } - }, + }, "Condition": "TrueCondition" - }, - "MyExplicitApiDeployment31ec20c228": { - "Type": "AWS::ApiGateway::Deployment", + }, + "MyExplicitApiDeployment7145dd00ce": { + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "MyExplicitApi" - }, - "Description": "RestApi deployment id: 31ec20c2288b273d15235777b0b90f3c0e2f9d52", + }, + "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", "StageName": "Stage" } - }, + }, "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "stream.ddb_handler", + "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", + "S3Bucket": "mybucket", + "S3Key": "mykey", "S3ObjectVersion": "MyVersion" - }, + }, "Role": { "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", + "FunctionWithExplicitS3UriRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -162,29 +162,29 @@ ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", + "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "sns:Publish", + "Action": "sns:Publish", "Resource": { "Ref": "SnsDlqQueue" - }, + }, "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -194,68 +194,68 @@ ] } } - }, + }, "MyFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "TracingConfig": { "Mode": { "Ref": "TracingConfigParam" } - }, + }, "Code": { "S3Bucket": { "Ref": "CodeBucket" - }, + }, "S3Key": { "Fn::Sub": "code.zip.${CodeKey}" - }, + }, "S3ObjectVersion": { "Fn::Join": [ - "", + "", [ - "some", + "some", "version" ] ] } - }, + }, "FunctionName": { - "Ref": "FunctionName" - }, + "Fn::Sub": "MySuperFunctionName" + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], + ], "Handler": { "Fn::Sub": [ - "${filename}.handler", + "${filename}.handler", { "filename": "index" } ] - }, + }, "Role": { "Fn::GetAtt": [ - "MyNewRole", + "MyNewRole", "Arn" ] - }, + }, "Runtime": { "Fn::Join": [ - "", + "", [ - "nodejs", + "nodejs", "4.3" ] ] } } - }, + }, "FunctionWithExplicitS3UriRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -267,13 +267,13 @@ } ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -283,12 +283,12 @@ ] } } - }, + }, "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" ], "Tags": [ @@ -298,13 +298,13 @@ } ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -314,64 +314,64 @@ ] } } - }, + }, "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, "DeadLetterConfig": { "TargetArn": { "Ref": "SnsDlqQueue" } - }, + }, "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } - ], - "Handler": "index.handler", + ], + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MySnsDlqLambdaFunctionRole", + "MySnsDlqLambdaFunctionRole", "Arn" ] - }, + }, "Runtime": "python2.7" } }, "MyNewRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "Policies": [ { - "PolicyName": "lambdaRole", + "PolicyName": "lambdaRole", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ - "cloudwatch:*", + "cloudwatch:*", "logs:*" - ], - "Resource": "*", + ], + "Resource": "*", "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -381,72 +381,72 @@ ] } } - }, + }, "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "stream.ddb_handler", + "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "streams.zip" - }, + }, "Role": { "Fn::GetAtt": [ - "DynamoDBFunctionRole", + "DynamoDBFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithExplicitS3UriDeploymenta227798f00" - }, + }, "RestApiId": { "Ref": "ApiWithExplicitS3Uri" - }, + }, "StageName": "dev" - }, + }, "Condition": "TrueCondition" - }, + }, "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "Type": "AWS::Lambda::EventSourceMapping", "Properties": { - "BatchSize": 200, + "BatchSize": 200, "EventSourceArn": { "Fn::GetAtt": [ - "MyTable", + "MyTable", "StreamArn" ] - }, + }, "FunctionName": { "Ref": "DynamoDBFunction" - }, + }, "StartingPosition": "LATEST" } - }, + }, "ApiWithExplicitS3UriDeploymenta227798f00": { - "Type": "AWS::ApiGateway::Deployment", + "Type": "AWS::ApiGateway::Deployment", "Properties": { "RestApiId": { "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", + }, + "Description": "RestApi deployment id: a227798f004a50b665fe47a20bb9afbf076bd85d", "StageName": "Stage" - }, + }, "Condition": "TrueCondition" - }, + }, "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -459,32 +459,32 @@ ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", + "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", "Resource": { "Fn::GetAtt": [ - "SqsDlqQueue", + "SqsDlqQueue", "Arn" ] - }, + }, "Effect": "Allow" } ] } } - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -494,44 +494,44 @@ ] } } - }, + }, "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", + "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { - "Ref": "MyExplicitApiDeployment31ec20c228" - }, + "Ref": "MyExplicitApiDeployment7145dd00ce" + }, "RestApiId": { "Ref": "MyExplicitApi" - }, + }, "Variables": { "FunctionName": { "Fn::Sub": "${MyFunction}" - }, + }, "Var2": { "Fn::Join": [ - "join ", + "join ", [ - "some value ", + "some value ", "with some other value" ] ] } - }, + }, "StageName": "dev" } - }, + }, "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", + "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__Stage__": "*", "__ApiId__": { diff --git a/tests/translator/test_api_resource.py b/tests/translator/test_api_resource.py index fcf2c3e646..918097fe09 100644 --- a/tests/translator/test_api_resource.py +++ b/tests/translator/test_api_resource.py @@ -52,6 +52,7 @@ def test_redeploy_implicit_api(): "FirstLambdaFunction": { "Type": "AWS::Serverless::Function", "Properties": { + "FunctionName": "InitialFunction", "CodeUri": "s3://bucket/code.zip", "Handler": "index.handler", "Runtime": "nodejs4.3", @@ -86,6 +87,10 @@ def test_redeploy_implicit_api(): manifest["Resources"]["SecondLambdaFunction"]["Properties"]["Runtime"] = "java" assert second_updated_deployment_ids == translate_and_find_deployment_ids(manifest) + manifest["Resources"]["FirstLambdaFunction"]["Properties"]["FunctionName"] = "ChangedFunctionName" + fourth_updated_deployment_ids = translate_and_find_deployment_ids(manifest) + assert fourth_updated_deployment_ids != second_updated_deployment_ids + @patch("boto3.session.Session.region_name", "ap-southeast-1") def translate_and_find_deployment_ids(manifest):