diff --git a/samtranslator/model/sam_resources.py b/samtranslator/model/sam_resources.py index 910aa6618b..1e25693f32 100644 --- a/samtranslator/model/sam_resources.py +++ b/samtranslator/model/sam_resources.py @@ -647,7 +647,17 @@ def _construct_version(self, function, intrinsics_resolver, code_sha256=None): # SHA Collisions: For purposes of triggering a new update, we are concerned about just the difference previous # and next hashes. The chances that two subsequent hashes collide is fairly low. prefix = "{id}Version".format(id=self.logical_id) - logical_id = logical_id_generator.LogicalIdGenerator(prefix, code_dict, code_sha256).gen() + logical_dict = {} + try: + logical_dict = code_dict.copy() + except (AttributeError, UnboundLocalError): + pass + else: + if function.Environment: + logical_dict.update(function.Environment) + if function.MemorySize: + logical_dict.update({"MemorySize": function.MemorySize}) + logical_id = logical_id_generator.LogicalIdGenerator(prefix, logical_dict, code_sha256).gen() attributes = self.get_passthrough_resource_attributes() if attributes is None: diff --git a/tests/translator/output/aws-cn/function_with_event_dest_basic.json b/tests/translator/output/aws-cn/function_with_event_dest_basic.json index a21943243f..01a3440e10 100644 --- a/tests/translator/output/aws-cn/function_with_event_dest_basic.json +++ b/tests/translator/output/aws-cn/function_with_event_dest_basic.json @@ -121,21 +121,12 @@ "Runtime": "nodejs12.x" } }, - "MyTestFunctionVersion948f7f815d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MyTestFunction" - } - } - }, "MyTestFunctionAliaslive": { "Type": "AWS::Lambda::Alias", "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MyTestFunctionVersion948f7f815d", + "MyTestFunctionVersiondaf9da458d", "Version" ] }, @@ -144,6 +135,15 @@ }, "Name": "live" } + }, + "MyTestFunctionVersiondaf9da458d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MyTestFunction" + } + } } } } \ No newline at end of file diff --git a/tests/translator/output/aws-cn/globals_for_function.json b/tests/translator/output/aws-cn/globals_for_function.json index 1559424a9f..79ecc2ab9a 100644 --- a/tests/translator/output/aws-cn/globals_for_function.json +++ b/tests/translator/output/aws-cn/globals_for_function.json @@ -144,7 +144,7 @@ "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "FunctionWithOverridesVersion640128d35d", + "FunctionWithOverridesVersion096ed3b52b", "Version" ] }, @@ -211,7 +211,7 @@ "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersionfb7aeaa544", + "MinimalFunctionVersion0a06fc8fb1", "Version" ] }, @@ -221,7 +221,7 @@ "Name": "live" } }, - "FunctionWithOverridesVersion640128d35d": { + "FunctionWithOverridesVersion096ed3b52b": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::Version", "Properties": { @@ -230,7 +230,7 @@ } } }, - "MinimalFunctionVersionfb7aeaa544": { + "MinimalFunctionVersion0a06fc8fb1": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::Version", "Properties": { diff --git a/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json b/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json index 91663ba8f9..2849abc9a1 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json +++ b/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json @@ -121,21 +121,12 @@ "Runtime": "nodejs12.x" } }, - "MyTestFunctionVersion948f7f815d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MyTestFunction" - } - } - }, "MyTestFunctionAliaslive": { "Type": "AWS::Lambda::Alias", "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MyTestFunctionVersion948f7f815d", + "MyTestFunctionVersiondaf9da458d", "Version" ] }, @@ -144,6 +135,15 @@ }, "Name": "live" } + }, + "MyTestFunctionVersiondaf9da458d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MyTestFunction" + } + } } } } \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/globals_for_function.json b/tests/translator/output/aws-us-gov/globals_for_function.json index 4170d86bc3..6a7fbfe707 100644 --- a/tests/translator/output/aws-us-gov/globals_for_function.json +++ b/tests/translator/output/aws-us-gov/globals_for_function.json @@ -144,7 +144,7 @@ "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "FunctionWithOverridesVersion640128d35d", + "FunctionWithOverridesVersion096ed3b52b", "Version" ] }, @@ -211,7 +211,7 @@ "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersionfb7aeaa544", + "MinimalFunctionVersion0a06fc8fb1", "Version" ] }, @@ -221,7 +221,7 @@ "Name": "live" } }, - "FunctionWithOverridesVersion640128d35d": { + "FunctionWithOverridesVersion096ed3b52b": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::Version", "Properties": { @@ -230,7 +230,7 @@ } } }, - "MinimalFunctionVersionfb7aeaa544": { + "MinimalFunctionVersion0a06fc8fb1": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::Version", "Properties": { diff --git a/tests/translator/output/function_with_event_dest_basic.json b/tests/translator/output/function_with_event_dest_basic.json index 5aae94593c..e845f151f5 100644 --- a/tests/translator/output/function_with_event_dest_basic.json +++ b/tests/translator/output/function_with_event_dest_basic.json @@ -121,21 +121,12 @@ "Runtime": "nodejs12.x" } }, - "MyTestFunctionVersion948f7f815d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MyTestFunction" - } - } - }, "MyTestFunctionAliaslive": { "Type": "AWS::Lambda::Alias", "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MyTestFunctionVersion948f7f815d", + "MyTestFunctionVersiondaf9da458d", "Version" ] }, @@ -144,6 +135,15 @@ }, "Name": "live" } + }, + "MyTestFunctionVersiondaf9da458d": { + "DeletionPolicy": "Retain", + "Type": "AWS::Lambda::Version", + "Properties": { + "FunctionName": { + "Ref": "MyTestFunction" + } + } } } } \ No newline at end of file diff --git a/tests/translator/output/globals_for_function.json b/tests/translator/output/globals_for_function.json index 4557c0e91f..df33cc3648 100644 --- a/tests/translator/output/globals_for_function.json +++ b/tests/translator/output/globals_for_function.json @@ -144,7 +144,7 @@ "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "FunctionWithOverridesVersion640128d35d", + "FunctionWithOverridesVersion096ed3b52b", "Version" ] }, @@ -211,7 +211,7 @@ "Properties": { "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersionfb7aeaa544", + "MinimalFunctionVersion0a06fc8fb1", "Version" ] }, @@ -221,7 +221,7 @@ "Name": "live" } }, - "FunctionWithOverridesVersion640128d35d": { + "FunctionWithOverridesVersion096ed3b52b": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::Version", "Properties": { @@ -230,7 +230,7 @@ } } }, - "MinimalFunctionVersionfb7aeaa544": { + "MinimalFunctionVersion0a06fc8fb1": { "DeletionPolicy": "Retain", "Type": "AWS::Lambda::Version", "Properties": {