首页 文章

使用CloudFormation更新AWS Lambda函数

提问于
浏览
0

我有一个带有Lambda资源的CloudFormation模板 .

在部署步骤中,我需要使用我的zip文件(我通过 aws cloudformation package 上传)更新此Lambda函数 . 现在,我可以将Lambda函数的名称作为参数传递给SAM functionName,但是当我这样做时,它会抱怨函数名已经存在 .

这很好,但我如何指定只更新代码而不是尝试替换Lambda函数?

1 回答

  • 0

    要更新Lambda函数的代码,您只需要遵循以下过程:

    # update code artefact and maybe compile it to target folder
    # e.g. for Java using Maven: mvn clean compile package
    
    $ aws cloudformation package ...
    $ aws cloudformation deploy ...
    

    这将更新模板中的所有资源 . 另见this how-to guide .

    如果您只想更新单个Lambda函数的代码,也可以使用aws lambda update-function-code . 但是,对于堆栈中的不同Lambda函数,这可能有点繁琐,因为您需要每个函数的ARN . 因此,去年我编写了一个名为lambda-updater的小型NPM工具,它在CloudFormation堆栈中搜索Lambda函数,只更新函数的代码 . 它可能对你有意义 .

相关问题