ccleve
ccleve

Reputation: 15799

Move EBS volume to new instance on instance failure

If an EC2 instance goes down and autoscaling brings up a new instance, how do I move the old EBS volume to the new instance automatically?

The EBS volume will likely contain a large amount of data, and backups aren't instant, so relocating the volume automatically is probably the best way to preserve data.

Upvotes: 4

Views: 1269

Answers (3)

BraveNewCurrency
BraveNewCurrency

Reputation: 13065

If an EC2 instance goes down and autoscaling brings up a new instance, how do I move the old EBS volume to the new instance automatically?

There is no API call to do this automatically. But you can write a daemon that will launch a new box with the right parameters.

Unfortunately, what you want to do is not a good strategy if you care about disaster recovery:

1) When an box dies, it's possible that the EBS volume can get "stuck" in the detaching state for hours (I've actually seen >24 hours).

2) If your zone is having problems, you can easily launch instance in other zones, but you can't move the drive between zones.

You're much better off launching from a snapshot instead, which solves both of those problems.

(You might also consider a distributed filesystem like CEPH, GFS, AFS, etc.)

Upvotes: 4

yegor256
yegor256

Reputation: 105053

Autoscaling should not only bring up a new instance, but also attach the same EBS volume to it. As soon as the previous EC2 instance gets terminated AWS automatically detaches EBS volume. If you're using Elastic Beanstalk I would recommend to use ebextensions. Otherwise, you should rely on OpsWorks.

Or do this attachment manually through SDK/API.

Upvotes: -3

Deepak Singhal
Deepak Singhal

Reputation: 10866

I think what you are looking for is S3. If there is some data which you feel needs to be shared by other ec2 instances.. then you should save that data on S3 rather than on EBS volume itself. Data on S3 can easily be accessed by any EC2 instance even located outside network location and that too with very minimal latency. EBS volume are supposed to be associated with that EC2 itself.

Upvotes: 1

Related Questions