Search code examples
powershellamazon-web-servicesamazon-ec2amazon-ebs

Mount back an EBS snapshot in Auto Scaling


I am using Auto Scaling with a Load Balancer and have attached 2 EBS volumes.

Now whenever an instance is terminated it stores the snapshot of the EBS volumes.

I have gone through several links but cannot find how to retrieve/mount the EBS volume when a Launch Configuration launches a new instance.

Can I can get any reference or PowerShell script to identify a volume via tag name from the volume list and mount it when the instance is initiating?


Solution

  • There is no automatic facility to mount an existing EBS snapshot or volume when Auto Scaling launches an instance.

    Best practice for Auto Scaling is to store data off-instance, such as in Amazon S3 or Amazon EFS. This way, the data is accessible to all instances simultaneously and can be used by new instances that are launched.

    There is also no automatic facility to create an EBS snapshot when an Auto Scaling instance is terminated. Rather, there is the option to Delete on Termination, which controls whether the EBS volume should be deleted when the instance is terminated. If this option is off, then the EBS volumes will remain after an instance is terminated. You could write some code (eg in a User Data script) that re-attached an EBS volume to a new instance launched by Auto Scaling but this can get messy. (For example: Which instance to attach? What happens if more instances are launched?)

    Bottom line: Yes, you could write a script to do this, but it is a poor architectural design.