@@ -664,6 +664,69 @@ def test_function_features(self, lambda_client):
664
664
665
665
# Check Lambda function doesn't exist
666
666
assert not lambda_validator .function_exists (resource_name )
667
+
668
+ def test_function_layers (self , lambda_client ):
669
+ resource_name = random_suffix_name ("functionlayers" , 24 )
670
+
671
+ resources = get_bootstrap_resources ()
672
+ logging .debug (resources )
673
+
674
+ replacements = REPLACEMENT_VALUES .copy ()
675
+ replacements ["FUNCTION_NAME" ] = resource_name
676
+ replacements ["BUCKET_NAME" ] = resources .FunctionsBucket .name
677
+ replacements ["LAMBDA_ROLE" ] = resources .EICRole .arn
678
+ replacements ["LAMBDA_FILE_NAME" ] = LAMBDA_FUNCTION_FILE_ZIP
679
+ replacements ["AWS_REGION" ] = get_region ()
680
+ replacements ["LAYERS" ] = "arn:aws:lambda:us-west-2:336392948345:layer:AWSSDKPandas-Python310:14"
681
+
682
+ # Load Lambda CR
683
+ resource_data = load_lambda_resource (
684
+ "function_layers" ,
685
+ additional_replacements = replacements ,
686
+ )
687
+ logging .debug (resource_data )
688
+
689
+ # Create k8s resource
690
+ ref = k8s .CustomResourceReference (
691
+ CRD_GROUP , CRD_VERSION , RESOURCE_PLURAL ,
692
+ resource_name , namespace = "default" ,
693
+ )
694
+ k8s .create_custom_resource (ref , resource_data )
695
+ cr = k8s .wait_resource_consumed_by_controller (ref )
696
+
697
+ assert cr is not None
698
+ assert k8s .get_resource_exists (ref )
699
+
700
+ time .sleep (CREATE_WAIT_AFTER_SECONDS )
701
+
702
+ cr = k8s .wait_resource_consumed_by_controller (ref )
703
+
704
+ lambda_validator = LambdaValidator (lambda_client )
705
+
706
+ # Check Lambda function exists
707
+ assert lambda_validator .function_exists (resource_name )
708
+
709
+ # Update cr
710
+ layers_list = ["arn:aws:lambda:us-west-2:017000801446:layer:AWSLambdaPowertoolsPythonV2:68" , "arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:52" ]
711
+ cr ["spec" ]["layers" ] = layers_list
712
+
713
+ #Patch k8s resource
714
+ k8s .patch_custom_resource (ref , cr )
715
+ time .sleep (UPDATE_WAIT_AFTER_SECONDS )
716
+
717
+ #Check function_snapstart update fields
718
+ function = lambda_validator .get_function (resource_name )
719
+ for i in range (len (function ["Configuration" ]["Layers" ])) :
720
+ assert function ["Configuration" ]["Layers" ][i ]["Arn" ] == layers_list [i ]
721
+
722
+ # Delete k8s resource
723
+ _ , deleted = k8s .delete_custom_resource (ref )
724
+ assert deleted is True
725
+
726
+ time .sleep (DELETE_WAIT_AFTER_SECONDS )
727
+
728
+ # Check Lambda function doesn't exist
729
+ assert not lambda_validator .function_exists (resource_name )
667
730
668
731
def test_function_event_invoke_config (self , lambda_client ):
669
732
resource_name = random_suffix_name ("lambda-function" , 24 )
0 commit comments