DEV Community

Cover image for Amazon RDS Basics: Managed Databases, Multi-AZ, Read Replicas and Backups
Robin Sishodia
Robin Sishodia

Posted on Originally published at sishodiarobin.hashnode.dev

Amazon RDS Basics: Managed Databases, Multi-AZ, Read Replicas and Backups

Amazon RDS runs a managed relational database for you. AWS handles the server, patching, backups and failover, and you choose the engine, size and settings. It is the usual next step after you have an app that scales and needs a database behind it.

What it does

  • Runs engines such as MySQL, PostgreSQL, MariaDB, Oracle and SQL Server, and Amazon Aurora.
  • Takes automated backups and lets you restore to a point in time.
  • Can keep a standby copy in another Availability Zone with Multi-AZ.
  • Can add read replicas to spread read traffic.

Key concepts

Piece What it is
DB instance The managed database server
DB subnet group The subnets, in at least two Availability Zones, where RDS can place the database
Multi-AZ A standby copy in another zone for automatic failover
Read replica A copy that serves read-only queries to take load off the main database
Automated backups and snapshots Daily backups with a retention period, plus manual snapshots you keep
Parameter group The engine settings you can change
Security group Controls who can connect to the database port

Good to know

  • Keep the database in private subnets and do not make it publicly accessible.
  • Allow access only from your application's security group.
  • Multi-AZ is for availability and failover. Read replicas are for read performance. They are not the same thing.
  • Turn on automated backups and pick a retention period that fits your needs.
  • Turn on encryption at rest when you create the database, because it is chosen at creation time.
  • Store the database password in Secrets Manager instead of in your code.
  • Check the current pricing and free tier rules, because a running database costs money even when idle.

Hands-on: try it in your own account

  1. Open RDS > Subnet groups and create a subnet group with private subnets in two Availability Zones.
  2. Create a security group that allows the database port only from your web server's security group.
  3. Choose Create database, pick MySQL or PostgreSQL, and use the Free tier template if it is available to you.
  4. Choose a small instance class, turn off public access, and select your subnet group and security group.
  5. Leave automated backups and encryption on.
  6. Wait until the status is Available, then connect from your EC2 instance with a client.
  7. Take a manual snapshot and look at the restore option.
  8. Clean up: delete the database, choose whether to keep a final snapshot, and delete the snapshots you do not need.

Common mistakes

  • Making the database publicly accessible.
  • Opening the database port to the whole internet instead of to the app's security group.
  • Thinking Multi-AZ is a read replica, or the other way round.
  • Forgetting that encryption must be chosen when the database is created.
  • Leaving the database running after practice and paying for it.

Key takeaways

  • RDS is a managed relational database, so AWS does the servers and backups.
  • Keep it private and open the port only to your app.
  • Multi-AZ is for failover, read replicas are for reads.
  • Delete the practice database and snapshots when you are done.

Tomorrow I'll start a new AWS topic.

Part of #120DaysOfAWS.

Top comments (0)