amazon-web-services - AWS 云信息 : Tagging block device from auto-scaling launch configuration

标签 amazon-web-services aws-cloudformation tagging block-device

我已通过 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/

相关文章:

amazon-web-services - 有没有办法通过 cloudformation/cdk 配置 aws sso 用户?

amazon-web-services - Redis集群在不同主机上有什么好处?

azure - AWS RDS - 对我来说访问 BI/DW 系统的最佳方式是什么

amazon-web-services - 如何使用 cognito 身份 ID 获取用户属性(用户名、电子邮件等)

python - nltk pos 标记器看起来包含 '.'

amazon-s3 - 您可以在 AWS 中标记单个 S3 对象吗?

jquery - 复制 stackoverflow 问题页面中使用的标签文本框的最简单方法是什么

amazon-web-services - Talend S3 CSV转为Redshift处理丢失的数据

amazon-web-services - 具有 Cloudformation 动态引用的 AWS Proton 模板

amazon-web-services - AWS CFT Glue 在 DynamoDB Target 中添加采样