在不同区域创建 CloudFormation 资源

Create CloudFormation resources in different region

我有一个 CF 堆栈,并且定义了不同的资源。其中之一是 S3 存储桶。我需要 运行 eu-west-1 区域中的堆栈,同时在 ap-southeast-1 区域中创建存储桶。我该怎么做?

单个 CloudFormation 堆栈只能在堆栈所在的单个区域中拥有资源。

但是,使用 CloudFormation 堆栈集,您可以跨多个区域和 AWS 账户中的多个 CloudFormation 堆栈创建资源。

有关使用堆栈集的更多信息,请参阅堆栈集文档:http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-concepts.html

不幸的是,在 CloudFormation 中使用标准 AWS::S3::Bucket 这是不可能的,因为由 CloudFormation 堆栈管理的资源只能驻留在与堆栈本身相同的区域中。但是,您可以使用 Lambda 函数

解决这个问题

creating the bucket 时,您的 Lambda 函数必须将 LocationConstraint 设置为 ap-southeast-1。此外,您的 Lambda 函数将负责更新和删除您的存储桶,这可能涉及更多代码。

您可以使用 Lambda-backed Custom Resources.

将您的 Lambda 函数连接到 CloudFormation

您可以使用 cfs3-uploader

等工具在每个区域为 Cloudformation 快速创建 S3 存储桶