【发布时间】:2021-11-26 07:37:54
【问题描述】:
我已经通过 Cloudformation 模板创建了一个自动缩放组及其启动配置。
自动缩放组只有一个名为“名称”的标签。 启动配置中 ec2 实例的块储存设备映射如下:
ASGLaunchConfiguration:
Type: AWS::AutoScaling::LaunchConfiguration
DependsOn: CloudwatchConfigSsm
Properties:
ImageId: !Ref PresentationAMIId
InstanceType: !Ref PresentationInstanceType
AssociatePublicIpAddress: false
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 20
VolumeType: gp2
Encrypted: true
但问题是在关联的自动缩放组中定义的名为“名称”的标记不会传播到创建的 EBS 卷。 自动伸缩组中的标签定义如下:
Tags:
- Key: 'Name'
Value: !Sub 'presentation-server-${Env}'
PropagateAtLaunch: true
此外,我需要添加一些其他重要的标签。 我怎样才能做到这一点?
更新:
我创建了以下启动模板:
ASGLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
DependsOn: CloudwatchConfigSsm
Properties:
LaunchTemplateName: !Sub 'ec2-launch-template-${Region}-${Env}'
TagSpecifications:
- ResourceType: instance
Tags:
- Key: System
Value: 'xxx'
- Key: Env
Value: !Sub '${Env}'
- Key: EnvNumber
Value: '01'
- Key: Country
Value: !Sub '${Region}'
- Key: Company
Value: 'xxx'
- Key: Global
Value: 'all'
- Key: CostCenter
Value: 'xxxx'
- Key: 'Name'
Value: !Sub 'presentation-server-${Env}'
- ResourceType: volume
Tags:
- Key: 'Name'
Value: !Sub 'presentation-server-ebs-volume-${Env}'
- Key: System
Value: 'xxx'
- Key: Env
Value: !Sub '${Env}'
- Key: EnvNumber
Value: '01'
- Key: Country
Value: !Sub '${Region}'
- Key: Company
Value: 'xxx'
- Key: Global
Value: 'all'
- Key: CostCenter
Value: 'xxxx'
LaunchTemplateData:
ImageId: !Ref PresentationAMIId
InstanceType: !Ref PresentationInstanceType
NetworkInterfaces:
- AssociatePublicIpAddress: false
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 20
VolumeType: gp2
Encrypted: true
更新堆栈时出现以下错误:
您只能在请求中指定一个 TagSpecification 参数。 确保请求只包含一个 TagSpecification 参数 然后再试一次。
【问题讨论】:
-
根据您的建议修改了我的模板。我今天将更新堆栈并在此处通知您。非常感谢:)
-
@Marcin 我在更新堆栈时用错误输出更新了问题
-
对不起,我不知道你的新代码是什么?如果你愿意,你可以提出新的问题。
-
@Marcin 用代码更新了问题
-
我用更正的模板更新了答案。
标签: amazon-web-services amazon-cloudformation tagging block-device