gpt4 book ai didi

amazon-web-services - 我可以使用 CloudFormation 模板更新 AWS Lambda 函数吗?

转载 作者:行者123 更新时间:2023-12-03 07:22:52 26 4
gpt4 key购买 nike

我想使用 CloudFormation 堆栈部署和更新 Lambda 函数。

我的堆栈创建工作流程是:

  1. 将我的 Lambda 函数代码(zip 文件)上传到 S3
  2. 使用 s3 存储桶(存储 lambda 函数代码的位置)和 LambdaFileName(zip 文件名)作为 CloudFormation 参数,通过部署 CloudFormation 模板来创建 CloudFormation 堆栈

但是,我不知道如何使用模板更新 Lambda 函数。我尝试将新功能代码上传到S3并另存为新文件名。并使用新文件作为参数来更新堆栈。但由于该文件是 zip 文件,CloudFormation 无法检测到任何更改。

我的问题:

  1. 如何使用 CloudFormation 模板更新 Lambda 函数
  2. 我应该使用 AWS::Lambda::Function 还是 AWS::Serverless::Function 资源?我希望支持版本控制。

谢谢。

我的CloudFormation模板如下。

AWSTemplateFormatVersion: "2010-09-09"
Metadata: ""
Description: ""
Parameters:

LambdaS3:
Description: Api Gateway Authorizer Lambda S3Bucket Name
Type: String

Lambdafilename:
Description: Api Gateway Authorizer Lambda file Name (Latest)
Type: String

Transform: AWS::Serverless-2016-10-31

Resources:
# LambdaFunction:
# DeletionPolicy: "Delete"
# Type: "AWS::Lambda::Function"
# Properties:
# Description: ""
# FunctionName: "LambdaFunction"
# Handler: "lambda_function.lambda_handler"
# Code:
# S3Bucket: !Ref LambdaS3
# S3Key: !Sub '${Lambdafilename}.zip'
# MemorySize: 512
# Role: !GetAtt IAMRole2.Arn
# Runtime: "python3.8"
# Timeout: 20
# TracingConfig:
# Mode: "PassThrough"

LambdaFunction:
DeletionPolicy: "Delete"
Type: "AWS::Serverless::Function"
Properties:
Description: ""
FunctionName: "LambdaFunction"
Handler: "lambda_function.lambda_handler"
CodeUri:
Bucket: !Ref LambdaS3
Key: !Sub '${Lambdafilename}.zip'
MemorySize: 512
Role: !GetAtt IAMRole2.Arn
Runtime: "python3.8"
Timeout: 20
Tracing: "PassThrough"
AutoPublishAlias: live
DeploymentPreference:
Type: Linear10PercentEvery10Minutes

最佳答案

CodeUri 采用 Version 。因此,如果您的存储桶是版本的,则对其对象的任何更改(即使名称相同)也会导致不同的版本。因此,一旦您指定新版本作为参数,您的函数就会更新。

关于amazon-web-services - 我可以使用 CloudFormation 模板更新 AWS Lambda 函数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70539681/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com