Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions samtranslator/model/preferences/deployment_preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down
Loading