1

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.

gre_gor
  • 6,669
  • 9
  • 47
  • 52
Nani
  • 117
  • 1
  • 12
  • 2
    Can you provide the relevant code for the CloudFormation template? – Eric Dec 13 '17 at 22:32
  • the problem got solved by setting ASG update policy with min instance in service to zero – Nani Dec 14 '17 at 20:00
  • 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 Aug 28 '18 at 09:22

2 Answers2

1

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.

John Hanley
  • 74,467
  • 6
  • 95
  • 159
  • i put an update policy with min instance in service =0 and min=1, desired=1, max=1 ,so that ASG terminates old one and the volumes are available and when it launches new instance it attaches old volumes to new one – Nani Dec 14 '17 at 19:57
0

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

Nani
  • 117
  • 1
  • 12