简体   繁体   English

部署后获取更新的 AWS Lambda URL

[英]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.

相关问题 AWS lambda ResourceConflictException 部署 - AWS lambda ResourceConflictException on deployment 如何让 AWS API 网关在 AWS Lambda function 中调用 URL? - How to get AWS API Gateway invoke URL in an AWS Lambda function? AWS CloudFront Lambda@Edge 部署 - AWS CloudFront Lambda@Edge deployment 如何在另一个lambda之后执行AWS lambda - How to execute AWS lambda after another lambda 在 AWS Lambda 中运行 .NET 6 Web API 项目,部署为 ZIP - Running .NET 6 Web API project in AWS Lambda with ZIP deployment 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 将简单的 node.js 应用程序部署到 AWS Lambda 无服务器失败并出现 GeneralServiceException - Deployment of simple node js application to AWS Lambda Serverless Failing with GeneralServiceException 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 使用 aws sam cli 构建和部署 lambda function 后,我在日志中看到 Client.network socket disconnected - After building and deploying lambda function with aws sam cli, I get Client network socket disconnected in logs AWS Lambda 无法连接到端点 URL DynamoDB - AWS Lambda could not connect to endpoint URL DynamoDB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM