diff --git a/samtranslator/model/preferences/deployment_preference.py b/samtranslator/model/preferences/deployment_preference.py index 0f2c544c66..0b2026d5d1 100644 --- a/samtranslator/model/preferences/deployment_preference.py +++ b/samtranslator/model/preferences/deployment_preference.py @@ -44,6 +44,8 @@ def from_dict(cls, logical_id, deployment_preference_dict): :return: """ enabled = deployment_preference_dict.get("Enabled", True) + enabled = False if enabled in ["false", "False"] else enabled + if not enabled: return DeploymentPreference(None, None, None, None, False, None, None) diff --git a/tests/translator/input/function_with_deployment_preference_from_parameters.yaml b/tests/translator/input/function_with_deployment_preference_from_parameters.yaml new file mode 100644 index 0000000000..b77580f9be --- /dev/null +++ b/tests/translator/input/function_with_deployment_preference_from_parameters.yaml @@ -0,0 +1,64 @@ +Parameters: + MyTrueParameter: + Default: 'True' + Type: String + MyLowerFalseParameter: + Default: 'false' + Type: String + MyUpperFalseParameter: + Default: 'False' + Type: String + +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Enabled: !Ref MyTrueParameter + Type: Linear10PercentEvery1Minute + Hooks: + PreTraffic: !Ref MySanityTestFunction + PostTraffic: !Ref MyValidationTestFunction + Alarms: + - !Ref MyCloudWatchAlarm + TriggerConfigurations: + - TriggerEvents: + - DeploymentSuccess + - DeploymentFailure + TriggerName: TestTrigger + TriggerTargetArn: !Ref MySNSTopic + + MySanityTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/mySanityTestFunction.zip + DeploymentPreference: + Enabled: !Ref MyLowerFalseParameter + + MyValidationTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/myValidationTestFunction.zip + DeploymentPreference: + Enabled: !Ref MyUpperFalseParameter + + MyCloudWatchAlarm: + Type: AWS::CloudWatch::Alarm + Properties: + ComparisonOperator: GreaterThanThreshold + EvaluationPeriods: 1 + MetricName: MyMetric + Namespace: AWS/EC2 + Period: 300 + Threshold: 10 + + MySNSTopic: + Type: AWS::SNS::Topic \ No newline at end of file diff --git a/tests/translator/model/preferences/test_deployment_preference.py b/tests/translator/model/preferences/test_deployment_preference.py index 19331b3e42..e6fbc9d8e9 100644 --- a/tests/translator/model/preferences/test_deployment_preference.py +++ b/tests/translator/model/preferences/test_deployment_preference.py @@ -81,6 +81,28 @@ def test_from_dict_with_disabled_preference_does_not_require_other_parameters(se self.assertEqual(expected_deployment_preference, deployment_preference_from_yaml_dict) + def test_from_dict_with_string_disabled_preference_does_not_require_other_parameters(self): + expected_deployment_preference = DeploymentPreference(None, None, None, None, False, None, None) + + deployment_preference_yaml_dict = dict() + deployment_preference_yaml_dict["Enabled"] = "False" + deployment_preference_from_yaml_dict = DeploymentPreference.from_dict( + "logical_id", deployment_preference_yaml_dict + ) + + self.assertEqual(expected_deployment_preference, deployment_preference_from_yaml_dict) + + def test_from_dict_with_lowercase_string_disabled_preference_does_not_require_other_parameters(self): + expected_deployment_preference = DeploymentPreference(None, None, None, None, False, None, None) + + deployment_preference_yaml_dict = dict() + deployment_preference_yaml_dict["Enabled"] = "false" + deployment_preference_from_yaml_dict = DeploymentPreference.from_dict( + "logical_id", deployment_preference_yaml_dict + ) + + self.assertEqual(expected_deployment_preference, deployment_preference_from_yaml_dict) + def test_from_dict_with_non_dict_hooks_raises_invalid_resource_exception(self): with self.assertRaises(InvalidResourceException): DeploymentPreference.from_dict("logical_id", {"Type": "Canary", "Hooks": "badhook"}) diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json b/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json new file mode 100644 index 0000000000..0e83fb6c66 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json @@ -0,0 +1,317 @@ +{ + "Parameters": { + "MyTrueParameter": { + "Default": "True", + "Type": "String" + }, + "MyLowerFalseParameter": { + "Default": "false", + "Type": "String" + }, + "MyUpperFalseParameter": { + "Default": "False", + "Type": "String" + } + }, + "Resources": { + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "EvaluationPeriods": 1, + "Namespace": "AWS/EC2", + "Period": 300, + "ComparisonOperator": "GreaterThanThreshold", + "Threshold": 10, + "MetricName": "MyMetric" + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery1Minute" + } + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "TriggerConfigurations": [ + { + "TriggerEvents": [ + "DeploymentSuccess", + "DeploymentFailure" + ], + "TriggerTargetArn": { + "Ref": "MySNSTopic" + }, + "TriggerName": "TestTrigger" + } + ] + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "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" + ] + } + } + ] + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MyValidationTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "myValidationTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyValidationTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json new file mode 100644 index 0000000000..960cf3d85b --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json @@ -0,0 +1,317 @@ +{ + "Parameters": { + "MyTrueParameter": { + "Default": "True", + "Type": "String" + }, + "MyLowerFalseParameter": { + "Default": "false", + "Type": "String" + }, + "MyUpperFalseParameter": { + "Default": "False", + "Type": "String" + } + }, + "Resources": { + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "EvaluationPeriods": 1, + "Namespace": "AWS/EC2", + "Period": 300, + "ComparisonOperator": "GreaterThanThreshold", + "Threshold": 10, + "MetricName": "MyMetric" + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery1Minute" + } + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "TriggerConfigurations": [ + { + "TriggerEvents": [ + "DeploymentSuccess", + "DeploymentFailure" + ], + "TriggerTargetArn": { + "Ref": "MySNSTopic" + }, + "TriggerName": "TestTrigger" + } + ] + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "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" + ] + } + } + ] + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MyValidationTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "myValidationTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyValidationTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + } + } +} \ No newline at end of file diff --git a/tests/translator/output/function_with_deployment_preference_from_parameters.json b/tests/translator/output/function_with_deployment_preference_from_parameters.json new file mode 100644 index 0000000000..bba04a56af --- /dev/null +++ b/tests/translator/output/function_with_deployment_preference_from_parameters.json @@ -0,0 +1,317 @@ +{ + "Parameters": { + "MyTrueParameter": { + "Default": "True", + "Type": "String" + }, + "MyLowerFalseParameter": { + "Default": "false", + "Type": "String" + }, + "MyUpperFalseParameter": { + "Default": "False", + "Type": "String" + } + }, + "Resources": { + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "EvaluationPeriods": 1, + "Namespace": "AWS/EC2", + "Period": 300, + "ComparisonOperator": "GreaterThanThreshold", + "Threshold": 10, + "MetricName": "MyMetric" + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery1Minute" + } + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + }, + "TriggerConfigurations": [ + { + "TriggerEvents": [ + "DeploymentSuccess", + "DeploymentFailure" + ], + "TriggerTargetArn": { + "Ref": "MySNSTopic" + }, + "TriggerName": "TestTrigger" + } + ] + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "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" + ] + } + } + ] + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MyValidationTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "myValidationTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyValidationTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + } + } + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index e1480b183a..68e6833f1a 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -231,6 +231,7 @@ class TestTranslatorEndToEnd(TestCase): "function_with_disabled_deployment_preference", "function_with_deployment_preference", "function_with_deployment_preference_all_parameters", + "function_with_deployment_preference_from_parameters", "function_with_deployment_preference_multiple_combinations", "function_with_alias_and_event_sources", "function_with_resource_refs", diff --git a/tests/translator/validator/test_validator.py b/tests/translator/validator/test_validator.py index ceff650a8b..d76aa94eaa 100644 --- a/tests/translator/validator/test_validator.py +++ b/tests/translator/validator/test_validator.py @@ -56,6 +56,7 @@ "function_with_disabled_deployment_preference", "function_with_deployment_preference", "function_with_deployment_preference_all_parameters", + "function_with_deployment_preference_from_parameters", "function_with_deployment_preference_multiple_combinations", "function_with_alias_and_event_sources", "function_with_resource_refs", @@ -98,6 +99,7 @@ def test_validate_template_success(testcase): "function_with_disabled_deployment_preference", "function_with_deployment_preference", "function_with_deployment_preference_all_parameters", + "function_with_deployment_preference_from_parameters", "function_with_deployment_preference_multiple_combinations", "function_with_alias_and_event_sources", "function_with_resource_refs",