[AWS] 6. AWS Fundamentals: RDS (Relational Database Service) + Amazon Aurora + ElastiCache
Source: Dev.to
What is Amazon RDS?
- RDS = Relational Database Service – a fully‑managed database service that uses SQL as the query language.
- Lets you create, run, and scale relational databases in the AWS cloud without handling the underlying infrastructure.
Supported Engines
| Engine | Notes |
|---|---|
| PostgreSQL | |
| MySQL | |
| MariaDB | |
| Oracle | |
| Microsoft SQL Server | |
| IBM DB2 | |
| Aurora (AWS‑proprietary) | Compatible with PostgreSQL & MySQL drivers |
Core Managed‑Service Features
- Automated provisioning & OS patching
- Continuous backups → Point‑in‑Time Restore (PITR)
- Monitoring dashboards (CloudWatch)
- Read replicas – improve read performance
- Multi‑AZ deployments – disaster recovery (DR)
- Maintenance windows for upgrades
- Vertical & horizontal scaling
- EBS‑backed storage
Note: You cannot SSH directly into a standard RDS instance.
Storage Auto‑Scaling
- RDS can dynamically increase storage when free space falls below a threshold.
- Maximum storage threshold must be set (upper limit).
- Auto‑scale triggers when all conditions are met:
- Free storage falls below the defined threshold.
Network cost: Data transfer between AZs incurs a fee, but in‑region replica traffic is free.
Multi‑AZ (Synchronous) Replication
- Provides a single DNS name that automatically fails over to a standby instance.
- Increases availability; no application changes required.
- Not intended for scaling reads.
- Can be combined with read replicas for DR.
Zero‑Downtime Modification
- Click Modify in the console.
- RDS takes a snapshot.
- Restores a new DB in a different AZ.
- Synchronizes the two instances.
RDS Custom vs. Standard RDS
| Feature | RDS (Standard) | RDS Custom |
|---|---|---|
| OS & DB management | Fully managed by AWS | Managed by AWS plus full admin access |
| Customization | Limited (parameter groups, option groups) | Full OS & DB configuration, SSH/SSM access |
| Use‑case | Typical production workloads | Need for OS‑level patches, custom binaries, or special DB configurations |
Tip: De‑activate automation mode before customizing; take a snapshot first.
Amazon Aurora
- Proprietary, cloud‑optimized engine (compatible with PostgreSQL & MySQL).
- Claims 5× MySQL performance and 3× PostgreSQL performance on RDS.
- Storage auto‑scales in 10 GB increments up to 256 TB.
- Up to 15 read replicas with sub‑10 ms replica lag.
- Instantaneous failover (HA native).
Architecture Highlights
- 6 copies of data across 3 AZs:
- 4 copies for writes
- 3 copies for reads
- Peer‑to‑peer replication → self‑healing.
- Data striped across hundreds of volumes.
Features
- Automatic fail‑over
Tip: Even a stopped RDS instance incurs storage charges. If you plan to stop it for an extended period, snapshot & restore instead of leaving it stopped.
Restoring Backups
RDS / Aurora Backup → New DB Instance
- Create a backup of your on‑premises database.
- Store the backup on Amazon S3 (object storage).
- Restore the backup file onto a new RDS instance running MySQL.
Aurora Cluster → New Cluster (from S3)
- Use Percona XtraBackup (or another tool) to back up the on‑premises DB.
- Store the backup file on Amazon S3.
- Restore the file onto a new Aurora cluster running MySQL.
Clone an Existing Aurora DB Cluster
- Faster than snapshot & restore because it uses a copy‑on‑write protocol.
- The new cluster initially shares the same data volume (no data copy).
- When the new cluster is updated, additional storage is allocated and data is copied, keeping the two clusters independent.
- Use case: Create a “staging” database from production without impacting the production workload.
Encryption
At‑Rest Encryption
- Database master and replicas are encrypted with AWS KMS (must be defined at launch).
- If the master is not encrypted, read replicas cannot be encrypted.
- To encrypt an existing unencrypted DB:
- Take a DB snapshot.
- Restore the snapshot with encryption enabled.
In‑Flight Encryption
- TLS is enabled by default; use the AWS TLS root certificates on the client side.
Authentication & Access Control
- IAM Authentication: Use IAM roles instead of traditional username/passwords.
- Security Groups: Control network access to RDS/Aurora instances.
- SSH Access: Not available except on RDS Custom.
Audit & Monitoring
- Enable Audit Logs and forward them to CloudWatch Logs for longer retention.
RDS Proxy
- Fully managed database proxy for RDS/Aurora.
- Benefits:
- Pools and shares DB connections, reducing CPU/RAM load and connection‑timeouts.
- Server‑less, auto‑scaling, highly available (multi‑AZ).
- Reduces failover time by up to 66 %.
- Supports:
- RDS (MySQL, PostgreSQL, MariaDB, MSSQL Server)
- Aurora (MySQL, PostgreSQL)
- No code changes required for most applications.
- Enforce IAM authentication and store credentials securely in AWS Secrets Manager.
- Never publicly accessible – must be accessed from within a VPC.
Managed Caching: ElastiCache
| Service | Purpose | Key Features |
|---|---|---|
| ElastiCache | Managed Redis or Memcached | - In‑memory, high‑performance cache - Reduces load on primary databases - Helps make applications stateless |
| AWS responsibilities | OS maintenance, patching, optimizations, setup, monitoring, failure recovery, backups | — |
| Application impact | Requires code changes to integrate caching layer | — |
| IAM support | IAM authentication for Redis (not for Memcached) | — |
IAM Policies for ElastiCache
- Used only for AWS API‑level security (e.g., creating/modifying clusters).
Redis
- AUTH: Set a password/token when creating a Redis cluster for an extra security layer (in addition to security groups).
- Encryption in transit: Supports SSL/TLS.
Common Use Cases
- Gaming leaderboards: Use Sorted Sets for unique, ordered elements with real‑time ranking.
Memcached
- Supports SASL‑based authentication (advanced).
Caching Strategies
| Strategy | Description |
|---|---|
| Lazy Loading | Data is cached on read; cached data may become stale. |
| Write‑Through | Writes update both the cache and the underlying DB, preventing stale data. |
| Session Store | Store temporary session data with TTL (time‑to‑live) features. |
Quote: “There are only two hard things in Computer Science: cache invalidation and naming things.”
Important Ports
| Service | Port |
|---|---|
| FTP | 21 |
| SSH / SFTP | 22 |
| HTTP | 80 |
| HTTPS | 443 |
| PostgreSQL (RDS) | 5432 |
| MySQL / MariaDB (RDS) | 3306 |
| Oracle (RDS) | 1521 |
| Microsoft SQL Server (RDS) | 1433 |
| Aurora (PostgreSQL‑compatible) | 5432 |
| Aurora (MySQL‑compatible) | 3306 |
You don’t need to memorize every number; just be able to differentiate an “important” port (e.g., HTTPS 443) from an “RDS database” port (e.g., PostgreSQL 5432).