0
votes

I've mounted an EBS Volume onto my Elastic Beanstalk EC2 to use it as a permanent database. I am aware that Elastic Beanstalk keeps rolling itself to a new environment every now and then, but the problem is that sometimes it changes region, (e.g. from eu-west-3a to eu-west-3c) causing my EBS volume to detach!

  1. How can I keep my EC2 instance from abruptly changing region by itself? or, limit its spawning to a single region? It's an annoyance to migrate my EBS Volume using snapshots every time this happens.

  2. How can I re-attach my EBS Volume to my EC2 instance automatically? Is .ebextensions the answer? I really can't seem to figure that one out... :(

Thank you in advance!

1

1 Answers

0
votes
  1. How can I keep my EC2 instance from abruptly changing region by itself?

You can use Custom Availability Zones option in aws:autoscaling:asg namespace to limit the Auto Scaling group (ASG) to one specific availability zone (AZ). This will ensure that when an instance is terminated and a replacement started it will be placed in the same AZ. Be sure to set the AZ to the same one where is your extra EBS volume. The drawback is that your application will be limited to only one AZ, thus if something happens with it, your application will be off-line.

  1. How can I re-attach my EBS Volume to my EC2 instance automatically? Is .ebextensions the answer?

There are several ways of doing this. .ebextensions would be one of them. You would have to provide a script which would re-attach the volume to the instance and mount it accordingly. En example script can be found here.

The other way, would be to use Amazon EC2 Auto Scaling Lifecycle Hooks. Once setup up, when the ASG launches a new instance you could have a lambda function which would attach the volume. You would also need to ensure that it is mounted on the instance. Thus probably .ebextensions would be easier to use.

P.S.

Its Availability Zone, not Region.