gpt4 book ai didi

python - 如何为我的 Lambda 函数创建可重复使用的 CloudFormation 模板?

转载 作者:行者123 更新时间:2023-12-03 07:19:58 25 4
gpt4 key购买 nike

我有 9 个 lambda 函数作为单个 CloudFormation 项目的一部分。

我觉得每个 Lambda 函数的 CloudFormation 模板在很多地方都开始变得相同,而且感觉像是重复的 YAML 代码。

有没有办法通过参数化输入来创建单个 Lambda 配置并重用相同的代码?

最佳答案

是的,CloudFormation Nested Stacks可以帮助您将共享 Lambda 配置声明为一个组件,然后您可以将其用于多个资源

您可以创建专用的子“Lambda”模板,而不是为 Lambda 函数复制和粘贴相同的配置。

然后,您可以从一个封装 CloudFormation 模板(通常称为“根堆栈”)多次指向 Lambda CloudFormation (CF) 堆栈。

Parameters , Outputs & !GetAtt将是帮助您在子堆栈和根堆栈之间共享数据以及参数化方面(如函数名称、内存、运行时等)的核心工具。


组织规模上,AWS CloudFormation Modules会更合适,可以让你更大规模地封装和复用资源配置。

Here's how AWS describes them :

Modules are building blocks that can be reused across multiple CloudFormation templates and is used just like a native CloudFormation resource.

...

This means you can create a module that defines your organization’s standards for a Lambda function and then consume that Lambda module in another module that defines the patterns for your serverless Amazon API Gateway implementation.

关于python - 如何为我的 Lambda 函数创建可重复使用的 CloudFormation 模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69509905/

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