Amazon Web Services-在CloudFormation中用自己的名称标记S3存储桶 [英] Amazon Web Services - Tag a S3 bucket with its own name within a CloudFormation
问题描述
我目前正在使用AWS CloudFormation,因为我想用自己的名称标记存储桶(以便在成本分配报告中将其成本分开)。
I am currently fighting with AWS CloudFormation because I want to tag a bucket with its own name (in order to separate its costs in my Cost Allocation report).
当我这样做
"MyBucket" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"AccessControl" : "Private",
"Tags" : [
{ "Key" : "Name", "Value" : { "Ref" : "MyBucket" } }
]
}
},
CloudFormation向导引发以下错误:
the CloudFormation wizard throws the following error:
Error
Template validation error: Circular dependency between resources: [MyBucket]
真正的问题是我想保留生成的名称(例如my-bucket-15jsi17g9cby0),使其不通过 BucketName属性指定自定义名称。
The real problem is that I want to keep the generated name (such as my-bucket-15jsi17g9cby0) as not specify a custom name through the "BucketName" property.
有人有想法吗?
推荐答案
您可以使用CloudFormation 伪参数,以生成BucketName和Name标记值的唯一名称。这类似于模板自动生成的内容。这也保证了唯一的名称,因为与该区域组合的堆栈名称对于CloudFormation必须是唯一的。如果仅使用单个区域,则可以删除区域引用。
You could use the CloudFormation pseudo parameters to generate a unique name for the BucketName and the Name tag value. This is similar to what the template generates automatically. This also guarantees a unique name since the stack name combined with the region must be unique to CloudFormation. If you're only using a single region, you could drop the region reference.
"MyBucket" : {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"BucketName" : { "Fn::Join" : [ "-", [{ "Ref" : "AWS::StackName" }, "s3", { "Ref" : "AWS::Region" }]]},
"AccessControl" : "Private",
"Tags" : [
{ "Key" : "Name", "Value" : { "Fn::Join" : [ "-", [{ "Ref" : "AWS::StackName" }, "s3", { "Ref" : "AWS::Region" }]]}}
]
}
}
这篇关于Amazon Web Services-在CloudFormation中用自己的名称标记S3存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!