From 8d0e058e149e7be4defd754c76c364a7ed6f71b5 Mon Sep 17 00:00:00 2001 From: Keeton Hodgson Date: Thu, 19 May 2022 12:45:58 -0600 Subject: [PATCH] fix: apply resource conditions to DeploymentPreference resources (#1578) * fix code deploy conditions bug * Cover all condition cases, update tests * black reformat * Update tests to use .get_codedeploy_iam_role() instead of .codedeploy_iam_role * Fixing unit tests after merging Condition fix commit * Use feature toggle to gate deployment preference condition fix * Add tests * Revert using feature toggle * Add property to opt-in deployment preference condition passthrough * Add tests for PassthroughCondition * Fix passthrough condition logic and add tests * Update PassthroughCondition to support intrinsic * intrinscs support + tests * update invalid intrinsics end-to-end test * uncomment and update invalid value unit test * black Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com> Co-authored-by: Ruperto Torres --- .../preferences/deployment_preference.py | 27 +- .../deployment_preference_collection.py | 70 +- samtranslator/model/sam_resources.py | 69 +- samtranslator/translator/translator.py | 9 +- ...through_condition_with_invalid_values.yaml | 72 ++ ...ment_no_service_role_with_passthrough.yaml | 48 ++ ..._no_service_role_without_passthrough.yaml} | 7 + ...preference_condition_with_passthrough.yaml | 31 + ...ference_condition_without_passthrough.yaml | 30 + ...binations_conditions_with_passthrough.yaml | 91 +++ ...ations_conditions_without_passthrough.yaml | 86 +++ ...h_condition_with_supported_intrinsics.yaml | 110 +++ .../preferences/test_deployment_preference.py | 58 +- .../test_deployment_preference_collection.py | 5 +- ...ment_no_service_role_with_passthrough.json | 283 ++++++++ ..._no_service_role_without_passthrough.json} | 214 +++--- ...preference_condition_with_passthrough.json | 208 ++++++ ...ference_condition_without_passthrough.json | 205 ++++++ ...binations_conditions_with_passthrough.json | 585 ++++++++++++++++ ...ations_conditions_without_passthrough.json | 570 +++++++++++++++ ...h_condition_with_supported_intrinsics.json | 649 ++++++++++++++++++ ...ment_no_service_role_with_passthrough.json | 283 ++++++++ ..._no_service_role_without_passthrough.json} | 214 +++--- ...preference_condition_with_passthrough.json | 208 ++++++ ...ference_condition_without_passthrough.json | 205 ++++++ ...binations_conditions_with_passthrough.json | 585 ++++++++++++++++ ...ations_conditions_without_passthrough.json | 570 +++++++++++++++ ...h_condition_with_supported_intrinsics.json | 649 ++++++++++++++++++ ...through_condition_with_invalid_values.json | 3 + ...ment_no_service_role_with_passthrough.json | 283 ++++++++ ..._no_service_role_without_passthrough.json} | 214 +++--- ...preference_condition_with_passthrough.json | 208 ++++++ ...ference_condition_without_passthrough.json | 205 ++++++ ...binations_conditions_with_passthrough.json | 585 ++++++++++++++++ ...ations_conditions_without_passthrough.json | 570 +++++++++++++++ ...h_condition_with_supported_intrinsics.json | 649 ++++++++++++++++++ tests/translator/test_function_resources.py | 167 ++++- tests/translator/test_translator.py | 8 +- .../test_deployment_preference_collection.py | 4 +- tests/validator/test_validator.py | 2 +- 40 files changed, 8694 insertions(+), 345 deletions(-) create mode 100644 tests/translator/input/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.yaml create mode 100644 tests/translator/input/function_with_deployment_no_service_role_with_passthrough.yaml rename tests/translator/input/{function_with_deployment_no_service_role.yaml => function_with_deployment_no_service_role_without_passthrough.yaml} (90%) create mode 100644 tests/translator/input/function_with_deployment_preference_condition_with_passthrough.yaml create mode 100644 tests/translator/input/function_with_deployment_preference_condition_without_passthrough.yaml create mode 100644 tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.yaml create mode 100644 tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.yaml create mode 100644 tests/translator/input/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.yaml create mode 100644 tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json rename tests/translator/output/aws-cn/{function_with_deployment_no_service_role.json => function_with_deployment_no_service_role_without_passthrough.json} (67%) create mode 100644 tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json create mode 100644 tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json create mode 100644 tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json create mode 100644 tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json create mode 100644 tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json create mode 100644 tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json rename tests/translator/output/aws-us-gov/{function_with_deployment_no_service_role.json => function_with_deployment_no_service_role_without_passthrough.json} (67%) create mode 100644 tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json create mode 100644 tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json create mode 100644 tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json create mode 100644 tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json create mode 100644 tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json create mode 100644 tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json create mode 100644 tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json rename tests/translator/output/{function_with_deployment_no_service_role.json => function_with_deployment_no_service_role_without_passthrough.json} (67%) create mode 100644 tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json create mode 100644 tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json create mode 100644 tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json create mode 100644 tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json create mode 100644 tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json diff --git a/samtranslator/model/preferences/deployment_preference.py b/samtranslator/model/preferences/deployment_preference.py index 0b2026d5d..0f876dcdc 100644 --- a/samtranslator/model/preferences/deployment_preference.py +++ b/samtranslator/model/preferences/deployment_preference.py @@ -25,7 +25,16 @@ """ DeploymentPreferenceTuple = namedtuple( "DeploymentPreferenceTuple", - ["deployment_type", "pre_traffic_hook", "post_traffic_hook", "alarms", "enabled", "role", "trigger_configurations"], + [ + "deployment_type", + "pre_traffic_hook", + "post_traffic_hook", + "alarms", + "enabled", + "role", + "trigger_configurations", + "condition", + ], ) @@ -37,17 +46,18 @@ class DeploymentPreference(DeploymentPreferenceTuple): """ @classmethod - def from_dict(cls, logical_id, deployment_preference_dict): + def from_dict(cls, logical_id, deployment_preference_dict, condition=None): """ :param logical_id: the logical_id of the resource that owns this deployment preference :param deployment_preference_dict: the dict object taken from the SAM template + :param condition: condition on this deployment preference :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) + return DeploymentPreference(None, None, None, None, False, None, None, None) if "Type" not in deployment_preference_dict: raise InvalidResourceException(logical_id, "'DeploymentPreference' is missing required Property 'Type'") @@ -64,6 +74,15 @@ def from_dict(cls, logical_id, deployment_preference_dict): alarms = deployment_preference_dict.get("Alarms", None) role = deployment_preference_dict.get("Role", None) trigger_configurations = deployment_preference_dict.get("TriggerConfigurations", None) + passthrough_condition = deployment_preference_dict.get("PassthroughCondition", False) + return DeploymentPreference( - deployment_type, pre_traffic_hook, post_traffic_hook, alarms, enabled, role, trigger_configurations + deployment_type, + pre_traffic_hook, + post_traffic_hook, + alarms, + enabled, + role, + trigger_configurations, + condition if passthrough_condition else None, ) diff --git a/samtranslator/model/preferences/deployment_preference_collection.py b/samtranslator/model/preferences/deployment_preference_collection.py index 5f1c13029..bd5be65f9 100644 --- a/samtranslator/model/preferences/deployment_preference_collection.py +++ b/samtranslator/model/preferences/deployment_preference_collection.py @@ -9,6 +9,9 @@ is_intrinsic_if, is_intrinsic_no_value, validate_intrinsic_if_items, + make_combined_condition, + ref, + fnGetAtt, ) from samtranslator.model.update_policy import UpdatePolicy from samtranslator.translator.arn_generator import ArnGenerator @@ -27,6 +30,7 @@ "Linear10PercentEvery10Minutes", "AllAtOnce", ] +CODE_DEPLOY_CONDITION_NAME = "ServerlessCodeDeployCondition" class DeploymentPreferenceCollection(object): @@ -41,20 +45,19 @@ class DeploymentPreferenceCollection(object): def __init__(self): """ - This collection stores an intenral dict of the deployment preferences for each function's - deployment preference in the SAM Template. + This collection stores an internal dict of the deployment preferences for each function's + deployment preference in the SAM Template. """ self._resource_preferences = {} - self.codedeploy_application = self._codedeploy_application() - self.codedeploy_iam_role = self._codedeploy_iam_role() - def add(self, logical_id, deployment_preference_dict): + def add(self, logical_id, deployment_preference_dict, condition=None): """ Add this deployment preference to the collection :raise ValueError if an existing logical id already exists in the _resource_preferences :param logical_id: logical id of the resource where this deployment preference applies :param deployment_preference_dict: the input SAM template deployment preference mapping + :param condition: the condition (if it exists) on the serverless function """ if logical_id in self._resource_preferences: raise ValueError( @@ -63,7 +66,9 @@ def add(self, logical_id, deployment_preference_dict): ) ) - self._resource_preferences[logical_id] = DeploymentPreference.from_dict(logical_id, deployment_preference_dict) + self._resource_preferences[logical_id] = DeploymentPreference.from_dict( + logical_id, deployment_preference_dict, condition + ) def get(self, logical_id): """ @@ -85,18 +90,52 @@ def can_skip_service_role(self): """ return all(preference.role or not preference.enabled for preference in self._resource_preferences.values()) + def needs_resource_condition(self): + """ + If all preferences have a condition, all code deploy resources need to be conditionally created + :return: True, if a condition needs to be created + """ + # If there are any enabled deployment preferences without conditions, return false + return self._resource_preferences and not any( + not preference.condition and preference.enabled for preference in self._resource_preferences.values() + ) + + def get_all_deployment_conditions(self): + """ + Returns a list of all conditions associated with the deployment preference resources + :return: List of condition names + """ + conditions_set = set([preference.condition for preference in self._resource_preferences.values()]) + if None in conditions_set: + # None can exist if there are disabled deployment preference(s) + conditions_set.remove(None) + return list(conditions_set) + + def create_aggregate_deployment_condition(self): + """ + Creates an aggregate deployment condition if necessary + :return: None if <2 conditions are found, otherwise a dictionary of new conditions to add to template + """ + return make_combined_condition(self.get_all_deployment_conditions(), CODE_DEPLOY_CONDITION_NAME) + def enabled_logical_ids(self): """ :return: only the logical id's for the deployment preferences in this collection which are enabled """ return [logical_id for logical_id, preference in self._resource_preferences.items() if preference.enabled] - def _codedeploy_application(self): + def get_codedeploy_application(self): codedeploy_application_resource = CodeDeployApplication(CODEDEPLOY_APPLICATION_LOGICAL_ID) codedeploy_application_resource.ComputePlatform = "Lambda" + if self.needs_resource_condition(): + conditions = self.get_all_deployment_conditions() + condition_name = CODE_DEPLOY_CONDITION_NAME + if len(conditions) <= 1: + condition_name = conditions.pop() + codedeploy_application_resource.set_resource_attribute("Condition", condition_name) return codedeploy_application_resource - def _codedeploy_iam_role(self): + def get_codedeploy_iam_role(self): iam_role = IAMRole(CODE_DEPLOY_SERVICE_ROLE_LOGICAL_ID) iam_role.AssumeRolePolicyDocument = { "Version": "2012-10-17", @@ -120,6 +159,12 @@ def _codedeploy_iam_role(self): ArnGenerator.generate_aws_managed_policy_arn("service-role/AWSCodeDeployRoleForLambda") ] + if self.needs_resource_condition(): + conditions = self.get_all_deployment_conditions() + condition_name = CODE_DEPLOY_CONDITION_NAME + if len(conditions) <= 1: + condition_name = conditions.pop() + iam_role.set_resource_attribute("Condition", condition_name) return iam_role def deployment_group(self, function_logical_id): @@ -137,7 +182,7 @@ def deployment_group(self, function_logical_id): except ValueError as e: raise InvalidResourceException(function_logical_id, str(e)) - deployment_group.ApplicationName = self.codedeploy_application.get_runtime_attr("name") + deployment_group.ApplicationName = ref(CODEDEPLOY_APPLICATION_LOGICAL_ID) deployment_group.AutoRollbackConfiguration = { "Enabled": True, "Events": ["DEPLOYMENT_FAILURE", "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST"], @@ -149,13 +194,16 @@ def deployment_group(self, function_logical_id): deployment_group.DeploymentStyle = {"DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL"} - deployment_group.ServiceRoleArn = self.codedeploy_iam_role.get_runtime_attr("arn") + deployment_group.ServiceRoleArn = fnGetAtt(CODE_DEPLOY_SERVICE_ROLE_LOGICAL_ID, "Arn") if deployment_preference.role: deployment_group.ServiceRoleArn = deployment_preference.role if deployment_preference.trigger_configurations: deployment_group.TriggerConfigurations = deployment_preference.trigger_configurations + if deployment_preference.condition: + deployment_group.set_resource_attribute("Condition", deployment_preference.condition) + return deployment_group def _convert_alarms(self, preference_alarms): @@ -240,7 +288,7 @@ def update_policy(self, function_logical_id): deployment_preference = self.get(function_logical_id) return UpdatePolicy( - self.codedeploy_application.get_runtime_attr("name"), + ref(CODEDEPLOY_APPLICATION_LOGICAL_ID), self.deployment_group(function_logical_id).get_runtime_attr("name"), deployment_preference.pre_traffic_hook, deployment_preference.post_traffic_hook, diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 8ae71e8f5..a277aa189 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -1,5 +1,7 @@ """ SAM macro definitions """ import copy +from typing import Union +from samtranslator.intrinsics.resolver import IntrinsicsResolver import samtranslator.model.eventsources import samtranslator.model.eventsources.pull @@ -139,6 +141,7 @@ def to_cloudformation(self, **kwargs): intrinsics_resolver = kwargs["intrinsics_resolver"] mappings_resolver = kwargs.get("mappings_resolver", None) conditions = kwargs.get("conditions", {}) + feature_toggle = kwargs.get("feature_toggle") if self.DeadLetterQueue: self._validate_dlq() @@ -185,6 +188,8 @@ def to_cloudformation(self, **kwargs): lambda_alias, intrinsics_resolver, mappings_resolver, + self.get_passthrough_resource_attributes(), + feature_toggle, ) event_invoke_policies = [] if self.EventInvokeConfig: @@ -827,10 +832,16 @@ 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, mappings_resolver + self, + deployment_preference_collection, + lambda_alias, + intrinsics_resolver, + mappings_resolver, + passthrough_resource_attributes, + feature_toggle=None, ): if "Enabled" in self.DeploymentPreference: - # resolve intrinsics and mappings for Type + # resolve intrinsics and mappings for Enabled enabled = self.DeploymentPreference["Enabled"] enabled = intrinsics_resolver.resolve_parameter_refs(enabled) enabled = mappings_resolver.resolve_parameter_refs(enabled) @@ -843,10 +854,28 @@ def _validate_deployment_preference_and_add_update_policy( preference_type = mappings_resolver.resolve_parameter_refs(preference_type) self.DeploymentPreference["Type"] = preference_type + if "PassthroughCondition" in self.DeploymentPreference: + self.DeploymentPreference["PassthroughCondition"] = self._resolve_property_to_boolean( + self.DeploymentPreference["PassthroughCondition"], + "PassthroughCondition", + intrinsics_resolver, + mappings_resolver, + ) + elif feature_toggle: + self.DeploymentPreference["PassthroughCondition"] = feature_toggle.is_enabled( + "deployment_preference_condition_fix" + ) + else: + self.DeploymentPreference["PassthroughCondition"] = False + if deployment_preference_collection is None: raise ValueError("deployment_preference_collection required for parsing the deployment preference") - deployment_preference_collection.add(self.logical_id, self.DeploymentPreference) + deployment_preference_collection.add( + self.logical_id, + self.DeploymentPreference, + passthrough_resource_attributes.get("Condition"), + ) if deployment_preference_collection.get(self.logical_id).enabled: if self.AutoPublishAlias is None: @@ -860,6 +889,40 @@ def _validate_deployment_preference_and_add_update_policy( "UpdatePolicy", deployment_preference_collection.update_policy(self.logical_id).to_dict() ) + def _resolve_property_to_boolean( + self, + property_value: Union[bool, str, dict], + property_name: str, + intrinsics_resolver: IntrinsicsResolver, + mappings_resolver: IntrinsicsResolver, + ) -> bool: + """ + Resolves intrinsics, if any, and/or converts string in a given property to boolean. + Raises InvalidResourceException if can't resolve intrinsic or can't resolve string to boolean + + :param property_value: property value to resolve + :param property_name: name/key of property to resolve + :param intrinsics_resolver: resolves intrinsics + :param mappings_resolver: resolves FindInMap + :return bool: resolved boolean value + """ + processed_property_value = intrinsics_resolver.resolve_parameter_refs(property_value) + processed_property_value = mappings_resolver.resolve_parameter_refs(processed_property_value) + + # FIXME: We should support not only true/false, but also yes/no, on/off? See https://yaml.org/type/bool.html + if processed_property_value in [True, "true", "True"]: + return True + elif processed_property_value in [False, "false", "False"]: + return False + elif is_intrinsic(processed_property_value): # couldn't resolve intrinsic + raise InvalidResourceException( + self.logical_id, + f"Unsupported intrinsic: the only intrinsic functions supported for " + f"property {property_name} are FindInMap and parameter Refs.", + ) + else: + raise InvalidResourceException(self.logical_id, f"Invalid value for property {property_name}.") + def _construct_function_url(self, lambda_function, lambda_alias): """ This method is used to construct a lambda url resource diff --git a/samtranslator/translator/translator.py b/samtranslator/translator/translator.py index b40737c36..e4c65f4b0 100644 --- a/samtranslator/translator/translator.py +++ b/samtranslator/translator/translator.py @@ -143,6 +143,7 @@ def translate(self, sam_template, parameter_values, feature_toggle=None, passthr ) kwargs["redeploy_restapi_parameters"] = self.redeploy_restapi_parameters kwargs["shared_api_usage_plan"] = shared_api_usage_plan + kwargs["feature_toggle"] = self.feature_toggle translated = macro.to_cloudformation(**kwargs) supported_resource_refs = macro.get_resource_references(translated, supported_resource_refs) @@ -168,10 +169,14 @@ def translate(self, sam_template, parameter_values, feature_toggle=None, passthr document_errors.append(e) if deployment_preference_collection.any_enabled(): - template["Resources"].update(deployment_preference_collection.codedeploy_application.to_dict()) + template["Resources"].update(deployment_preference_collection.get_codedeploy_application().to_dict()) + if deployment_preference_collection.needs_resource_condition(): + new_conditions = deployment_preference_collection.create_aggregate_deployment_condition() + if new_conditions: + template.get("Conditions").update(new_conditions) if not deployment_preference_collection.can_skip_service_role(): - template["Resources"].update(deployment_preference_collection.codedeploy_iam_role.to_dict()) + template["Resources"].update(deployment_preference_collection.get_codedeploy_iam_role().to_dict()) for logical_id in deployment_preference_collection.enabled_logical_ids(): try: diff --git a/tests/translator/input/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.yaml b/tests/translator/input/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.yaml new file mode 100644 index 000000000..6e110e927 --- /dev/null +++ b/tests/translator/input/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.yaml @@ -0,0 +1,72 @@ +# Tests unsupported intrinsic and invalid type in the PassthroughCondition property + +Mappings: + HelloWorldMap: + hello: + key1: true + key2: false + world: + key1: false + key2: true + +Parameters: + FnName: + Type: String + ProvisionedConcurrency: + Type: String + Default: 10 + EnableAliasProvisionedConcurrency: + Type: String + AllowedValues: + - true + - false + Default: true + DefaultTrueParam: + Type: String + Default: "true" + DefaultFalseParam: + Type: String + Default: "false" + HelloWorldParam: + Type: String + Default: "hello" + +Conditions: + AliasProvisionedConcurrencyEnabled: !Equals [!Ref EnableAliasProvisionedConcurrency, true] + FunctionCondition: !Equals [true, true] + +Resources: + InvalidType: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: ["hello"] + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' + + UnsupportedIntrinsic: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: !If + - AliasProvisionedConcurrencyEnabled + - true + - false + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' diff --git a/tests/translator/input/function_with_deployment_no_service_role_with_passthrough.yaml b/tests/translator/input/function_with_deployment_no_service_role_with_passthrough.yaml new file mode 100644 index 000000000..6a033caee --- /dev/null +++ b/tests/translator/input/function_with_deployment_no_service_role_with_passthrough.yaml @@ -0,0 +1,48 @@ +Conditions: + Condition1: + Fn::Equals: + - true + - true + +Globals: + Function: + AutoPublishAlias: live + DeploymentPreference: + Type: AllAtOnce + Role: !Ref DeploymentRole + PassthroughCondition: true + +Resources: + + MinimalFunction: + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + OtherFunction: + Condition: Condition1 + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + + DeploymentRole: + Type: AWS::IAM::Role + Properties: + ManagedPolicyArns: + - arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Action: + - sts:AssumeRole + Effect: Allow + Principal: + Service: + - codedeploy.amazonaws.com + + + diff --git a/tests/translator/input/function_with_deployment_no_service_role.yaml b/tests/translator/input/function_with_deployment_no_service_role_without_passthrough.yaml similarity index 90% rename from tests/translator/input/function_with_deployment_no_service_role.yaml rename to tests/translator/input/function_with_deployment_no_service_role_without_passthrough.yaml index ae40a6a00..ef92307c8 100644 --- a/tests/translator/input/function_with_deployment_no_service_role.yaml +++ b/tests/translator/input/function_with_deployment_no_service_role_without_passthrough.yaml @@ -1,3 +1,9 @@ +Conditions: + Condition1: + Fn::Equals: + - true + - true + Globals: Function: AutoPublishAlias: live @@ -15,6 +21,7 @@ Resources: Runtime: python2.7 OtherFunction: + Condition: Condition1 Type: 'AWS::Serverless::Function' Properties: CodeUri: s3://sam-demo-bucket/hello.zip diff --git a/tests/translator/input/function_with_deployment_preference_condition_with_passthrough.yaml b/tests/translator/input/function_with_deployment_preference_condition_with_passthrough.yaml new file mode 100644 index 000000000..b112e4d30 --- /dev/null +++ b/tests/translator/input/function_with_deployment_preference_condition_with_passthrough.yaml @@ -0,0 +1,31 @@ +Parameters: + FnName: + Type: String + ProvisionedConcurrency: + Type: String + Default: 10 + EnableAliasProvisionedConcurrency: + Type: String + AllowedValues: + - true + - false + Default: true +Conditions: + AliasProvisionedConcurrencyEnabled: !Equals [!Ref EnableAliasProvisionedConcurrency, true] + FunctionCondition: !Equals [true, true] +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: true + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' diff --git a/tests/translator/input/function_with_deployment_preference_condition_without_passthrough.yaml b/tests/translator/input/function_with_deployment_preference_condition_without_passthrough.yaml new file mode 100644 index 000000000..06e788bfe --- /dev/null +++ b/tests/translator/input/function_with_deployment_preference_condition_without_passthrough.yaml @@ -0,0 +1,30 @@ +Parameters: + FnName: + Type: String + ProvisionedConcurrency: + Type: String + Default: 10 + EnableAliasProvisionedConcurrency: + Type: String + AllowedValues: + - true + - false + Default: true +Conditions: + AliasProvisionedConcurrencyEnabled: !Equals [!Ref EnableAliasProvisionedConcurrency, true] + FunctionCondition: !Equals [true, true] +Resources: + MinimalFunction: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' \ No newline at end of file diff --git a/tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.yaml b/tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.yaml new file mode 100644 index 000000000..78445ec10 --- /dev/null +++ b/tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.yaml @@ -0,0 +1,91 @@ +Conditions: + Condition1: + Fn::Equals: + - true + - true + Condition2: + Fn::Equals: + - true + - false + Condition3: + Fn::Equals: + - true + - false + +Parameters: + MyFalseParameter: + Type: String + Default: False + +Resources: + MinimalFunction: + Condition: Condition1 + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery2Minutes + PassthroughCondition: true + + MinimalFunctionWithMinimalDeploymentPreference: + Type: 'AWS::Serverless::Function' + Condition: Condition2 + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: livewithdeployment + DeploymentPreference: + Type: Canary10Percent5Minutes + PassthroughCondition: true + + MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms: + Type: 'AWS::Serverless::Function' + Condition: Condition2 + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: livewithdeploymentwithhooksandalarms + DeploymentPreference: + Type: Linear10PercentEvery2Minutes + Hooks: + PreTraffic: !Ref MySanityTestFunction + PostTraffic: !Ref MyValidationTestFunction + Alarms: + - !Ref MyCloudWatchAlarm + PassthroughCondition: true + + MySanityTestFunction: + Type: 'AWS::Serverless::Function' + Condition: Condition3 + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/mySanityTestFunction.zip + DeploymentPreference: + Enabled: False + PassthroughCondition: true + + MyValidationTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/myValidationTestFunction.zip + DeploymentPreference: + Enabled: !Ref MyFalseParameter + PassthroughCondition: true + + MyCloudWatchAlarm: + Type: AWS::CloudWatch::Alarm + Properties: + ComparisonOperator: GreaterThanThreshold + EvaluationPeriods: 1 + MetricName: MyMetric + Namespace: AWS/EC2 + Period: 300 + Threshold: 10 diff --git a/tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.yaml b/tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.yaml new file mode 100644 index 000000000..f9e994109 --- /dev/null +++ b/tests/translator/input/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.yaml @@ -0,0 +1,86 @@ +Conditions: + Condition1: + Fn::Equals: + - true + - true + Condition2: + Fn::Equals: + - true + - false + Condition3: + Fn::Equals: + - true + - false + +Parameters: + MyFalseParameter: + Type: String + Default: False + +Resources: + MinimalFunction: + Condition: Condition1 + Type: 'AWS::Serverless::Function' + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery2Minutes + + MinimalFunctionWithMinimalDeploymentPreference: + Type: 'AWS::Serverless::Function' + Condition: Condition2 + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: livewithdeployment + DeploymentPreference: + Type: Canary10Percent5Minutes + + MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms: + Type: 'AWS::Serverless::Function' + Condition: Condition2 + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: livewithdeploymentwithhooksandalarms + DeploymentPreference: + Type: Linear10PercentEvery2Minutes + Hooks: + PreTraffic: !Ref MySanityTestFunction + PostTraffic: !Ref MyValidationTestFunction + Alarms: + - !Ref MyCloudWatchAlarm + + MySanityTestFunction: + Type: 'AWS::Serverless::Function' + Condition: Condition3 + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/mySanityTestFunction.zip + DeploymentPreference: + Enabled: False + + MyValidationTestFunction: + Type: 'AWS::Serverless::Function' + Properties: + Handler: hello.handler + Runtime: python2.7 + CodeUri: s3://my-bucket/myValidationTestFunction.zip + DeploymentPreference: + Enabled: !Ref MyFalseParameter + + MyCloudWatchAlarm: + Type: AWS::CloudWatch::Alarm + Properties: + ComparisonOperator: GreaterThanThreshold + EvaluationPeriods: 1 + MetricName: MyMetric + Namespace: AWS/EC2 + Period: 300 + Threshold: 10 diff --git a/tests/translator/input/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.yaml b/tests/translator/input/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.yaml new file mode 100644 index 000000000..0c438d554 --- /dev/null +++ b/tests/translator/input/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.yaml @@ -0,0 +1,110 @@ +# Tests supported intrinsics in the PassthroughCondition property + +Mappings: + HelloWorldMap: + hello: + key1: true + key2: false + world: + key1: false + key2: true + +Parameters: + FnName: + Type: String + ProvisionedConcurrency: + Type: String + Default: 10 + EnableAliasProvisionedConcurrency: + Type: String + AllowedValues: + - true + - false + Default: true + DefaultTrueParam: + Type: String + Default: "true" + DefaultFalseParam: + Type: String + Default: "false" + HelloParam: + Type: String + Default: "hello" + WorldParam: + Type: String + Default: "world" + +Conditions: + AliasProvisionedConcurrencyEnabled: !Equals [!Ref EnableAliasProvisionedConcurrency, true] + FunctionCondition: !Equals [true, true] + +Resources: + TrueRef: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: !Ref DefaultTrueParam + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' + + FalseRef: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: !Ref DefaultFalseParam + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' + + TrueFindInMap: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: !FindInMap + - HelloWorldMap + - !Ref HelloParam + - key1 + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' + + FalseFindInMap: + Type: 'AWS::Serverless::Function' + Condition: FunctionCondition + Properties: + CodeUri: s3://sam-demo-bucket/hello.zip + Handler: hello.handler + Runtime: python2.7 + AutoPublishAlias: live + DeploymentPreference: + Type: Linear10PercentEvery3Minutes + PassthroughCondition: !FindInMap + - HelloWorldMap + - !Ref WorldParam + - key1 + ProvisionedConcurrencyConfig: !If + - AliasProvisionedConcurrencyEnabled + - ProvisionedConcurrentExecutions: !Ref ProvisionedConcurrency + - !Ref 'AWS::NoValue' \ 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 e6fbc9d8e..2f7a7645d 100644 --- a/tests/translator/model/preferences/test_deployment_preference.py +++ b/tests/translator/model/preferences/test_deployment_preference.py @@ -16,31 +16,51 @@ def setUp(self): "TriggerTargetArn": {"Ref": "MySNSTopic"}, "TriggerName": "TestTrigger", } - self.expected_deployment_preference = DeploymentPreference( - self.deployment_type, + self.condition = "condition" + + def test_from_dict_with_intrinsic_function_type(self): + + type = {"Ref": "SomeType"} + expected_deployment_preference = DeploymentPreference( + type, self.pre_traffic_hook, self.post_traffic_hook, self.alarms, True, self.role, self.trigger_configurations, + None, ) - def test_from_dict_with_intrinsic_function_type(self): + deployment_preference_yaml_dict = dict() + deployment_preference_yaml_dict["Type"] = type + deployment_preference_yaml_dict["Hooks"] = { + "PreTraffic": self.pre_traffic_hook, + "PostTraffic": self.post_traffic_hook, + } + deployment_preference_yaml_dict["Alarms"] = self.alarms + deployment_preference_yaml_dict["Role"] = self.role + deployment_preference_yaml_dict["TriggerConfigurations"] = self.trigger_configurations + deployment_preference_from_yaml_dict = DeploymentPreference.from_dict( + "logical_id", deployment_preference_yaml_dict, self.condition + ) - type = {"Ref": "SomeType"} + self.assertEqual(expected_deployment_preference, deployment_preference_from_yaml_dict) + + def test_from_dict(self): expected_deployment_preference = DeploymentPreference( - type, + self.deployment_type, self.pre_traffic_hook, self.post_traffic_hook, self.alarms, True, self.role, self.trigger_configurations, + None, ) deployment_preference_yaml_dict = dict() - deployment_preference_yaml_dict["Type"] = type + deployment_preference_yaml_dict["Type"] = self.deployment_type deployment_preference_yaml_dict["Hooks"] = { "PreTraffic": self.pre_traffic_hook, "PostTraffic": self.post_traffic_hook, @@ -49,12 +69,23 @@ def test_from_dict_with_intrinsic_function_type(self): deployment_preference_yaml_dict["Role"] = self.role deployment_preference_yaml_dict["TriggerConfigurations"] = self.trigger_configurations deployment_preference_from_yaml_dict = DeploymentPreference.from_dict( - "logical_id", deployment_preference_yaml_dict + "logical_id", deployment_preference_yaml_dict, self.condition ) self.assertEqual(expected_deployment_preference, deployment_preference_from_yaml_dict) - def test_from_dict(self): + def test_from_dict_with_passthrough_condition(self): + expected_deployment_preference = DeploymentPreference( + self.deployment_type, + self.pre_traffic_hook, + self.post_traffic_hook, + self.alarms, + True, + self.role, + self.trigger_configurations, + self.condition, + ) + deployment_preference_yaml_dict = dict() deployment_preference_yaml_dict["Type"] = self.deployment_type deployment_preference_yaml_dict["Hooks"] = { @@ -64,14 +95,15 @@ def test_from_dict(self): deployment_preference_yaml_dict["Alarms"] = self.alarms deployment_preference_yaml_dict["Role"] = self.role deployment_preference_yaml_dict["TriggerConfigurations"] = self.trigger_configurations + deployment_preference_yaml_dict["PassthroughCondition"] = True deployment_preference_from_yaml_dict = DeploymentPreference.from_dict( - "logical_id", deployment_preference_yaml_dict + "logical_id", deployment_preference_yaml_dict, self.condition ) - self.assertEqual(self.expected_deployment_preference, deployment_preference_from_yaml_dict) + self.assertEqual(expected_deployment_preference, deployment_preference_from_yaml_dict) def test_from_dict_with_disabled_preference_does_not_require_other_parameters(self): - expected_deployment_preference = DeploymentPreference(None, None, None, None, False, None, None) + expected_deployment_preference = DeploymentPreference(None, None, None, None, False, None, None, None) deployment_preference_yaml_dict = dict() deployment_preference_yaml_dict["Enabled"] = False @@ -82,7 +114,7 @@ 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) + expected_deployment_preference = DeploymentPreference(None, None, None, None, False, None, None, None) deployment_preference_yaml_dict = dict() deployment_preference_yaml_dict["Enabled"] = "False" @@ -93,7 +125,7 @@ def test_from_dict_with_string_disabled_preference_does_not_require_other_parame 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) + expected_deployment_preference = DeploymentPreference(None, None, None, None, False, None, None, None) deployment_preference_yaml_dict = dict() deployment_preference_yaml_dict["Enabled"] = "false" diff --git a/tests/translator/model/preferences/test_deployment_preference_collection.py b/tests/translator/model/preferences/test_deployment_preference_collection.py index 6ca0d2c59..2ee6bf81d 100644 --- a/tests/translator/model/preferences/test_deployment_preference_collection.py +++ b/tests/translator/model/preferences/test_deployment_preference_collection.py @@ -18,6 +18,7 @@ def setup_method(self, method): self.post_traffic_host_global = "post_traffic_function_ref" self.pre_traffic_hook_global = "pre_traffic_function_ref" self.function_logical_id = "FunctionLogicalId" + self.condition = "CodeDeployCondition" @patch("boto3.session.Session.region_name", "ap-southeast-1") def test_when_no_global_dict_each_local_deployment_preference_requires_parameters(self): @@ -37,7 +38,7 @@ def test_codedeploy_application(self): expected_codedeploy_application_resource.ComputePlatform = "Lambda" self.assertEqual( - DeploymentPreferenceCollection().codedeploy_application.to_dict(), + DeploymentPreferenceCollection().get_codedeploy_application().to_dict(), expected_codedeploy_application_resource.to_dict(), ) @@ -59,7 +60,7 @@ def test_codedeploy_iam_role(self): ] self.assertEqual( - DeploymentPreferenceCollection().codedeploy_iam_role.to_dict(), expected_codedeploy_iam_role.to_dict() + DeploymentPreferenceCollection().get_codedeploy_iam_role().to_dict(), expected_codedeploy_iam_role.to_dict() ) @patch("boto3.session.Session.region_name", "ap-southeast-1") diff --git a/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json new file mode 100644 index 000000000..801fd6cb3 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json @@ -0,0 +1,283 @@ +{ + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "OtherFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition1" + }, + "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" + } + ] + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "OtherFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + } + }, + "Condition": "Condition1" + }, + "OtherFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "DeploymentRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "OtherFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "OtherFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "OtherFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "OtherFunctionDeploymentGroup" + } + } + }, + "Condition": "Condition1", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "OtherFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "OtherFunction" + }, + "Name": "live" + } + } + } +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_no_service_role.json b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json similarity index 67% rename from tests/translator/output/aws-cn/function_with_deployment_no_service_role.json rename to tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json index 65d6a4483..704201e99 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_no_service_role.json +++ b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json @@ -1,79 +1,78 @@ { + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, "Resources": { "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "ServiceRoleArn": { "Ref": "DeploymentRole" - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", + "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } } - }, + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "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", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -81,21 +80,7 @@ } } ] - } - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } - } - }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], @@ -104,15 +89,30 @@ "Value": "SAM", "Key": "lambda:createdBy" } - ], + ] + } + }, + "OtherFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + } + }, + "Condition": "Condition1" + }, + "OtherFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -120,23 +120,33 @@ } } ] - } - } - }, + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, "DeploymentRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" @@ -146,125 +156,127 @@ ] } } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "ServiceRoleArn": { "Ref": "DeploymentRole" - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", + "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } } - }, + }, "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "Type": "AWS::CodeDeploy::Application", "Properties": { "ComputePlatform": "Lambda" } - }, + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } } - }, + }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "OtherFunctionRole", + "OtherFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] - } - }, + }, + "Condition": "Condition1" + }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "MinimalFunctionDeploymentGroup" } } - }, + }, "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "MinimalFunctionVersion640128d35d", "Version" ] - }, + }, "FunctionName": { "Ref": "MinimalFunction" - }, + }, "Name": "live" } - }, + }, "OtherFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "OtherFunctionDeploymentGroup" } } - }, + }, + "Condition": "Condition1", "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] - }, + }, "FunctionName": { "Ref": "OtherFunction" - }, + }, "Name": "live" } } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json new file mode 100644 index 000000000..1e82b6612 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json @@ -0,0 +1,208 @@ +{ + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "Default": true, + "Type": "String", + "AllowedValues": [ + true, + false + ] + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + ] + } + } + ] + } + }, + "Condition": "FunctionCondition" + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "FunctionCondition", + "Properties": { + "Name": "live", + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + } + } + } + } +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json new file mode 100644 index 000000000..5660e1f9f --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json @@ -0,0 +1,205 @@ +{ + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "Default": true, + "Type": "String", + "AllowedValues": [ + true, + false + ] + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "FunctionCondition", + "Properties": { + "Name": "live", + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + } + } + } + } + } \ No newline at end of file diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json new file mode 100644 index 000000000..2999c3fd1 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json @@ -0,0 +1,585 @@ +{ + "Conditions": { + "ServerlessCodeDeployCondition": { + "Fn::Or": [ + { + "Condition": "Condition2" + }, + { + "Condition": "Condition1" + } + ] + }, + "Condition3": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition2": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "MyFalseParameter": { + "Default": false, + "Type": "String" + } + }, + "Resources": { + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "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" + } + ] + }, + "Condition": "Condition1" + }, + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "EvaluationPeriods": 1, + "Namespace": "AWS/EC2", + "Period": 300, + "ComparisonOperator": "GreaterThanThreshold", + "Threshold": 10, + "MetricName": "MyMetric" + } + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition1" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Condition": "Condition2" + }, + "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" + ] + } + } + ] + } + }, + "Condition": "ServerlessCodeDeployCondition" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "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": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Condition": "Condition2", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "Name": "livewithdeploymentwithhooksandalarms" + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition3" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "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": "Linear10PercentEvery2Minutes" + } + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + }, + "Condition": "Condition2", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "Name": "livewithdeployment" + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition3" + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Condition": "ServerlessCodeDeployCondition" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Condition": "Condition1" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "Condition1", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "MyValidationTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "myValidationTestFunction.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MyValidationTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json new file mode 100644 index 000000000..6e2b17324 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json @@ -0,0 +1,570 @@ +{ + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + }, + "Condition2": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition3": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Parameters": { + "MyFalseParameter": { + "Type": "String", + "Default": false + } + }, + "Resources": { + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition1", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition1", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition1", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition2", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + }, + "Properties": { + "Name": "livewithdeployment", + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition2", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Properties": { + "Name": "livewithdeploymentwithhooksandalarms", + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition3", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition3", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "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": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + } + }, + "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": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "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": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "AlarmConfiguration": { + "Enabled": true, + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ] + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + } + } +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json b/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json new file mode 100644 index 000000000..7e26228d8 --- /dev/null +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json @@ -0,0 +1,649 @@ +{ + "Mappings": { + "HelloWorldMap": { + "hello": { + "key1": true, + "key2": false + }, + "world": { + "key1": false, + "key2": true + } + } + }, + "Parameters": { + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Type": "String", + "Default": 10 + }, + "EnableAliasProvisionedConcurrency": { + "Type": "String", + "AllowedValues": [ + true, + false + ], + "Default": true + }, + "DefaultTrueParam": { + "Type": "String", + "Default": "true" + }, + "DefaultFalseParam": { + "Type": "String", + "Default": "false" + }, + "HelloParam": { + "Type": "String", + "Default": "hello" + }, + "WorldParam": { + "Type": "String", + "Default": "world" + } + }, + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "TrueRef": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueRefVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" + } + } + }, + "TrueRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueRefDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "TrueRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueRefVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TrueRefRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseRef": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseRefVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + } + } + }, + "FalseRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseRefDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "FalseRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseRefVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "FalseRefRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueFindInMap": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueFindInMapVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + } + } + }, + "TrueFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueFindInMapDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "TrueFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueFindInMapVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TrueFindInMapRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseFindInMap": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseFindInMapVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + } + } + }, + "FalseFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseFindInMapDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "FalseFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseFindInMapVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "FalseFindInMapRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + } + }, + "TrueRefDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "FunctionCondition", + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "FalseRefDeploymentGroup": { + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "TrueFindInMapDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "FunctionCondition", + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "FalseFindInMapDeploymentGroup": { + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json new file mode 100644 index 000000000..8300aab2f --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json @@ -0,0 +1,283 @@ +{ + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "OtherFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition1" + }, + "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" + } + ] + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "OtherFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + } + }, + "Condition": "Condition1" + }, + "OtherFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "DeploymentRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "OtherFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "OtherFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "OtherFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "OtherFunctionDeploymentGroup" + } + } + }, + "Condition": "Condition1", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "OtherFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "OtherFunction" + }, + "Name": "live" + } + } + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role.json b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json similarity index 67% rename from tests/translator/output/aws-us-gov/function_with_deployment_no_service_role.json rename to tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json index ca6cf4a1e..ad07002d0 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json @@ -1,79 +1,78 @@ { + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, "Resources": { "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "ServiceRoleArn": { "Ref": "DeploymentRole" - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", + "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } } - }, + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "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", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -81,21 +80,7 @@ } } ] - } - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } - } - }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], @@ -104,15 +89,30 @@ "Value": "SAM", "Key": "lambda:createdBy" } - ], + ] + } + }, + "OtherFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + } + }, + "Condition": "Condition1" + }, + "OtherFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -120,23 +120,33 @@ } } ] - } - } - }, + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, "DeploymentRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" @@ -146,125 +156,127 @@ ] } } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "ServiceRoleArn": { "Ref": "DeploymentRole" - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", + "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } } - }, + }, "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "Type": "AWS::CodeDeploy::Application", "Properties": { "ComputePlatform": "Lambda" } - }, + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } } - }, + }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "OtherFunctionRole", + "OtherFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] - } - }, + }, + "Condition": "Condition1" + }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "MinimalFunctionDeploymentGroup" } } - }, + }, "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "MinimalFunctionVersion640128d35d", "Version" ] - }, + }, "FunctionName": { "Ref": "MinimalFunction" - }, + }, "Name": "live" } - }, + }, "OtherFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "OtherFunctionDeploymentGroup" } } - }, + }, + "Condition": "Condition1", "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] - }, + }, "FunctionName": { "Ref": "OtherFunction" - }, + }, "Name": "live" } } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json new file mode 100644 index 000000000..385a1f49f --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json @@ -0,0 +1,208 @@ +{ + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "Default": true, + "Type": "String", + "AllowedValues": [ + true, + false + ] + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + ] + } + } + ] + } + }, + "Condition": "FunctionCondition" + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "FunctionCondition", + "Properties": { + "Name": "live", + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + } + } + } + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json new file mode 100644 index 000000000..d69bc3b59 --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json @@ -0,0 +1,205 @@ +{ + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "Default": true, + "Type": "String", + "AllowedValues": [ + true, + false + ] + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "FunctionCondition", + "Properties": { + "Name": "live", + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + } + } + } + } + } \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json new file mode 100644 index 000000000..d534f9d6f --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json @@ -0,0 +1,585 @@ +{ + "Conditions": { + "ServerlessCodeDeployCondition": { + "Fn::Or": [ + { + "Condition": "Condition2" + }, + { + "Condition": "Condition1" + } + ] + }, + "Condition3": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition2": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "MyFalseParameter": { + "Default": false, + "Type": "String" + } + }, + "Resources": { + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "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" + } + ] + }, + "Condition": "Condition1" + }, + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "EvaluationPeriods": 1, + "Namespace": "AWS/EC2", + "Period": 300, + "ComparisonOperator": "GreaterThanThreshold", + "Threshold": 10, + "MetricName": "MyMetric" + } + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition1" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Condition": "Condition2" + }, + "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" + ] + } + } + ] + } + }, + "Condition": "ServerlessCodeDeployCondition" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "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": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Condition": "Condition2", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "Name": "livewithdeploymentwithhooksandalarms" + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition3" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "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": "Linear10PercentEvery2Minutes" + } + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + }, + "Condition": "Condition2", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "Name": "livewithdeployment" + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition3" + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Condition": "ServerlessCodeDeployCondition" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Condition": "Condition1" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "Condition1", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "MyValidationTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "myValidationTestFunction.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MyValidationTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json new file mode 100644 index 000000000..aaf023072 --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json @@ -0,0 +1,570 @@ +{ + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + }, + "Condition2": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition3": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Parameters": { + "MyFalseParameter": { + "Type": "String", + "Default": false + } + }, + "Resources": { + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition1", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition1", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition1", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition2", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + }, + "Properties": { + "Name": "livewithdeployment", + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition2", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Properties": { + "Name": "livewithdeploymentwithhooksandalarms", + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition3", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition3", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "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": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + } + }, + "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": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "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": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "AlarmConfiguration": { + "Enabled": true, + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ] + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json new file mode 100644 index 000000000..05b248c26 --- /dev/null +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json @@ -0,0 +1,649 @@ +{ + "Mappings": { + "HelloWorldMap": { + "hello": { + "key1": true, + "key2": false + }, + "world": { + "key1": false, + "key2": true + } + } + }, + "Parameters": { + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Type": "String", + "Default": 10 + }, + "EnableAliasProvisionedConcurrency": { + "Type": "String", + "AllowedValues": [ + true, + false + ], + "Default": true + }, + "DefaultTrueParam": { + "Type": "String", + "Default": "true" + }, + "DefaultFalseParam": { + "Type": "String", + "Default": "false" + }, + "HelloParam": { + "Type": "String", + "Default": "hello" + }, + "WorldParam": { + "Type": "String", + "Default": "world" + } + }, + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "TrueRef": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueRefVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" + } + } + }, + "TrueRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueRefDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "TrueRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueRefVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TrueRefRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseRef": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseRefVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + } + } + }, + "FalseRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseRefDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "FalseRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseRefVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "FalseRefRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueFindInMap": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueFindInMapVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + } + } + }, + "TrueFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueFindInMapDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "TrueFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueFindInMapVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TrueFindInMapRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseFindInMap": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseFindInMapVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + } + } + }, + "FalseFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseFindInMapDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "FalseFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseFindInMapVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "FalseFindInMapRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + } + }, + "TrueRefDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "FunctionCondition", + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "FalseRefDeploymentGroup": { + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "TrueFindInMapDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "FunctionCondition", + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "FalseFindInMapDeploymentGroup": { + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json b/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json new file mode 100644 index 000000000..931b1c7d2 --- /dev/null +++ b/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json @@ -0,0 +1,3 @@ +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [InvalidType] is invalid. Invalid value for property PassthroughCondition. Resource with id [UnsupportedIntrinsic] is invalid. Unsupported intrinsic: the only intrinsic functions supported for property PassthroughCondition are FindInMap and parameter Refs." +} \ No newline at end of file diff --git a/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json b/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json new file mode 100644 index 000000000..1a6c407f6 --- /dev/null +++ b/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json @@ -0,0 +1,283 @@ +{ + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "OtherFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition1" + }, + "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" + } + ] + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "OtherFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + } + }, + "Condition": "Condition1" + }, + "OtherFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "DeploymentRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" + ], + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + } + } + }, + "MinimalFunctionDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "OtherFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "OtherFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "OtherFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "OtherFunctionDeploymentGroup" + } + } + }, + "Condition": "Condition1", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "OtherFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "OtherFunction" + }, + "Name": "live" + } + } + } +} diff --git a/tests/translator/output/function_with_deployment_no_service_role.json b/tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json similarity index 67% rename from tests/translator/output/function_with_deployment_no_service_role.json rename to tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json index ef9ed4aa6..e3b229376 100644 --- a/tests/translator/output/function_with_deployment_no_service_role.json +++ b/tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json @@ -1,79 +1,78 @@ { + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, "Resources": { "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "ServiceRoleArn": { "Ref": "DeploymentRole" - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", + "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } } - }, + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] } - }, + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "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", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -81,21 +80,7 @@ } } ] - } - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } - } - }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], @@ -104,15 +89,30 @@ "Value": "SAM", "Key": "lambda:createdBy" } - ], + ] + } + }, + "OtherFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + } + }, + "Condition": "Condition1" + }, + "OtherFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" @@ -120,23 +120,33 @@ } } ] - } - } - }, + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, "DeploymentRole": { - "Type": "AWS::IAM::Role", + "Type": "AWS::IAM::Role", "Properties": { "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" - ], + ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", + "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" @@ -146,125 +156,127 @@ ] } } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "ServiceRoleArn": { "Ref": "DeploymentRole" - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", + "DeploymentType": "BLUE_GREEN", "DeploymentOption": "WITH_TRAFFIC_CONTROL" } } - }, + }, "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "Type": "AWS::CodeDeploy::Application", "Properties": { "ComputePlatform": "Lambda" } - }, + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } } - }, + }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Type": "AWS::Lambda::Function", "Properties": { + "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, "Role": { "Fn::GetAtt": [ - "OtherFunctionRole", + "OtherFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", + "Value": "SAM", "Key": "lambda:createdBy" } ] - } - }, + }, + "Condition": "Condition1" + }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "MinimalFunctionDeploymentGroup" } } - }, + }, "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "MinimalFunctionVersion640128d35d", "Version" ] - }, + }, "FunctionName": { "Ref": "MinimalFunction" - }, + }, "Name": "live" } - }, + }, "OtherFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "OtherFunctionDeploymentGroup" } } - }, + }, + "Condition": "Condition1", "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] - }, + }, "FunctionName": { "Ref": "OtherFunction" - }, + }, "Name": "live" } } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json b/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json new file mode 100644 index 000000000..07936044d --- /dev/null +++ b/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json @@ -0,0 +1,208 @@ +{ + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "Default": true, + "Type": "String", + "AllowedValues": [ + true, + false + ] + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + ] + } + } + ] + } + }, + "Condition": "FunctionCondition" + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "FunctionCondition", + "Properties": { + "Name": "live", + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + } + } + } + } +} diff --git a/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json b/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json new file mode 100644 index 000000000..643c86b29 --- /dev/null +++ b/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json @@ -0,0 +1,205 @@ +{ + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "Default": true, + "Type": "String", + "AllowedValues": [ + true, + false + ] + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + ] + }, + "Condition": "FunctionCondition" + }, + "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" + } + }, + "Condition": "FunctionCondition" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "FunctionCondition", + "Properties": { + "Name": "live", + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + } + } + } + } + } \ No newline at end of file diff --git a/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json new file mode 100644 index 000000000..f908e21be --- /dev/null +++ b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json @@ -0,0 +1,585 @@ +{ + "Conditions": { + "ServerlessCodeDeployCondition": { + "Fn::Or": [ + { + "Condition": "Condition2" + }, + { + "Condition": "Condition1" + } + ] + }, + "Condition3": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition2": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition1": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "MyFalseParameter": { + "Default": false, + "Type": "String" + } + }, + "Resources": { + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "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" + } + ] + }, + "Condition": "Condition1" + }, + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "EvaluationPeriods": 1, + "Namespace": "AWS/EC2", + "Period": 300, + "ComparisonOperator": "GreaterThanThreshold", + "Threshold": 10, + "MetricName": "MyMetric" + } + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "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": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition1" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Condition": "Condition2" + }, + "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" + ] + } + } + ] + } + }, + "Condition": "ServerlessCodeDeployCondition" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "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": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Condition": "Condition2", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "Name": "livewithdeploymentwithhooksandalarms" + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition1" + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition3" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "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": "Linear10PercentEvery2Minutes" + } + ] + }, + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition2" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + }, + "Condition": "Condition2", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "Name": "livewithdeployment" + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + }, + "Condition": "Condition3" + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Condition": "ServerlessCodeDeployCondition" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Condition": "Condition1" + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Condition": "Condition1", + "Properties": { + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "FunctionName": { + "Ref": "MinimalFunction" + }, + "Name": "live" + } + }, + "MyValidationTestFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Handler": "hello.handler", + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "myValidationTestFunction.zip" + }, + "Role": { + "Fn::GetAtt": [ + "MyValidationTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Value": "SAM", + "Key": "lambda:createdBy" + } + ] + } + } + } +} diff --git a/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json new file mode 100644 index 000000000..0519f0b44 --- /dev/null +++ b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json @@ -0,0 +1,570 @@ +{ + "Conditions": { + "Condition1": { + "Fn::Equals": [ + true, + true + ] + }, + "Condition2": { + "Fn::Equals": [ + true, + false + ] + }, + "Condition3": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Parameters": { + "MyFalseParameter": { + "Type": "String", + "Default": false + } + }, + "Resources": { + "MyCloudWatchAlarm": { + "Type": "AWS::CloudWatch::Alarm", + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + } + }, + "MinimalFunction": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition1", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + } + }, + "MinimalFunctionAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition1", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition1", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition2", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + }, + "Properties": { + "Name": "livewithdeployment", + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Type": "AWS::Lambda::Alias", + "Condition": "Condition2", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + } + } + }, + "Properties": { + "Name": "livewithdeploymentwithhooksandalarms", + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MySanityTestFunction": { + "Type": "AWS::Lambda::Function", + "Condition": "Condition3", + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MySanityTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Condition": "Condition3", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "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": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "MyValidationTestFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + } + }, + "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": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "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": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Properties": { + "AlarmConfiguration": { + "Enabled": true, + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ] + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + } + } +} diff --git a/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json b/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json new file mode 100644 index 000000000..9efc3b9c1 --- /dev/null +++ b/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json @@ -0,0 +1,649 @@ +{ + "Mappings": { + "HelloWorldMap": { + "hello": { + "key1": true, + "key2": false + }, + "world": { + "key1": false, + "key2": true + } + } + }, + "Parameters": { + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Type": "String", + "Default": 10 + }, + "EnableAliasProvisionedConcurrency": { + "Type": "String", + "AllowedValues": [ + true, + false + ], + "Default": true + }, + "DefaultTrueParam": { + "Type": "String", + "Default": "true" + }, + "DefaultFalseParam": { + "Type": "String", + "Default": "false" + }, + "HelloParam": { + "Type": "String", + "Default": "hello" + }, + "WorldParam": { + "Type": "String", + "Default": "world" + } + }, + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Resources": { + "TrueRef": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueRefVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" + } + } + }, + "TrueRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueRefDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "TrueRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueRefVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TrueRefRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseRef": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseRefVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + } + } + }, + "FalseRefAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseRefDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "FalseRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseRefVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "FalseRefRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueFindInMap": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "TrueFindInMapVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + } + } + }, + "TrueFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueFindInMapDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "TrueFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueFindInMapVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "TrueFindInMapRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseFindInMap": { + "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "FalseFindInMapVersion640128d35d": { + "Type": "AWS::Lambda::Version", + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + } + } + }, + "FalseFindInMapAliaslive": { + "Type": "AWS::Lambda::Alias", + "Condition": "FunctionCondition", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseFindInMapDeploymentGroup" + } + } + }, + "Properties": { + "Name": "live", + "FunctionName": { + "Ref": "FalseFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseFindInMapVersion640128d35d", + "Version" + ] + }, + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "FalseFindInMapRole": { + "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "ServerlessDeploymentApplication": { + "Type": "AWS::CodeDeploy::Application", + "Properties": { + "ComputePlatform": "Lambda" + } + }, + "CodeDeployServiceRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + } + }, + "TrueRefDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "FunctionCondition", + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "FalseRefDeploymentGroup": { + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "TrueFindInMapDeploymentGroup": { + "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "FunctionCondition", + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + }, + "FalseFindInMapDeploymentGroup": { + "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": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentType": "BLUE_GREEN", + "DeploymentOption": "WITH_TRAFFIC_CONTROL" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_function_resources.py b/tests/translator/test_function_resources.py index 279668155..bb3c8e5cc 100644 --- a/tests/translator/test_function_resources.py +++ b/tests/translator/test_function_resources.py @@ -1,5 +1,7 @@ from unittest import TestCase from unittest.mock import patch, Mock +from parameterized import parameterized + import os from samtranslator.model.sam_resources import SamFunction from samtranslator.model.lambda_ import LambdaAlias, LambdaVersion, LambdaFunction @@ -144,7 +146,9 @@ def test_sam_function_with_deployment_preference(self, get_resolved_alias_name_m resources = sam_func.to_cloudformation(**kwargs) 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) + deployment_preference_collection.add.assert_called_once_with( + self.sam_func.logical_id, deploy_preference_dict, None + ) aliases = [r.to_dict() for r in resources if r.resource_type == LambdaAlias.resource_type] @@ -222,7 +226,7 @@ def test_sam_function_with_disabled_deployment_preference_does_not_add_update_po resources = sam_func.to_cloudformation(**kwargs) - preference_collection.add.assert_called_once_with(sam_func.logical_id, deploy_preference_dict) + preference_collection.add.assert_called_once_with(sam_func.logical_id, deploy_preference_dict, None) preference_collection.get.assert_called_once_with(sam_func.logical_id) self.intrinsics_resolver_mock.resolve_parameter_refs.assert_called_with(enabled) aliases = [r.to_dict() for r in resources if r.resource_type == LambdaAlias.resource_type] @@ -318,7 +322,9 @@ def test_sam_function_with_deployment_preference_intrinsic_ref_enabled_boolean_p resources = sam.to_cloudformation(**kwargs) 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) + deployment_preference_collection.add.assert_called_once_with( + self.sam_func.logical_id, deploy_preference_dict, None + ) 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] @@ -395,6 +401,161 @@ def test_sam_function_with_deployment_preference_intrinsic_findinmap_enabled_dic sam_func.to_cloudformation(**kwargs) self.assertTrue(sam_func.DeploymentPreference["Enabled"]) + @patch("boto3.session.Session.region_name", "ap-southeast-1") + @patch.object(SamFunction, "_get_resolved_alias_name") + def test_sam_function_with_deployment_preference_passthrough_condition_through_property( + self, get_resolved_alias_name_mock + ): + deploy_preference_dict = {"Type": "LINEAR", "PassthroughCondition": True} + alias_name = "AliasName" + func = { + "Type": "AWS::Serverless::Function", + "Condition": "Condition1", + "Properties": { + "CodeUri": self.code_uri, + "Runtime": "nodejs12.x", + "Handler": "index.handler", + "AutoPublishAlias": alias_name, + "DeploymentPreference": deploy_preference_dict, + }, + } + + sam_func = SamFunction.from_dict(logical_id="foo", resource_dict=func) + + kwargs = dict() + 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 + + self.intrinsics_resolver_mock.resolve_parameter_refs.return_value = { + "S3Bucket": "bucket", + "S3Key": "key", + "S3ObjectVersion": "version", + } + self.mappings_resolver_mock.resolve_parameter_refs.return_value = True + resources = sam_func.to_cloudformation(**kwargs) + + 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, "Condition1" + ) + + aliases = [r.to_dict() for r in resources if r.resource_type == LambdaAlias.resource_type] + + self.assertTrue("UpdatePolicy" in list(aliases[0].values())[0]) + self.assertEqual(list(aliases[0].values())[0]["UpdatePolicy"], self.update_policy().to_dict()) + + @patch("boto3.session.Session.region_name", "ap-southeast-1") + @patch.object(SamFunction, "_get_resolved_alias_name") + def test_sam_function_with_deployment_preference_passthrough_condition_through_feature_flag( + self, get_resolved_alias_name_mock + ): + deploy_preference_dict = {"Type": "LINEAR"} + alias_name = "AliasName" + func = { + "Type": "AWS::Serverless::Function", + "Condition": "Condition1", + "Properties": { + "CodeUri": self.code_uri, + "Runtime": "nodejs12.x", + "Handler": "index.handler", + "AutoPublishAlias": alias_name, + "DeploymentPreference": deploy_preference_dict, + }, + } + + sam_func = SamFunction.from_dict(logical_id="foo", resource_dict=func) + + kwargs = dict() + 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 + feature_toggle_mock = Mock() + feature_toggle_mock.is_enabled.side_effect = lambda x: x == "deployment_preference_condition_fix" + kwargs["feature_toggle"] = feature_toggle_mock + + self.intrinsics_resolver_mock.resolve_parameter_refs.return_value = { + "S3Bucket": "bucket", + "S3Key": "key", + "S3ObjectVersion": "version", + } + resources = sam_func.to_cloudformation(**kwargs) + + 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, "Condition1" + ) + + aliases = [r.to_dict() for r in resources if r.resource_type == LambdaAlias.resource_type] + + self.assertTrue("UpdatePolicy" in list(aliases[0].values())[0]) + self.assertEqual(list(aliases[0].values())[0]["UpdatePolicy"], self.update_policy().to_dict()) + + @parameterized.expand( + [ + ( + {"Fn::Sub": ["${Hello}", {"Hello": "helloworld"}]}, + "Resource with id [foo] is invalid. Unsupported intrinsic: the only intrinsic functions supported for property PassthroughCondition are FindInMap and parameter Refs.", + ), + ("my_string", "Resource with id [foo] is invalid. Invalid value for property PassthroughCondition."), + ] + ) + @patch("boto3.session.Session.region_name", "ap-southeast-1") + @patch.object(SamFunction, "_get_resolved_alias_name") + def test_sam_function_with_deployment_preference_passthrough_condition_invalid_input( + self, invalid_passthrough_condition, expected_exception_message, get_resolved_alias_name_mock + ): + deploy_preference_dict = {"Type": "LINEAR", "PassthroughCondition": invalid_passthrough_condition} + alias_name = "AliasName" + func = { + "Type": "AWS::Serverless::Function", + "Condition": "Condition1", + "Properties": { + "CodeUri": self.code_uri, + "Runtime": "nodejs12.x", + "Handler": "index.handler", + "AutoPublishAlias": alias_name, + "DeploymentPreference": deploy_preference_dict, + }, + } + + sam_func = SamFunction.from_dict(logical_id="foo", resource_dict=func) + + kwargs = dict() + 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 + feature_toggle_mock = Mock() + feature_toggle_mock.is_enabled.side_effect = lambda x: x == "deployment_preference_condition_fix" + kwargs["feature_toggle"] = feature_toggle_mock + + self.intrinsics_resolver_mock.resolve_parameter_refs.return_value = { + "S3Bucket": "bucket", + "S3Key": "key", + "S3ObjectVersion": "version", + } + self.mappings_resolver_mock.resolve_parameter_refs.return_value = invalid_passthrough_condition + + with self.assertRaises(InvalidResourceException) as e: + sam_func.to_cloudformation(**kwargs) + + self.assertEqual( + e.exception.message, + expected_exception_message, + ) + @patch("samtranslator.translator.logical_id_generator.LogicalIdGenerator") def test_version_creation(self, LogicalIdGeneratorMock): generator_mock = LogicalIdGeneratorMock.return_value diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 6e1368288..e2942b707 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -366,14 +366,20 @@ class TestTranslatorEndToEnd(AbstractTestTranslator): "function_with_disabled_deployment_preference", "function_with_disabled_traffic_hook", "function_with_deployment_preference", + "function_with_deployment_preference_condition_with_passthrough", + "function_with_deployment_preference_condition_without_passthrough", "function_with_deployment_preference_all_parameters", "function_with_deployment_preference_from_parameters", "function_with_deployment_preference_multiple_combinations", "function_with_deployment_preference_alarms_intrinsic_if", + "function_with_deployment_preference_multiple_combinations_conditions_with_passthrough", + "function_with_deployment_preference_multiple_combinations_conditions_without_passthrough", + "function_with_deployment_preference_passthrough_condition_with_supported_intrinsics", "function_with_alias_and_event_sources", "function_with_resource_refs", "function_with_deployment_and_custom_role", - "function_with_deployment_no_service_role", + "function_with_deployment_no_service_role_with_passthrough", + "function_with_deployment_no_service_role_without_passthrough", "function_with_global_layers", "function_with_layers", "function_with_many_layers", diff --git a/tests/unit/model/preferences/test_deployment_preference_collection.py b/tests/unit/model/preferences/test_deployment_preference_collection.py index 0ab04c949..163660aed 100644 --- a/tests/unit/model/preferences/test_deployment_preference_collection.py +++ b/tests/unit/model/preferences/test_deployment_preference_collection.py @@ -20,7 +20,7 @@ def test_codedeploy_iam_role_contains_AWSCodeDeployRoleForLambdaLimited_managedp ) as get_partition_name_patch: get_partition_name_patch.return_value = partition - iam_role = DeploymentPreferenceCollection().codedeploy_iam_role + iam_role = DeploymentPreferenceCollection().get_codedeploy_iam_role() self.assertIn( "arn:{}:iam::aws:policy/service-role/AWSCodeDeployRoleForLambdaLimited".format(partition), @@ -41,7 +41,7 @@ def test_codedeploy_iam_role_contains_AWSCodeDeployRoleForLambda_managedpolicy(s ) as get_partition_name_patch: get_partition_name_patch.return_value = partition - iam_role = DeploymentPreferenceCollection().codedeploy_iam_role + iam_role = DeploymentPreferenceCollection().get_codedeploy_iam_role() self.assertIn( "arn:{}:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda".format(partition), diff --git a/tests/validator/test_validator.py b/tests/validator/test_validator.py index 6ac288d48..e35524df1 100644 --- a/tests/validator/test_validator.py +++ b/tests/validator/test_validator.py @@ -121,7 +121,7 @@ class TestValidatorTranslatorTemplates(TestValidatorBase): "function_with_alias_and_event_sources", "function_with_alias_intrinsics", "function_with_deployment_and_custom_role", - "function_with_deployment_no_service_role", + "function_with_deployment_no_service_role_with_passthrough", "function_with_deployment_preference", "function_with_deployment_preference_all_parameters", "function_with_deployment_preference_from_parameters",