1
votes

I am using cloudformation template and using autoscaling in it.

I am able to persist my volumes when I delete my stack, but I am not able to attach any tags to my volumes via cloudformation.

Is there any way to do this ?

Or is it possible to create a AWS::EC2::Volume and attach it to autoscaling group in cloudformation. I have also tried this but I am not able to do this.

Basically my objective is whenever an instance is terminated I want to persist the volumes and the volumes must contain tags so that I can identify them.

The following Cloudformation types I am using in my template :

AWS::AutoScaling::LaunchConfiguration
AWS::AutoScaling::AutoScalingGroup

Thanks.

1

1 Answers

1
votes

The way I came up with for doing this uses UserData when an Instances launches to

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')
aws ec2 create-tags --resources ${VOLUME_IDS} --tags Key=YOUR,Value=TAG

A similar question is also asked on the aws developer forums