charles bell
charles bell

Reputation: 177

Persistant EBS on AWS EC2 instances

I have t2.micro EC2 instance running on AWS. To handle spikes in traffic I have created auto scale group which dynamically increases and decreases EC2 instances from an AMI. Everything is fine till here. The problem is my user login database is in same EC2 instance. When new EC2 instance is spawned it does not contain newly added user in primary EC2 instance. And if new user creates account in new instance, it is lost on the instance termination. Is there a way to have single EBS volume for all the instances?

Please point me towards some useful resources on building scalable web apps on AWS.

Upvotes: 0

Views: 90

Answers (1)

Renato Gama
Renato Gama

Reputation: 16519

The problems you are facing are the primarily reasons why this pattern (all in the same instance) is discouraged. This works while your app is small and is not receiving a lot of traffic.

What you should do instead is to extract your database from the app instances and move it to RDS (being it semi-managed will prevent you from a lot of tasks like server patching, regular backups, configuring replica set, etc). Also RDS will provide you with easy multi-AZ deployment that will help you achieve real fault tolerance. This step is optional though - you could just spin up a new EC2 instance and manually install your DB there (but keep it dedicated to DB purpose).

You architecture should look similar to the following diagram;

ELB ---> INSTANCE 1 --> RDS DB INSTANCE
     |                       ^
     |-> INSTANCE 2 ---------|
     |                       |
     |-> INSTANCE n ---------|

You should keep your instances as stateless as possible if you want to scale. The same approach applies to files that you store in the instance it self; you should move them to S3 (or if available on your region you can also use Elastic File System)

Upvotes: 1

Related Questions