AWS Databases
Learn about RDS (relational databases), DynamoDB (NoSQL), and choosing the right database for your needs.
Database Options in AWS
RDS
Relational Databases
MySQL, PostgreSQL, SQL Server
DynamoDB
NoSQL Database
Key-Value & Document
Aurora
MySQL/PostgreSQL Compatible
5x faster than MySQL
RDS - Relational Database Service
RDS is a managed relational database service. AWS handles backups, patching, and replication for you.
DynamoDB - NoSQL Database
DynamoDB is a fully managed NoSQL database. It's perfect for high-traffic applications that need low latency.
Speed
Single-digit millisecond latency
Scale
Auto-scales to any size
Free Tier
25 GB free forever
How to Choose the Right Database
| Use Case | Recommended Service | Why? |
|---|---|---|
| E-commerce, CRM, ERP | RDS | Complex queries, transactions, relationships |
| High-traffic web apps | DynamoDB | Fast, scalable, serverless friendly |
| Analytics, Data warehousing | Redshift | Petabyte-scale data analysis |
| Mobile/Serverless apps | DynamoDB | Low latency, auto-scaling |
| Blogs, CMS | RDS | Simple relational data |
Exercise: Create a Database
Task: Create and connect to an RDS database.
- Go to RDS and click "Create database"
- Choose MySQL or PostgreSQL
- Select Free Tier template
- Set master username and password
- Create the database (takes 5-10 minutes)
- Note the endpoint URL
- Connect using MySQL Workbench or a Lambda function
- Create a table and insert data
Show Solution
# Python Lambda function to connect to RDS
import pymysql
import json
def lambda_handler(event, context):
connection = pymysql.connect(
host='your-database-endpoint',
user='your-username',
password='your-password',
database='your-database'
)
cursor = connection.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INT, name VARCHAR(100))")
cursor.execute("INSERT INTO users VALUES (1, 'John Doe')")
connection.commit()
return {
'statusCode': 200,
'body': json.dumps('Database created and data inserted!')
}
Key Takeaway
Choose RDS for relational data with complex queries. Choose DynamoDB for high-scale, low-latency applications. Both have free tier options to get started!