I'm looking for some best practices on how to run stateful applications on EC2 while utilizing Auto Scaling Groups (ASG). Our application needs to save state data to an EBS volume instead of a database, and we want to ensure that if an instance is replaced or recreated, we can recover and reuse those files. I understand that ASG/Launch Templates don't allow for attaching existing EBS volumes. Is there a common way in the industry to manage this? I'm open to suggestions on how to implement this efficiently, and I would appreciate any links to documentation or design patterns that could help. I've considered using ASG lifecycle hooks, Lambda, and CloudWatch metrics to create our own ASG controller, but I doubt it would match the reliability of using ASG directly. I'd rather not reinvent the wheel if there are existing solutions.
2 Answers
You could create an EFS (Elastic File System) first as part of your infrastructure, then mount it to your EC2 instances. It might introduce a little latency, but it's usually manageable, much less than using S3.
It really depends on the type of data you need to save. Both EFS and S3 can be good options for your use case, but you'd have to consider their performance aspects. EFS can introduce some latency, but if your data is mostly config files like XML or JSON, it should be fine. Just a note, you can't directly attach EFS in a launch template, so keep that in mind!
Does using EFS or S3 affect writing speed at all?

Got it, thanks for the suggestion!