gpt4 book ai didi

amazon-web-services - 如何循环访问 CloudFormation 模板中的值

转载 作者:行者123 更新时间:2023-12-03 18:05:31 25 4
gpt4 key购买 nike

我尝试在 AWS CloudFormation 模板中传递逗号分隔的参数列表,并根据这些值创建多个 Amazon S3 存储桶。

我有一个要求,我将传递一个逗号分隔的国家/地区名称列表,然后 CloudFormation 模板将构建许多 S3 存储桶(基于参数中传递的国家/地区名称)。

例如,如果我在参数中传递 fr,us,gb,堆栈应创建 fr_myprod_bucket, us_myprod_bucket, gb_myprod_bucket

我知道 CloudFormation 中没有 for 循环,所以不确定如何实现这一点?

最佳答案

使用Count macro !

The Count macro provides a template-wide Count property for CloudFormation resources. It allows you to specify multiple resources of the same type without having to cut and paste.

因此,如下:

AWSTemplateFormatVersion: "2010-09-09"
Transform: Count
Resources:
Bucket:
Type: AWS::S3::Bucket
Properties:
Tags:
- Key: TestKey
Value: my bucket %d
Count: 3

相当于:

AWSTemplateFormatVersion: "2010-09-09"
Resources:
Bucket1:
Type: AWS::S3::Bucket
Properties:
Tags:
- Key: TestKey
Value: my bucket 1
Bucket2:
Type: AWS::S3::Bucket
Properties:
Tags:
- Key: TestKey
Value: my bucket 2
Bucket3:
Type: AWS::S3::Bucket
Properties:
Tags:
- Key: TestKey
Value: my bucket 3

关于amazon-web-services - 如何循环访问 CloudFormation 模板中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57195157/

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