gpt4 book ai didi

amazon-web-services - 我可以将标签定义为参数部分 AWS CloudFormation 模板中的参数吗

转载 作者:行者123 更新时间:2023-12-04 08:12:33 24 4
gpt4 key购买 nike

我可以将标签定义为参数部分 AWS CloudFormation 模板中的参数并在每个创建的资源中使用它吗?

我当前的模板:

AWSTemplateFormatVersion: 2010-09-09
Description: "Some information"
Parameters:
Test1:
Type: String
Description: Test1
Default: t1
Test2:
Type: String
Description: Test2
Default: t2

...

LBSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Enable access to app loadbalancer"
Tags:
- Key: Name
Value: !Join
- ""
- - !Ref Test1
- !Ref Test2
- Key: Test1
Value: !Ref Test1
- Key: Test2
Value: !Ref Test2

我对任何其他资源(AWS::ElasticLoadBalancing::LoadBalancer、AWS::AutoScaling::AutoScalingGroup 等)使用相同的标签,并且看起来像是重复的代码(每次创建新资源时)。我可以制作这样的东西吗?:

AWSTemplateFormatVersion: 2010-09-09
Description: "Some information"
Parameters:
Test1:
Type: String
Description: Test1
Default: t1
Test2:
Type: String
Description: Test2
Default: t2
Tag:
#define all tags, which I created above

...

LBSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: "Enable access to app loadbalancer"
Tags: !Ref Tag

...

不幸的是,我在https://docs.aws.amazon.com/上没有找到任何相关信息。

最佳答案

您可以将标记应用到堆栈,它们将传播到资源。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html

All stack-level tags, including automatically created tags, are propagated to resources that AWS CloudFormation supports. Currently, tags are not propagated to Amazon EBS volumes that are created from block device mappings.

例如:

aws cloudformation create-stack --stack-name my-stack
--template-url <template>
--parameters ParameterKey=Param1,ParameterValue=Value1
--tags Key=Tag1,Value=Value1

关于amazon-web-services - 我可以将标签定义为参数部分 AWS CloudFormation 模板中的参数吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49149800/

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