1
votes

I have cloud formation template that creates two EBS volumes and I am attaching those volumes to instance using aws ec2 attach-volumes from user data, also I have auto scaling group setup, so when I update stack with different instance type and it launches new instance, volumes are not attached.

I checked logs and it says volumes are not available, I know why because the terminated instance is using those volumes when ASG launches new one, is there any way that I could reuse those volumes.

2
Can you provide the relevant code for the CloudFormation template? - Eric
the problem got solved by setting ASG update policy with min instance in service to zero - Nani
are you creating the EBS volume via CloudFormation as well? how do you identify the volume in your attach-volume script, would you mind sharing those details? - Roberto Andrade

2 Answers

1
votes

Your problem is that the EBS volumes are attached to a different EC2 instance when you want to attach them.

One solution is to write a program (e.g. Python) that monitors the EBS volumes. The program is launched in UserData. Once the volumes become available the program attaches them and exits.

0
votes

when i add ASG update policy with min instance in service = 0 and min=1, desired=1 and max=1 it is working because ASG terminates old instance before it launches new instance when you have min instances in service=0