本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
AWS CloudFormation 與圖層一起使用
您可以使用 AWS CloudFormation 建立圖層,並將圖層與 Lambda 函數產生關聯。下列範例範本會建立名為 my-lambda-layer
的層,並使用 Layers 屬性將該層連接至 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