【问题标题】:AWS Cloudformation: Tagging block device from auto-scaling launch configurationAWS Cloudformation:从自动扩展启动配置中标记块设备
【发布时间】: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


【解决方案1】:

应该是:

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

【讨论】:

  • 谢谢。我会尝试一下并尽快通知您
  • @MahbubRahman 进展如何?仍然不清楚你能做什么?
  • 我从您上面的回答中了解到我在模板中犯了什么错误。 TagSpecifications 未放置在正确的位置。我进行了更正,但尚未更新我的堆栈。完成后我一定会通知你的。
  • @MahbubRahman 有什么好消息吗?
  • @kaissun 是的,它正在工作
猜你喜欢
  • 1970-01-01
  • 2014-01-25
  • 1970-01-01
  • 2015-04-11
  • 2016-02-10
  • 1970-01-01
  • 2017-11-18
  • 1970-01-01
  • 2018-08-20
相关资源
最近更新 更多