Cloudformation:实例停止后自动缩放持久卷并添加标签
Cloudformation : Autoscaling persist volume after instance stop and add tags
我正在使用 cloudformation 模板并在其中使用自动缩放。
我可以通过 cloudformation 保留我的 volumes when I delete my stack, but I am not able to attach any tags to my volumes。
有什么办法吗?
或者是否可以在 cloudformation 中创建一个 AWS::EC2::Volume and attach it to autoscaling group。我也试过这个,但我做不到。
基本上我的 objective 是每当实例终止时我想坚持 volumes and the volumes 必须包含标签以便我可以识别它们。
我在模板中使用的以下 Cloudformation 类型:
AWS::AutoScaling::LaunchConfiguration
AWS::AutoScaling::AutoScalingGroup
谢谢。
我想出的方法是在实例启动时使用 UserData
- describe volumes,按当前实例 id
筛选
VOLUME_IDS=$(aws ec2 describe-volumes --output text --filters Name=attachment.instance-id,Values=$(curl http://169.254.169.254/latest/meta-data/instance-id) --query 'Volumes[].VolumeId')
- create tags 在卷列表中
aws ec2 create-tags --resources ${VOLUME_IDS} --tags Key=YOUR,Value=TAG
aws developer 上也有人问过类似的问题forums
我正在使用 cloudformation 模板并在其中使用自动缩放。
我可以通过 cloudformation 保留我的 volumes when I delete my stack, but I am not able to attach any tags to my volumes。
有什么办法吗?
或者是否可以在 cloudformation 中创建一个 AWS::EC2::Volume and attach it to autoscaling group。我也试过这个,但我做不到。
基本上我的 objective 是每当实例终止时我想坚持 volumes and the volumes 必须包含标签以便我可以识别它们。
我在模板中使用的以下 Cloudformation 类型:
AWS::AutoScaling::LaunchConfiguration
AWS::AutoScaling::AutoScalingGroup
谢谢。
我想出的方法是在实例启动时使用 UserData
- describe volumes,按当前实例 id 筛选
VOLUME_IDS=$(aws ec2 describe-volumes --output text --filters Name=attachment.instance-id,Values=$(curl http://169.254.169.254/latest/meta-data/instance-id) --query 'Volumes[].VolumeId')
- create tags 在卷列表中
aws ec2 create-tags --resources ${VOLUME_IDS} --tags Key=YOUR,Value=TAG
aws developer 上也有人问过类似的问题forums