[英]Latest Lambda Layer ARN
I have a lambda layer which I keep updating.我有一个不断更新的 lambda 层。 This lambda layer has multiple versions.
这个 lambda 层有多个版本。 How can I find the lambda layer ARN with latest version using aws cli?
如何使用 aws cli 找到最新版本的 lambda 层 ARN?
I am able to do this using the command listed below -我可以使用下面列出的命令来做到这一点 -
aws lambda list-layer-versions --layer-name <layer name> --region us-east-1 --query 'LayerVersions[0].LayerVersionArn'
Unfortunately, it's currently not possible (I have encountered the same issue).不幸的是,目前不可能(我遇到了同样的问题)。
You can keep the latest ARN in your own place (like DynamoDB) and update it whenever you publish a new version of the layer.您可以将最新的 ARN 保存在您自己的位置(如 DynamoDB),并在您发布层的新版本时更新它。
You can create a custom macro to get the latest lambda layer version and use that as a reference.您可以创建自定义宏以获取最新的 lambda 层版本并将其用作参考。
The following function gets the latest version from the Lambda Layer stack:以下函数从 Lambda 层堆栈获取最新版本:
import json
import boto3
def latest_lambdalayer(event, context):
fragment = get_latestversion(event['fragment'])
return {
'requestId': event['requestId'],
'status': 'success',
'fragment': fragment
}
def get_latestversion(fragment):
cloudformation = boto3.resource('cloudformation')
stack = cloudformation.Stack('ticketapp-layer-dependencies')
for o in stack.outputs:
if o['OutputKey']=='TicketAppLambdaDependency':
return o['OutputValue']
#return "arn:aws:lambda:eu-central-1:899885580749:layer:ticketapp-dependencies-layer:16"
And you use this when defining the Lambda layer—here using same global template:在定义 Lambda 层时使用它——这里使用相同的全局模板:
Globals:
Function:
Layers:
- !Transform { "Name" : "LatestLambdaLayer"}
Runtime: nodejs12.x
MemorySize: 128
Timeout: 101
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.