与层结合使用 AWS CloudFormation
您可以使用 AWS CloudFormation 创建层并将层与 Lambda 函数关联起来。以下示例模板会创建一个名为 my-lambda-layer
的层,并使用层属性将该层附加到 Lambda 函数。
--- Description: CloudFormation Template for Lambda 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 Policies: - AWSLambdaBasicExecutionRole - AWSLambda_ReadOnlyAccess - AWSXrayWriteOnlyAccess Layers: - !Ref MyLambdaLayer