diff --git a/samtranslator/model/preferences/deployment_preference_collection.py b/samtranslator/model/preferences/deployment_preference_collection.py index 1c67e8b11c..b7d301760d 100644 --- a/samtranslator/model/preferences/deployment_preference_collection.py +++ b/samtranslator/model/preferences/deployment_preference_collection.py @@ -134,17 +134,19 @@ def deployment_group(self, function_logical_id): return deployment_group - def _replace_deployment_types(self, value): + def _replace_deployment_types(self, value, key=None): if isinstance(value, list): for i in range(len(value)): value[i] = self._replace_deployment_types(value[i]) return value elif is_instrinsic(value): for (k, v) in value.items(): - value[k] = self._replace_deployment_types(v) + value[k] = self._replace_deployment_types(v, k) return value else: if value in CODEDEPLOY_PREDEFINED_CONFIGURATIONS_LIST: + if key == "Fn::Sub": # Don't nest a "Sub" in a "Sub" + return ["CodeDeployDefault.Lambda${ConfigName}", {"ConfigName": value}] return fnSub("CodeDeployDefault.Lambda${ConfigName}", {"ConfigName": value}) return value diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 66008dee57..22cd93856d 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -87,6 +87,7 @@ def to_cloudformation(self, **kwargs): """ resources = [] intrinsics_resolver = kwargs["intrinsics_resolver"] + mappings_resolver = kwargs.get("mappings_resolver", None) if self.DeadLetterQueue: self._validate_dlq() @@ -105,7 +106,8 @@ def to_cloudformation(self, **kwargs): if self.DeploymentPreference: self._validate_deployment_preference_and_add_update_policy(kwargs.get('deployment_preference_collection', None), - lambda_alias, intrinsics_resolver) + lambda_alias, intrinsics_resolver, + mappings_resolver) managed_policy_map = kwargs.get('managed_policy_map', {}) if not managed_policy_map: @@ -392,13 +394,20 @@ def _construct_alias(self, name, function, version): return alias def _validate_deployment_preference_and_add_update_policy(self, deployment_preference_collection, lambda_alias, - intrinsics_resolver): + intrinsics_resolver, mappings_resolver): if 'Enabled' in self.DeploymentPreference: self.DeploymentPreference['Enabled'] = intrinsics_resolver.resolve_parameter_refs( self.DeploymentPreference['Enabled']) if isinstance(self.DeploymentPreference['Enabled'], dict): raise InvalidResourceException(self.logical_id, "'Enabled' must be a boolean value") + if 'Type' in self.DeploymentPreference: + # resolve intrinsics and mappings for Type + preference_type = self.DeploymentPreference['Type'] + preference_type = intrinsics_resolver.resolve_parameter_refs(preference_type) + preference_type = mappings_resolver.resolve_parameter_refs(preference_type) + self.DeploymentPreference['Type'] = preference_type + if deployment_preference_collection is None: raise ValueError('deployment_preference_collection required for parsing the deployment preference') diff --git a/samtranslator/translator/translator.py b/samtranslator/translator/translator.py index a0043ebf1c..aefe131a57 100644 --- a/samtranslator/translator/translator.py +++ b/samtranslator/translator/translator.py @@ -6,6 +6,7 @@ from samtranslator.model.exceptions import (InvalidDocumentException, InvalidResourceException, DuplicateLogicalIdException, InvalidEventException) from samtranslator.intrinsics.resolver import IntrinsicsResolver +from samtranslator.intrinsics.actions import FindInMapAction from samtranslator.intrinsics.resource_refs import SupportedResourceReferences from samtranslator.plugins.api.default_definition_body_plugin import DefaultDefinitionBodyPlugin from samtranslator.plugins.application.serverless_app_plugin import ServerlessAppPlugin @@ -62,6 +63,8 @@ def translate(self, sam_template, parameter_values): template = copy.deepcopy(sam_template) macro_resolver = ResourceTypeResolver(sam_resources) intrinsics_resolver = IntrinsicsResolver(parameter_values) + mappings_resolver = IntrinsicsResolver(template.get('Mappings', {}), + {FindInMapAction.intrinsic_name: FindInMapAction()}) deployment_preference_collection = DeploymentPreferenceCollection() supported_resource_refs = SupportedResourceReferences() document_errors = [] @@ -76,6 +79,7 @@ def translate(self, sam_template, parameter_values): kwargs = macro.resources_to_link(sam_template['Resources']) kwargs['managed_policy_map'] = self.managed_policy_map kwargs['intrinsics_resolver'] = intrinsics_resolver + kwargs['mappings_resolver'] = mappings_resolver kwargs['deployment_preference_collection'] = deployment_preference_collection translated = macro.to_cloudformation(**kwargs) diff --git a/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml b/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml index 25846f7000..1a6a8606a7 100644 --- a/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml +++ b/tests/translator/input/function_with_custom_codedeploy_deployment_preference.yaml @@ -1,3 +1,29 @@ +Mappings: + DeploymentPreferenceMap: + prod: + DeploymentPreference: + AllAtOnce + beta: + DeploymentPreference: + CustomDeployment + +Parameters: + Stage: + Type: String + Default: 'beta' + Deployment: + Type: String + Default: 'AllAtOnce' + Custom: + Type: String + Default: 'CustomDeployment' + +Conditions: + MyCondition: + Fn::Equals: + - true + - false + Resources: MinimalFunction: Type: 'AWS::Serverless::Function' @@ -7,4 +33,64 @@ Resources: Runtime: python2.7 AutoPublishAlias: live DeploymentPreference: - Type: TestDeploymentConfiguration \ No newline at end of file + Type: TestDeploymentConfiguration + + CustomWithFindInMap: # Doesn't work + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !FindInMap [DeploymentPreferenceMap, !Ref Stage, DeploymentPreference] + + CustomWithCondition: # Works + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !If [MyCondition, TestDeploymentConfiguration, AllAtOnce] + + CustomWithCondition2: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !If [MyCondition, !Sub "${Deployment}", !Ref Custom] + + NormalWithSub: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !Sub ${Deployment} + + CustomWithSub: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !Sub ${Custom} + + NormalWithRef: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: !Ref Deployment \ No newline at end of file diff --git a/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json index e15c61776b..e3a9f705d9 100644 --- a/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json +++ b/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json @@ -1,142 +1,864 @@ { - "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { + "Parameters": { + "Deployment": { + "Default": "AllAtOnce", + "Type": "String" + }, + "Custom": { + "Default": "CustomDeployment", + "Type": "String" + }, + "Stage": { + "Default": "beta", + "Type": "String" + } + }, + "Conditions": { + "MyCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Mappings": { + "DeploymentPreferenceMap": { + "beta": { + "DeploymentPreference": "CustomDeployment" + }, + "prod": { + "DeploymentPreference": "AllAtOnce" + } + } + }, + "Resources": { + "NormalWithRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": "TestDeploymentConfiguration", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentGroupName": { + "Ref": "NormalWithRefDeploymentGroup" } } }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithRefVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "NormalWithRef" + }, + "Name": "live" + } + }, + "CustomWithFindInMapVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithFindInMap" + } + } + }, + "CustomWithCondition2DeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" } - } - ] + ] + }, + "CustomDeployment" + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "CustomWithFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithFindInMapDeploymentGroup" } } }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithFindInMapVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithFindInMap" + }, + "Name": "live" + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithSubAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "Runtime": "python2.7", - "Tags": [ + "DeploymentGroupName": { + "Ref": "CustomWithSubDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithSubVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithSub" + }, + "Name": "live" + } + }, + "NormalWithSub": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NormalWithSubRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithConditionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + } + } + }, + "CustomWithSubDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": "CustomDeployment" + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "CustomWithCondition2Version640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" + } + } + }, + "CustomWithCondition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithConditionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithSub": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithSubRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "NormalWithRefVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "NormalWithRef" + } + } + }, + "NormalWithSubDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Value": "SAM", - "Key": "lambda:createdBy" + "ConfigName": "AllAtOnce" } ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] } - ] + } + ] + } + } + }, + "NormalWithRefDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "NormalWithSubAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithSubDeploymentGroup" } } }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithSubVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "NormalWithSub" + }, + "Name": "live" + } + }, + "CustomWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" + } + }, + "CustomWithSubRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithConditionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithConditionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + "TestDeploymentConfiguration", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithFindInMap": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "NormalWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "NormalWithSub" + } + } + }, + "CustomWithConditionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithConditionDeploymentGroup" } } }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithConditionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithCondition" + }, + "Name": "live" + } + }, + "CustomWithFindInMapRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ] + } + } + }, + "NormalWithRef": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NormalWithRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" } + ] + } + }, + "CustomWithCondition2": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] + "Role": { + "Fn::GetAtt": [ + "CustomWithCondition2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "NormalWithRefRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithCondition2Aliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionName": { - "Ref": "MinimalFunction" + "DeploymentGroupName": { + "Ref": "CustomWithCondition2DeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithCondition2Version640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithCondition2" + }, + "Name": "live" + } + }, + "NormalWithSubRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "CustomWithFindInMapDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "CustomDeployment", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "Name": "live" + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "CustomWithCondition2Role": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] } } } } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json index 60928c399a..168fb53b4f 100644 --- a/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json +++ b/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json @@ -1,142 +1,864 @@ { - "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { + "Parameters": { + "Deployment": { + "Default": "AllAtOnce", + "Type": "String" + }, + "Custom": { + "Default": "CustomDeployment", + "Type": "String" + }, + "Stage": { + "Default": "beta", + "Type": "String" + } + }, + "Conditions": { + "MyCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Mappings": { + "DeploymentPreferenceMap": { + "beta": { + "DeploymentPreference": "CustomDeployment" + }, + "prod": { + "DeploymentPreference": "AllAtOnce" + } + } + }, + "Resources": { + "NormalWithRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": "TestDeploymentConfiguration", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentGroupName": { + "Ref": "NormalWithRefDeploymentGroup" } } }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithRefVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "NormalWithRef" + }, + "Name": "live" + } + }, + "CustomWithFindInMapVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithFindInMap" + } + } + }, + "CustomWithCondition2DeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" } - } - ] + ] + }, + "CustomDeployment" + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "CustomWithFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithFindInMapDeploymentGroup" } } }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithFindInMapVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithFindInMap" + }, + "Name": "live" + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithSubAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "Runtime": "python2.7", - "Tags": [ + "DeploymentGroupName": { + "Ref": "CustomWithSubDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithSubVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithSub" + }, + "Name": "live" + } + }, + "NormalWithSub": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NormalWithSubRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithConditionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + } + } + }, + "CustomWithSubDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": "CustomDeployment" + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "CustomWithCondition2Version640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" + } + } + }, + "CustomWithCondition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithConditionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithSub": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithSubRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "NormalWithRefVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "NormalWithRef" + } + } + }, + "NormalWithSubDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Value": "SAM", - "Key": "lambda:createdBy" + "ConfigName": "AllAtOnce" } ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] } - ] + } + ] + } + } + }, + "NormalWithRefDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "NormalWithSubAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithSubDeploymentGroup" } } }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithSubVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "NormalWithSub" + }, + "Name": "live" + } + }, + "CustomWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" + } + }, + "CustomWithSubRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithConditionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithConditionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + "TestDeploymentConfiguration", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithFindInMap": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "NormalWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "NormalWithSub" + } + } + }, + "CustomWithConditionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithConditionDeploymentGroup" } } }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithConditionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithCondition" + }, + "Name": "live" + } + }, + "CustomWithFindInMapRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ] + } + } + }, + "NormalWithRef": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NormalWithRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" } + ] + } + }, + "CustomWithCondition2": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] + "Role": { + "Fn::GetAtt": [ + "CustomWithCondition2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "NormalWithRefRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithCondition2Aliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionName": { - "Ref": "MinimalFunction" + "DeploymentGroupName": { + "Ref": "CustomWithCondition2DeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithCondition2Version640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithCondition2" + }, + "Name": "live" + } + }, + "NormalWithSubRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "CustomWithFindInMapDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "CustomDeployment", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "Name": "live" + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "CustomWithCondition2Role": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] } } } } +} \ No newline at end of file diff --git a/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json index d0d846442a..8f628b9b1d 100644 --- a/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json +++ b/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json @@ -1,142 +1,864 @@ { - "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { + "Parameters": { + "Deployment": { + "Default": "AllAtOnce", + "Type": "String" + }, + "Custom": { + "Default": "CustomDeployment", + "Type": "String" + }, + "Stage": { + "Default": "beta", + "Type": "String" + } + }, + "Conditions": { + "MyCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Mappings": { + "DeploymentPreferenceMap": { + "beta": { + "DeploymentPreference": "CustomDeployment" + }, + "prod": { + "DeploymentPreference": "AllAtOnce" + } + } + }, + "Resources": { + "NormalWithRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": "TestDeploymentConfiguration", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentGroupName": { + "Ref": "NormalWithRefDeploymentGroup" } } }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithRefVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "NormalWithRef" + }, + "Name": "live" + } + }, + "CustomWithFindInMapVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithFindInMap" + } + } + }, + "CustomWithCondition2DeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" } - } - ] + ] + }, + "CustomDeployment" + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "CustomWithFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithFindInMapDeploymentGroup" } } }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithFindInMapVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithFindInMap" + }, + "Name": "live" + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithSubAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "Runtime": "python2.7", - "Tags": [ + "DeploymentGroupName": { + "Ref": "CustomWithSubDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithSubVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithSub" + }, + "Name": "live" + } + }, + "NormalWithSub": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NormalWithSubRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithConditionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + } + } + }, + "CustomWithSubDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": "CustomDeployment" + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "CustomWithCondition2Version640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" + } + } + }, + "CustomWithCondition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithConditionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "CustomWithSub": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithSubRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "NormalWithRefVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "NormalWithRef" + } + } + }, + "NormalWithSubDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Value": "SAM", - "Key": "lambda:createdBy" + "ConfigName": "AllAtOnce" } ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] } - ] + } + ] + } + } + }, + "NormalWithRefDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "NormalWithSubAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithSubDeploymentGroup" } } }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithSubVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "NormalWithSub" + }, + "Name": "live" + } + }, + "CustomWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" + } + }, + "CustomWithSubRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithConditionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithConditionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + "TestDeploymentConfiguration", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithFindInMap": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "CustomWithFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "NormalWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "NormalWithSub" + } + } + }, + "CustomWithConditionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithConditionDeploymentGroup" } } }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithConditionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithCondition" + }, + "Name": "live" + } + }, + "CustomWithFindInMapRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ] + } + } + }, + "NormalWithRef": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "NormalWithRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" } + ] + } + }, + "CustomWithCondition2": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] + "Role": { + "Fn::GetAtt": [ + "CustomWithCondition2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "NormalWithRefRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "CustomWithCondition2Aliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionName": { - "Ref": "MinimalFunction" + "DeploymentGroupName": { + "Ref": "CustomWithCondition2DeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithCondition2Version640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "CustomWithCondition2" + }, + "Name": "live" + } + }, + "NormalWithSubRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "CustomWithFindInMapDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "DeploymentConfigName": "CustomDeployment", + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "Name": "live" + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "CustomWithCondition2Role": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] } } } - } \ No newline at end of file + } +} \ No newline at end of file diff --git a/tests/translator/test_function_resources.py b/tests/translator/test_function_resources.py index a349174157..2439a9a8ab 100644 --- a/tests/translator/test_function_resources.py +++ b/tests/translator/test_function_resources.py @@ -15,6 +15,8 @@ def setUp(self): self.intrinsics_resolver_mock = Mock() self.intrinsics_resolver_mock.resolve = Mock() + self.mappings_resolver_mock = Mock() + self.mappings_resolver_mock.resolve = Mock() self.code_uri = "s3://bucket/key?versionId=version" self.func_dict = { @@ -98,6 +100,7 @@ def test_sam_function_with_deployment_preference(self, get_resolved_alias_name_m kwargs["managed_policy_map"] = {"a": "b"} kwargs["event_resources"] = [] kwargs["intrinsics_resolver"] = self.intrinsics_resolver_mock + kwargs["mappings_resolver"] = self.mappings_resolver_mock deployment_preference_collection = self._make_deployment_preference_collection() kwargs['deployment_preference_collection'] = deployment_preference_collection get_resolved_alias_name_mock.return_value = alias_name @@ -136,6 +139,7 @@ def test_sam_function_with_deployment_preference_missing_collection_raises_error kwargs["managed_policy_map"] = {"a": "b"} kwargs["event_resources"] = [] kwargs["intrinsics_resolver"] = self.intrinsics_resolver_mock + kwargs["mappings_resolver"] = self.mappings_resolver_mock self.intrinsics_resolver_mock.resolve_parameter_refs.return_value = {"S3Bucket": "bucket", "S3Key": "key", "S3ObjectVersion": "version"} get_resolved_alias_name_mock.return_value = alias_name @@ -199,6 +203,7 @@ def test_sam_function_cannot_be_with_deployment_preference_without_alias(self): kwargs = dict() kwargs["intrinsics_resolver"] = self.intrinsics_resolver_mock + kwargs["mappings_resolver"] = self.mappings_resolver_mock kwargs['deployment_preference_collection'] = self._make_deployment_preference_collection() sam_func.to_cloudformation(**kwargs) @@ -257,6 +262,7 @@ def test_sam_function_with_deployment_preference_intrinsic_ref_enabled_boolean_p kwargs["managed_policy_map"] = {"a": "b"} kwargs["event_resources"] = [] kwargs["intrinsics_resolver"] = self.intrinsics_resolver_mock + kwargs["mappings_resolver"] = self.mappings_resolver_mock deployment_preference_collection = self._make_deployment_preference_collection() kwargs['deployment_preference_collection'] = deployment_preference_collection self.intrinsics_resolver_mock.resolve_parameter_refs.return_value = True @@ -267,7 +273,7 @@ def test_sam_function_with_deployment_preference_intrinsic_ref_enabled_boolean_p deployment_preference_collection.update_policy.assert_called_once_with(self.sam_func.logical_id) deployment_preference_collection.add.assert_called_once_with(self.sam_func.logical_id, deploy_preference_dict) - self.intrinsics_resolver_mock.resolve_parameter_refs.assert_called_with(enabled) + self.intrinsics_resolver_mock.resolve_parameter_refs.assert_any_call(enabled) aliases = [r.to_dict() for r in resources if r.resource_type == LambdaAlias.resource_type]