1
votes

I want to detach and attach an EBS volume on schedule.

Here is the flow example: I have 10 EC2 instances and each run a copy of my app. This app/api serves data that is on EBS volume attached to the instance. We want to refresh data every night on these instances taking one instance out of the service pool at a time. To minimize downtime of our instances, we'd create data volumes with new data in the background and once the data is ready we'd want to replace the EBS volumes. I want to do this every night for a bunch of instances: stop instance --> detach old volume --> attach new volume --> mount new volume --> restart app

What's the best way to achieve this?

1
Some alternatives: Use a shared Amazon EFS filesystem rather than EBS, or sync the data from S3 to the existing EBS volumes (triggered from each instance).John Rotenstein
Instead of using the EFS, we can also EBS with Multi-Attach feature. EBS provides better latency than the EFS volumes. The EBS can be mounted RO on the EC2 instances. But, only 16 EC2 can be attached, whereas EFS supports lot more.Praveen Sripati

1 Answers

1
votes

Create a Lambda Function with the desired logic and schedule the Lambda Function using the EventBridge. Not exactly the same, but here is a projects on cutting the costs be deleting any of the unused EBS volumes. Some of the code can be reused.