@@ -160,6 +160,42 @@ def test_alias_with_event_sources_get_correct_permissions(self):
160
160
function_policy = json .loads (function_policy_str )
161
161
self .assertEqual (len (function_policy ["Statement" ]), len (permission_resources ))
162
162
163
+ def test_function_with_alias_and_layer_version (self ):
164
+ self .create_and_verify_stack ("combination/function_with_alias_all_properties_and_layer_version" )
165
+ alias_name = "Live"
166
+ function_name = self .get_physical_id_by_type ("AWS::Lambda::Function" )
167
+ version_ids = self .get_function_version_by_name (function_name )
168
+ self .assertEqual (["1" ], version_ids )
169
+
170
+ alias = self .get_alias (function_name , alias_name )
171
+ self .assertEqual ("1" , alias ["FunctionVersion" ])
172
+
173
+ # Changing Description in the LayerVersion should create a new version, and leave the existing version intact
174
+ self .set_template_resource_property ("MyLayer" , "Description" , "test123" )
175
+ self .update_stack ()
176
+
177
+ version_ids = self .get_function_version_by_name (function_name )
178
+ self .assertEqual (["1" , "2" ], version_ids )
179
+
180
+ alias = self .get_alias (function_name , alias_name )
181
+ self .assertEqual ("2" , alias ["FunctionVersion" ])
182
+
183
+ # Changing ContentUri in LayerVersion should create a new version, and leave the existing version intact
184
+ self .set_template_resource_property ("MyLayer" , "ContentUri" , self .file_to_s3_uri_map ["layer2.zip" ]["uri" ])
185
+ self .update_stack ()
186
+
187
+ version_ids = self .get_function_version_by_name (function_name )
188
+ self .assertEqual (["1" , "2" , "3" ], version_ids )
189
+
190
+ alias = self .get_alias (function_name , alias_name )
191
+ self .assertEqual ("3" , alias ["FunctionVersion" ])
192
+
193
+ # Make sure the stack has only One Version & One Alias resource
194
+ alias = self .get_stack_resources ("AWS::Lambda::Alias" )
195
+ versions = self .get_stack_resources ("AWS::Lambda::Version" )
196
+ self .assertEqual (len (alias ), 1 )
197
+ self .assertEqual (len (versions ), 1 )
198
+
163
199
def get_function_version_by_name (self , function_name ):
164
200
lambda_client = self .client_provider .lambda_client
165
201
versions = lambda_client .list_versions_by_function (FunctionName = function_name )["Versions" ]
0 commit comments