RDS & Databases
Duration: 55 min
AWS offers multiple database services for different use cases. Amazon RDS (Relational Database Service) manages SQL databases like MySQL, PostgreSQL, and Oracle. DynamoDB is a NoSQL database for high-scale applications. This module covers RDS, DynamoDB, Aurora, read replicas, and backups.
RDS Overview
Amazon RDS is a managed relational database service. AWS handles patching, backups, and failover. You choose the database engine (MySQL, PostgreSQL, MariaDB, Oracle, SQL Server) and instance type.
RDS provides automated backups, read replicas for scaling read traffic, and Multi-AZ deployments for high availability.
DynamoDB
DynamoDB is a fully managed NoSQL database. It's serverless, scales automatically, and provides single-digit millisecond latency. Use it for applications requiring high throughput and flexible schemas.
DynamoDB uses partition keys and sort keys to organize data. You pay for provisioned or on-demand capacity.
Aurora
Amazon Aurora is a MySQL and PostgreSQL-compatible relational database built for the cloud. It's faster than standard RDS, with automatic scaling and high availability built-in.
Aurora separates storage and compute, allowing independent scaling. It provides automatic failover and read replicas.
Read Replicas and Backups
Read replicas are copies of your database that handle read traffic. They reduce load on the primary database. You can promote a read replica to a standalone database.
Automated backups are retained for a configurable period (default 7 days). Manual snapshots are retained indefinitely until you delete them.
Hands-On: Create RDS Instance
Create an RDS MySQL instance:
aws rds create-db-instance --db-instance-identifier mydb \
--db-instance-class db.t3.micro --engine mysql \
--master-username admin --master-user-password MyPassword123 \
--allocated-storage 20Create a read replica:
aws rds create-db-instance-read-replica \
--db-instance-identifier mydb-replica \
--source-db-instance-identifier mydbCreate a manual snapshot:
aws rds create-db-snapshot --db-instance-identifier mydb \
--db-snapshot-identifier mydb-snapshot-1Describe DB instances:
aws rds describe-db-instances --db-instance-identifier mydbModify DB instance (e.g., increase storage):
aws rds modify-db-instance --db-instance-identifier mydb \
--allocated-storage 100 --apply-immediatelyPython Boto3 Example
import boto3
rds = boto3.client('rds')
# Create RDS instance
rds.create_db_instance(
DBInstanceIdentifier='mydb',
DBInstanceClass='db.t3.micro',
Engine='mysql',
MasterUsername='admin',
MasterUserPassword='MyPassword123',
AllocatedStorage=20
)
# Create read replica
rds.create_db_instance_read_replica(
DBInstanceIdentifier='mydb-replica',
SourceDBInstanceIdentifier='mydb'
)
# Describe instances
response = rds.describe_db_instances(DBInstanceIdentifier='mydb')
for db in response['DBInstances']:
print(f"Endpoint: {db['Endpoint']['Address']}")
print(f"Status: {db['DBInstanceStatus']}")DynamoDB Example
import boto3
dynamodb = boto3.resource('dynamodb')
# Create table
table = dynamodb.create_table(
TableName='Users',
KeySchema=[
{'AttributeName': 'userId', 'KeyType': 'HASH'},
{'AttributeName': 'timestamp', 'KeyType': 'RANGE'}
],
AttributeDefinitions=[
{'AttributeName': 'userId', 'AttributeType': 'S'},
{'AttributeName': 'timestamp', 'AttributeType': 'N'}
],
BillingMode='PAY_PER_REQUEST'
)
# Put item
table.put_item(Item={'userId': 'user123', 'timestamp': 1234567890, 'name': 'John'})
# Get item
response = table.get_item(Key={'userId': 'user123', 'timestamp': 1234567890})
print(response['Item'])Terraform Example
resource "aws_db_instance" "mysql" {
identifier = "mydb"
engine = "mysql"
engine_version = "8.0"
instance_class = "db.t3.micro"
allocated_storage = 20
username = "admin"
password = "MyPassword123"
backup_retention_period = 7
multi_az = true
skip_final_snapshot = false
final_snapshot_identifier = "mydb-final-snapshot"
}
resource "aws_db_instance" "replica" {
identifier = "mydb-replica"
replicate_source_db = aws_db_instance.mysql.identifier
instance_class = "db.t3.micro"
skip_final_snapshot = true
}Quiz 1
❓ What is Amazon RDS?
Quiz 2
❓ What is DynamoDB?
Quiz 3
❓ What is the purpose of a read replica?
Quiz 4
❓ What is Aurora?
Quiz 5
❓ What is a manual snapshot in RDS?