Amazon web services CloudFormation模板导入其他模板
我有一个需要在模板中重复多次的结构,唯一的区别是可以与Amazon web services CloudFormation模板导入其他模板,amazon-web-services,amazon-cloudformation,Amazon Web Services,Amazon Cloudformation,我有一个需要在模板中重复多次的结构,唯一的区别是可以与“Fn::Join”一起使用的变量: 我希望有这样的解决方案: "Import" : [ { "Path":"s3://...", "Parameters":[ {"Key":"name", "Value":"foobar"} ] ] CloudFormation是否支持此功能,或者是否有一些工具可以实现此功能?使用。它允许编写生成CloudFo
“Fn::Join”一起使用的变量:
我希望有这样的解决方案:
"Import" : [
{
"Path":"s3://...",
"Parameters":[
{"Key":"name", "Value":"foobar"}
]
]
CloudFormation是否支持此功能,或者是否有一些工具可以实现此功能?使用。它允许编写生成CloudFormation模板的python代码——再也不用直接编写JSON了。如有必要,向注释、循环、类型检查和更高级的编程结构问好
此代码段将通过循环bucket\u name
list为2个S3 bucket生成一个模板:
来自对流层导入输出,参考,模板
从troposphere.s3导入桶,PublicRead
t=模板()
#桶的名称
bucket_name=['foo','bar']
对于bucket_名称中的bucket_名称:
s3bucket=t.add\u资源(Bucket(Bucket\u名称,AccessControl=PublicRead,)
t、 添加输出(
输出(
bucket_name+“bucket”,
值=参考值(s3bucket),
Description=“名称%s S3存储桶内容”%bucket\u名称
)
)
打印(t.to_json())
云形成模板:
{
"Outputs": {
"barBucket": {
"Description": "Name of bar S3 bucket content",
"Value": {
"Ref": "bar"
}
},
"fooBucket": {
"Description": "Name of foo S3 bucket content",
"Value": {
"Ref": "foo"
}
}
},
"Resources": {
"bar": {
"Properties": {
"AccessControl": "PublicRead"
},
"Type": "AWS::S3::Bucket"
},
"foo": {
"Properties": {
"AccessControl": "PublicRead"
},
"Type": "AWS::S3::Bucket"
}
}
}
注意:由于CloudFormation在堆栈名称前加前缀,并在随机字符串后加后缀,因此桶不会被命名为foo
和bar
。在CloudFormation的输出部分可以看到实名
更多对流层示例:使用。它允许编写生成CloudFormation模板的python代码——再也不用直接编写JSON了。如有必要,向注释、循环、类型检查和更高级的编程结构问好
此代码段将通过循环bucket\u name
list为2个S3 bucket生成一个模板:
来自对流层导入输出,参考,模板
从troposphere.s3导入桶,PublicRead
t=模板()
#桶的名称
bucket_name=['foo','bar']
对于bucket_名称中的bucket_名称:
s3bucket=t.add\u资源(Bucket(Bucket\u名称,AccessControl=PublicRead,)
t、 添加输出(
输出(
bucket_name+“bucket”,
值=参考值(s3bucket),
Description=“名称%s S3存储桶内容”%bucket\u名称
)
)
打印(t.to_json())
云形成模板:
{
"Outputs": {
"barBucket": {
"Description": "Name of bar S3 bucket content",
"Value": {
"Ref": "bar"
}
},
"fooBucket": {
"Description": "Name of foo S3 bucket content",
"Value": {
"Ref": "foo"
}
}
},
"Resources": {
"bar": {
"Properties": {
"AccessControl": "PublicRead"
},
"Type": "AWS::S3::Bucket"
},
"foo": {
"Properties": {
"AccessControl": "PublicRead"
},
"Type": "AWS::S3::Bucket"
}
}
}
注意:由于CloudFormation在堆栈名称前加前缀,并在随机字符串后加后缀,因此桶不会被命名为foo
和bar
。在CloudFormation的输出部分可以看到实名
更多对流层示例: