简体   繁体   English

在 cloudformation 模板中设置堆栈级别标签 - 而不是在嵌套堆栈中

[英]set stack level tags in a cloudformation template- not in a nested stack

A little confused about how to do this or if its possible.对如何做到这一点或是否可能感到有些困惑。

THis is not a nested stack.这不是嵌套堆栈。 I want to set tags in my CF template that apply to all resources in the template.我想在我的 CF 模板中设置适用于模板中所有资源的标签。 AWS::CloudFormation::Stack resource can do that, but I don't need/want a nested stack i just have one stack and one template. AWS::CloudFormation::Stack 资源可以做到这一点,但我不需要/想要嵌套堆栈,我只有一个堆栈和一个模板。

Use command deploy with --tags :使用命令deploy--tags

aws cloudformation deploy \
   --template-file template.yaml \
   --stack-name MyStack \
   --tags Key1=Value1 Key2=Value2

Docs : 文档

--tags (list) A list of tags to associate with the stack that is created or updated. --tags (list) 与创建或更新的堆栈相关联的标签列表。 AWS CloudFormation also propagates these tags to resources in the stack if the resource supports it.如果资源支持,AWS CloudFormation 还会将这些标签传播到堆栈中的资源。 Syntax: TagKey1=TagValue1 TagKey2=TagValue2 ...语法:TagKey1=TagValue1 TagKey2=TagValue2 ...

You can solve that with a kind of a workaround.您可以通过一种解决方法来解决该问题。 You can create another CF template that will include only the "AWS::CloudFormation::Stack" resource.您可以创建另一个仅包含“AWS::CloudFormation::Stack”资源的 CF 模板。 In the parameters, provide the tags that you want, and in the "TemplateURL" property, provide the URL of a template that specifies the stack that you want to create as a resource.在参数中,提供所需的标签,并在“TemplateURL”属性中,提供指定要创建为资源的堆栈的模板的 URL。 Note that the template must be stored on an Amazon S3 bucket, so the URL must have the form: https://s3.amazonaws.com/.../TemplateName.extension请注意,模板必须存储在 Amazon S3 存储桶中,因此 URL 必须采用以下格式: https : //s3.amazonaws.com/.../TemplateName.extension

For more details: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-templateurl有关更多详细信息: https : //docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-templateurl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM