Skip to content

Commit 99f5ab7

Browse files
author
cakepietoast
authored
feat: Trigger auto publish alias on env var/memorysize change (#1310)
1 parent b834f89 commit 99f5ab7

File tree

7 files changed

+53
-43
lines changed

7 files changed

+53
-43
lines changed

samtranslator/model/sam_resources.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,17 @@ def _construct_version(self, function, intrinsics_resolver, code_sha256=None):
661661
# SHA Collisions: For purposes of triggering a new update, we are concerned about just the difference previous
662662
# and next hashes. The chances that two subsequent hashes collide is fairly low.
663663
prefix = "{id}Version".format(id=self.logical_id)
664-
logical_id = logical_id_generator.LogicalIdGenerator(prefix, code_dict, code_sha256).gen()
664+
logical_dict = {}
665+
try:
666+
logical_dict = code_dict.copy()
667+
except (AttributeError, UnboundLocalError):
668+
pass
669+
else:
670+
if function.Environment:
671+
logical_dict.update(function.Environment)
672+
if function.MemorySize:
673+
logical_dict.update({"MemorySize": function.MemorySize})
674+
logical_id = logical_id_generator.LogicalIdGenerator(prefix, logical_dict, code_sha256).gen()
665675

666676
attributes = self.get_passthrough_resource_attributes()
667677
if attributes is None:

tests/translator/output/aws-cn/function_with_event_dest_basic.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,12 @@
121121
"Runtime": "nodejs12.x"
122122
}
123123
},
124-
"MyTestFunctionVersion948f7f815d": {
125-
"DeletionPolicy": "Retain",
126-
"Type": "AWS::Lambda::Version",
127-
"Properties": {
128-
"FunctionName": {
129-
"Ref": "MyTestFunction"
130-
}
131-
}
132-
},
133124
"MyTestFunctionAliaslive": {
134125
"Type": "AWS::Lambda::Alias",
135126
"Properties": {
136127
"FunctionVersion": {
137128
"Fn::GetAtt": [
138-
"MyTestFunctionVersion948f7f815d",
129+
"MyTestFunctionVersiondaf9da458d",
139130
"Version"
140131
]
141132
},
@@ -144,6 +135,15 @@
144135
},
145136
"Name": "live"
146137
}
138+
},
139+
"MyTestFunctionVersiondaf9da458d": {
140+
"DeletionPolicy": "Retain",
141+
"Type": "AWS::Lambda::Version",
142+
"Properties": {
143+
"FunctionName": {
144+
"Ref": "MyTestFunction"
145+
}
146+
}
147147
}
148148
}
149149
}

tests/translator/output/aws-cn/globals_for_function.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"Properties": {
145145
"FunctionVersion": {
146146
"Fn::GetAtt": [
147-
"FunctionWithOverridesVersion640128d35d",
147+
"FunctionWithOverridesVersion096ed3b52b",
148148
"Version"
149149
]
150150
},
@@ -211,7 +211,7 @@
211211
"Properties": {
212212
"FunctionVersion": {
213213
"Fn::GetAtt": [
214-
"MinimalFunctionVersionfb7aeaa544",
214+
"MinimalFunctionVersion0a06fc8fb1",
215215
"Version"
216216
]
217217
},
@@ -221,7 +221,7 @@
221221
"Name": "live"
222222
}
223223
},
224-
"FunctionWithOverridesVersion640128d35d": {
224+
"FunctionWithOverridesVersion096ed3b52b": {
225225
"DeletionPolicy": "Retain",
226226
"Type": "AWS::Lambda::Version",
227227
"Properties": {
@@ -230,7 +230,7 @@
230230
}
231231
}
232232
},
233-
"MinimalFunctionVersionfb7aeaa544": {
233+
"MinimalFunctionVersion0a06fc8fb1": {
234234
"DeletionPolicy": "Retain",
235235
"Type": "AWS::Lambda::Version",
236236
"Properties": {

tests/translator/output/aws-us-gov/function_with_event_dest_basic.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,12 @@
121121
"Runtime": "nodejs12.x"
122122
}
123123
},
124-
"MyTestFunctionVersion948f7f815d": {
125-
"DeletionPolicy": "Retain",
126-
"Type": "AWS::Lambda::Version",
127-
"Properties": {
128-
"FunctionName": {
129-
"Ref": "MyTestFunction"
130-
}
131-
}
132-
},
133124
"MyTestFunctionAliaslive": {
134125
"Type": "AWS::Lambda::Alias",
135126
"Properties": {
136127
"FunctionVersion": {
137128
"Fn::GetAtt": [
138-
"MyTestFunctionVersion948f7f815d",
129+
"MyTestFunctionVersiondaf9da458d",
139130
"Version"
140131
]
141132
},
@@ -144,6 +135,15 @@
144135
},
145136
"Name": "live"
146137
}
138+
},
139+
"MyTestFunctionVersiondaf9da458d": {
140+
"DeletionPolicy": "Retain",
141+
"Type": "AWS::Lambda::Version",
142+
"Properties": {
143+
"FunctionName": {
144+
"Ref": "MyTestFunction"
145+
}
146+
}
147147
}
148148
}
149149
}

tests/translator/output/aws-us-gov/globals_for_function.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"Properties": {
145145
"FunctionVersion": {
146146
"Fn::GetAtt": [
147-
"FunctionWithOverridesVersion640128d35d",
147+
"FunctionWithOverridesVersion096ed3b52b",
148148
"Version"
149149
]
150150
},
@@ -211,7 +211,7 @@
211211
"Properties": {
212212
"FunctionVersion": {
213213
"Fn::GetAtt": [
214-
"MinimalFunctionVersionfb7aeaa544",
214+
"MinimalFunctionVersion0a06fc8fb1",
215215
"Version"
216216
]
217217
},
@@ -221,7 +221,7 @@
221221
"Name": "live"
222222
}
223223
},
224-
"FunctionWithOverridesVersion640128d35d": {
224+
"FunctionWithOverridesVersion096ed3b52b": {
225225
"DeletionPolicy": "Retain",
226226
"Type": "AWS::Lambda::Version",
227227
"Properties": {
@@ -230,7 +230,7 @@
230230
}
231231
}
232232
},
233-
"MinimalFunctionVersionfb7aeaa544": {
233+
"MinimalFunctionVersion0a06fc8fb1": {
234234
"DeletionPolicy": "Retain",
235235
"Type": "AWS::Lambda::Version",
236236
"Properties": {

tests/translator/output/function_with_event_dest_basic.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,12 @@
121121
"Runtime": "nodejs12.x"
122122
}
123123
},
124-
"MyTestFunctionVersion948f7f815d": {
125-
"DeletionPolicy": "Retain",
126-
"Type": "AWS::Lambda::Version",
127-
"Properties": {
128-
"FunctionName": {
129-
"Ref": "MyTestFunction"
130-
}
131-
}
132-
},
133124
"MyTestFunctionAliaslive": {
134125
"Type": "AWS::Lambda::Alias",
135126
"Properties": {
136127
"FunctionVersion": {
137128
"Fn::GetAtt": [
138-
"MyTestFunctionVersion948f7f815d",
129+
"MyTestFunctionVersiondaf9da458d",
139130
"Version"
140131
]
141132
},
@@ -144,6 +135,15 @@
144135
},
145136
"Name": "live"
146137
}
138+
},
139+
"MyTestFunctionVersiondaf9da458d": {
140+
"DeletionPolicy": "Retain",
141+
"Type": "AWS::Lambda::Version",
142+
"Properties": {
143+
"FunctionName": {
144+
"Ref": "MyTestFunction"
145+
}
146+
}
147147
}
148148
}
149149
}

tests/translator/output/globals_for_function.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
"Properties": {
145145
"FunctionVersion": {
146146
"Fn::GetAtt": [
147-
"FunctionWithOverridesVersion640128d35d",
147+
"FunctionWithOverridesVersion096ed3b52b",
148148
"Version"
149149
]
150150
},
@@ -211,7 +211,7 @@
211211
"Properties": {
212212
"FunctionVersion": {
213213
"Fn::GetAtt": [
214-
"MinimalFunctionVersionfb7aeaa544",
214+
"MinimalFunctionVersion0a06fc8fb1",
215215
"Version"
216216
]
217217
},
@@ -221,7 +221,7 @@
221221
"Name": "live"
222222
}
223223
},
224-
"FunctionWithOverridesVersion640128d35d": {
224+
"FunctionWithOverridesVersion096ed3b52b": {
225225
"DeletionPolicy": "Retain",
226226
"Type": "AWS::Lambda::Version",
227227
"Properties": {
@@ -230,7 +230,7 @@
230230
}
231231
}
232232
},
233-
"MinimalFunctionVersionfb7aeaa544": {
233+
"MinimalFunctionVersion0a06fc8fb1": {
234234
"DeletionPolicy": "Retain",
235235
"Type": "AWS::Lambda::Version",
236236
"Properties": {

0 commit comments

Comments
 (0)