简体   繁体   English

aws 代码管道使用 s3 对象更新 lambda 函数源

[英]aws codepipline update lambda function source using s3 object

I am using terraform to create all the infra(CodePipeline, lambda, buckets) on AWS我正在使用 terraform 在 AWS 上创建所有基础设施(CodePipeline、lambda、bucket)

currently, I've created a pipeline that builds the source zip file and puts it on s3 bucket but the lambda still keeps using the older source.目前,我已经创建了一个管道来构建源 zip 文件并将其放在 s3 存储桶上,但 lambda 仍然继续使用旧源。 So, I update the URL manually in the AWS console and it works.因此,我在 AWS 控制台中手动更新了 URL 并且它工作正常。 Now I want to automate the flow but available solutions are:现在我想自动化流程,但可用的解决方案是:

  • AWS SAM + CFT AWS SAM + CFT
  • Codebuild Stage to update the source using AWS CLI使用 AWS CLI 更新源的 Codebuild Stage
  • Create a lambda that updates the source创建一个更新源的 lambda
  • Code Deploy + AWS SAM + CFT代码部署 + AWS SAM + CFT

I am not willing to use CFT at all since all of our code is in terraform and CFT requires me to create new lambdas instead of using old ones.我根本不愿意使用 CFT,因为我们所有的代码都是 terraform 并且 CFT 要求我创建新的 lambdas 而不是使用旧的。

is there any other simpler way to update the lambda source through Codepipeline有没有其他更简单的方法可以通过 Codepipeline 更新 lambda 源

The preferred way to deploy a Lambda via CodePipeline is using a CloudFormation Deploy action [1].通过 CodePipeline 部署 Lambda 的首选方法是使用 CloudFormation 部署操作 [1]。 Since you are not looking to use CloudFormation, next option could be to run your terraform plan/apply commands from within a CodeBuild job that is part of the pipeline.由于您不打算使用 CloudFormation,因此下一个选项可能是从作为管道一部分的 CodeBuild 作业中运行您的 terraform plan/apply 命令。 You will need to provide the CodeBuild role required permission for resource creation (or export the credentials in Environment variabels for TF to use via this [2] method) and install the TF binary within install phase of buildspec.您将需要为资源创建提供 CodeBuild 角色所需的权限(或导出环境变量中的凭据以供 TF 通过此 [2] 方法使用)并在 buildspec 的安装阶段安装 TF 二进制文件。

Ref:参考:

[1] Building a Continuous Delivery Pipeline for a Lambda Application with AWS CodePipeline - https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html [1] 使用 AWS CodePipeline 为 Lambda 应用程序构建持续交付管道 - https://docs.aws.amazon.com/lambda/latest/dg/build-pipeline.html

[2] How to retrieve Secret Manager data in buildspec.yaml [2] 如何在 buildspec.yaml 中检索 Secret Manager 数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM