Setting up RDS

Before adding our production Cluster, let's set up Amazon RDS...


First off, why should we set up Amazon Relational Database Service (RDS)? Why should we not just manage Postgres within the Cluster itself?

  1. Since the recommended means of service discovery in ECS is load balancing, we'll have to register the Postgres instance with the ALB. There's additional costs and overhead associated with this. We'll also have to assign a public IP to it and expose it to the internet. It's best to keep it private.
  2. Data integrity is an issue as well. What happens if the container crashes?

For more, check out this Reddit post.

RDS Setup

Navigate to Amazon RDS, click "Instances" on the sidebar, and then click the "Launch DB Instance" button.

You probably want to click the "Free tier eligible only". More info.

Select the "PostgreSQL" engine and then "Dev/Test". Under "Specify DB Details":

  1. "DB Engine Version": PostgreSQL 9.6.2-R1
  2. "DB Instance Class": db.t2.micro
  3. "Multi-AZ Deployment": No
  4. "Storage Type": General Purpose (SSD)
  5. "Allocated Storage": 5 GB
  6. "DB Instance Identifier": flask-microservices-production
  7. "Master Username": webapp
  8. "Master Password": something_super_secret

Click "Next Step". Under "Network & Security", make sure to pick the "VPC" and "Security group" associated with ALB. Select one of the available "Subnets" as well - either us-east-1a or us-east-1b.

Change the DB name to users_prod and then create the new database.

You can quickly check the status via:

$ aws rds describe-db-instances \
  --db-instance-identifier flask-microservices-production \
  --query 'DBInstances[].{DBInstanceStatus:DBInstanceStatus}'

Then, once the status is "available", grab the address:

$ aws rds describe-db-instances \
  --db-instance-identifier flask-microservices-production \
  --query 'DBInstances[].{Address:Endpoint.Address}'

Take note of the production URI:

postgres://webapp:YOUR_PASSWORD@YOUR_ADDRESS:5432/users_prod

Keep in mind that you cannot access the DB outside the VPC. So, if you want to connect to the instance, you will need to use SSH tunneling via SSHing into an EC2 instance on the same VPC and, from there, connecting to the database.



Setting up RDS

Before adding our production Cluster, let's set up Amazon RDS...


First off, why should we set up Amazon Relational Database Service (RDS)? Why should we not just manage Postgres within the Cluster itself?

  1. Since the recommended means of service discovery in ECS is load balancing, we'll have to register the Postgres instance with the ALB. There's additional costs and overhead associated with this. We'll also have to assign a public IP to it and expose it to the internet. It's best to keep it private.
  2. Data integrity is an issue as well. What happens if the container crashes?

For more, check out this Reddit post.

RDS Setup

Navigate to Amazon RDS, click "Instances" on the sidebar, and then click the "Launch DB Instance" button.

You probably want to click the "Free tier eligible only". More info.

Select the "PostgreSQL" engine and then "Dev/Test". Under "Specify DB Details":

  1. "DB Engine Version": PostgreSQL 9.6.2-R1
  2. "DB Instance Class": db.t2.micro
  3. "Multi-AZ Deployment": No
  4. "Storage Type": General Purpose (SSD)
  5. "Allocated Storage": 5 GB
  6. "DB Instance Identifier": flask-microservices-production
  7. "Master Username": webapp
  8. "Master Password": something_super_secret

Click "Next Step". Under "Network & Security", make sure to pick the "VPC" and "Security group" associated with ALB. Select one of the available "Subnets" as well - either us-east-1a or us-east-1b.

Change the DB name to users_prod and then create the new database.

You can quickly check the status via:

$ aws rds describe-db-instances \
  --db-instance-identifier flask-microservices-production \
  --query 'DBInstances[].{DBInstanceStatus:DBInstanceStatus}'

Then, once the status is "available", grab the address:

$ aws rds describe-db-instances \
  --db-instance-identifier flask-microservices-production \
  --query 'DBInstances[].{Address:Endpoint.Address}'

Take note of the production URI:

postgres://webapp:YOUR_PASSWORD@YOUR_ADDRESS:5432/users_prod

Keep in mind that you cannot access the DB outside the VPC. So, if you want to connect to the instance, you will need to use SSH tunneling via SSHing into an EC2 instance on the same VPC and, from there, connecting to the database.