gpt4 book ai didi

amazon-web-services - 如何使 Cloudformation 模板干燥

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

我正在使用 Cloudformation 实现多区域解决方案。每个区域都会有许多 lambda、警报、CW 日志等。有一些资源仅特定于一个区域:cloudfront、全局表等。我决定为每个区域创建自己的模板文件,因此,很多代码都是重复的。有没有一种方法可以创建一个模板文件,该模板文件可以由每个区域的其他模板文件导入?

我做了一些研究,有一些模块可以使用,但是为每个 lambda/重复资源创建一个模块是没有意义的(我们有大约 20 个)。

下面是一个将在两个区域中重复的 lambda 示例:

    Type: AWS::Serverless::Function
Properties:
Runtime: python3.8
CodeUri: endpoints
Handler: webhook.handler
Environment:
Variables:
S3_CONTENT_JSON_BUCKET: !Sub "xxxxx"
Layers:
- !FindInMap [ AccountSpecific, !Ref "AWS::AccountId", LoggingArn ]
- !Ref PythonCommonLayer
Policies:
- S3CrudPolicy:
BucketName: !Sub "xxxxx"
Events:
PostContentfulData:
Type: Api
Properties:
RestApiId:
Ref: ApiGateway
Path: /contentful
Method: POST
Auth:
ApiKeyRequired: true```

最佳答案

Is there a way to create one template file that could be imported by the other template files for each region?

遗憾的是没有。 CloudFormation 是特定于区域的,一个区域中的堆栈无法引用其他区域中的堆栈。但是,您可以使用 StackSets管理跨不同区域和帐户的多个模板。

关于amazon-web-services - 如何使 Cloudformation 模板干燥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73410424/

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