amazon-web-services - AWS 云信息 |如何配置 Lambda 以使用 S3 存储桶中的最新代码

标签 amazon-web-services amazon-s3 aws-lambda aws-cloudformation


Tests3bucketLambda: 
  Type: "AWS::Lambda::Function"
  Properties: 
    Code: 
      S3Bucket: TestS3Bucket
      S3Key: Tests3.zip
   FunctionName: "test-lambda-function"
   Handler: lambda-function-s3.lambda_handler
   Role: !GetAtt LambdaExecutionRole.Arn
   Runtime: python3.6
  


 

问题:当我更新在代码构建期间压缩并上传到 S3 存储桶的新代码时,但更改未部署到现有 lambda 函数。

最佳答案

如果您使用相同的 key 将新代码部署到对象,CF 不会将其视为更改,因为模板本身尚未修改。有几种方法可以缓解这种情况。

  1. 使用存储桶版本控制并提供对象版本和对象 key :https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html

    Code: 
      S3Bucket: TestS3Bucket
      S3Key: Tests3.zip
      S3ObjectVersion: blablabla....
    
  2. 修改每个部署上的对象键,例如时间戳

    Code: 
      S3Bucket: TestS3Bucket
      S3Key: Tests3_2021-05-06T17:15:55+00:00.zip
    
  3. 使用 Terraform 或 AWS CDK 等自动化工具来处理这些事情

关于amazon-web-services - AWS 云信息 |如何配置 Lambda 以使用 S3 存储桶中的最新代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67422776/

相关文章:

node.js - 在 AWS Lambda 函数中从 S3 获取对象并发送到 Api Gateway

amazon-web-services - AWS NLB 警告 : There is an Internet Gateway attached to these subnets

amazon-web-services - 如何让 Cloud Formation 创建变更集来更新我的 Lambda 函数?

mysql - 通过 SSH 在两个远程主机之间导入/导出 mysql

android - 打开失败 :ENOENT (No such file or directory) error

wordpress - 使用 .htaccess 将 WordPress 上传文件夹重定向到 s3 存储桶

java - 每次推送消息时AWS SQS : Is it a way SQS call me consumer,

php - 如何在我的网站上显示来 self 的 Amazon S3 的图像?

python - 将静态(对于 Django 项目)上传并使用到 AWS S3

logging - 有没有办法查看 lambda 函数何时部署以及谁部署的?