Using AWS CloudFormation with layers
You can use CloudFormation to create a layer and associate the layer with your Lambda Event Function.
The following example template creates a layer named my-lambda-layer and
attaches the layer to the Event Function using the Layers
property.
In this example, the template specifies the Amazon Resource Name (ARN) of an existing IAM execution role. You can also create a new execution role in the template using the CloudFormation AWS::IAM::Role resource.
Your Event Function doesn't need any special permissions to use layers.
--- Description: CloudFormation Template for Lambda Event Function with Lambda Layer Resources: MyLambdaLayer: Type: AWS::Lambda::LayerVersion Properties: LayerName: my-lambda-layer Description: My Lambda Layer Content: S3Bucket: amzn-s3-demo-bucket S3Key: my-layer.zip CompatibleRuntimes: - python3.9 - python3.10 - python3.11 MyLambdaFunction: Type: AWS::Lambda::Function Properties: FunctionName: my-lambda-function Runtime: python3.9 Handler: index.handler Timeout: 10 Role: arn:aws:iam::111122223333:role/my_lambda_roleLayers: - !Ref MyLambdaLayer
You can also use AWS Serverless Application Model to manage layers. For more information, see Using AWS SAM with layers.