与层结合使用 Amazon CloudFormation - Amazon Lambda
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

与层结合使用 Amazon CloudFormation

您可以使用 Amazon 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: my-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