[英]Get updated AWS Lambda URL after deployment
I have set up CI/CD for an AWS Lambda function such that the new version is automatically deployed using GitHub actions.我已经为 AWS Lambda function 设置了 CI/CD,以便使用 GitHub 操作自动部署新版本。 By default, AWS creates a new Lambda ID (and thus URL) for this lambda function. This means that the front-end portion of my code will need to be updated to contain the updated URL. Is there a way to automatically perform such updating?
默认情况下,AWS 为此 lambda function 创建一个新的 Lambda ID(以及 URL)。这意味着我的代码的前端部分需要更新以包含更新后的 URL。有没有办法自动执行此类更新? By eg saving the URL as an environment variable and inserting it in the code with a GitHub action?
例如,通过将 URL 保存为环境变量并使用 GitHub 操作将其插入代码中?
Or is there alternatively a way to re-use the old Lambda function URL for new deployments?或者有没有办法重新使用旧的 Lambda function URL 进行新部署?
You can get the updated Lambda URL by using SAM template outputs as follows:您可以使用SAM 模板输出获取更新后的 Lambda URL,如下所示:
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Outputs:
MyFunctionUrlEndpoint:
Description: "My Lambda Function URL Endpoint"
Value: !GetAtt MyFunctionUrl.FunctionUrl
Then you can access the output as described in this answer :然后您可以按照此答案中的描述访问 output:
aws cloudformation describe-stacks --stack-name stack_name --query 'Stacks[0].Outputs[?OutputKey==`MyFunctionUrlEndpoint`].OutputValue' --output text
which can then be further processed in eg your front-end code.然后可以在您的前端代码中进一步处理。
There may be easier methods, but this should work!可能有更简单的方法,但这应该有效!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.