如何使用 AWS Lambda 的无服务器框架获取最新的 Layer 版本
How to get latest Layer version with serverless framework for AWS Lambda
我正在尝试使用 serverless-latest-layer-version
插件获取带有无服务器框架的最新 Layer 版本。该插件本身可以获得最新版本的图层,但问题是每当我为图层和功能进行新部署时,图层版本总是显示新图层版本的前一个。下面是 serverless.yml 获取最新版本并将其应用到功能中的方法。帮我提出任何我遗漏的配置到最新层版本的建议?
layers:
my-layers:
path: my-layers
name: ${opt:stage, 'development'}-my-layer
description: Save all common npm dependencies in single project
compatibleRuntimes:
- nodejs10.x
functions:
app:
handler: index.handler
layers:
- arn:aws:lambda:ap-southeast-1:#{AWS::AccountId}:layer:${opt:stage, 'development'}-my-layer:latest
我认为您可以使用 CloudFormationRef。请参阅无服务器 (https://www.serverless.com/framework/docs/providers/aws/guide/layers/) 上的文档:
To use a layer with a function in the same service, use a
CloudFormation Ref. The name of your layer in the CloudFormation
template will be your layer name TitleCased (without spaces) and have
LambdaLayer appended to the end. EG:
layers:
test:
path: layer
functions:
hello:
handler: handler.hello
layers:
- { Ref: TestLambdaLayer }
我正在尝试使用 serverless-latest-layer-version
插件获取带有无服务器框架的最新 Layer 版本。该插件本身可以获得最新版本的图层,但问题是每当我为图层和功能进行新部署时,图层版本总是显示新图层版本的前一个。下面是 serverless.yml 获取最新版本并将其应用到功能中的方法。帮我提出任何我遗漏的配置到最新层版本的建议?
layers:
my-layers:
path: my-layers
name: ${opt:stage, 'development'}-my-layer
description: Save all common npm dependencies in single project
compatibleRuntimes:
- nodejs10.x
functions:
app:
handler: index.handler
layers:
- arn:aws:lambda:ap-southeast-1:#{AWS::AccountId}:layer:${opt:stage, 'development'}-my-layer:latest
我认为您可以使用 CloudFormationRef。请参阅无服务器 (https://www.serverless.com/framework/docs/providers/aws/guide/layers/) 上的文档:
To use a layer with a function in the same service, use a CloudFormation Ref. The name of your layer in the CloudFormation template will be your layer name TitleCased (without spaces) and have LambdaLayer appended to the end. EG:
layers:
test:
path: layer
functions:
hello:
handler: handler.hello
layers:
- { Ref: TestLambdaLayer }