我已通过 Cloudformation 模板创建了一个自动缩放组及其启动配置。
自动缩放组只有一个名为“name”的标签。 启动配置中的 ec2 实例有一个 block 储存设备映射,如下所示:
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
但问题是在关联的自动缩放组中定义的名为“name”的标签不会传播到创建的 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
更新堆栈时出现以下错误:
You can specify only one TagSpecification parameter in the request. Ensure that the request includes only one TagSpecification parameter and try again.
最佳答案
应该是:
ASGLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
DependsOn: CloudwatchConfigSsm
Properties:
LaunchTemplateName: !Sub 'ec2-launch-template-${Region}-${Env}'
LaunchTemplateData:
ImageId: !Ref PresentationAMIId
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'
InstanceType: !Ref PresentationInstanceType
NetworkInterfaces:
- AssociatePublicIpAddress: false
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 20
VolumeType: gp2
Encrypted: true
关于amazon-web-services - AWS 云信息 : Tagging block device from auto-scaling launch configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69460366/