Create Database in RDS
Setting up PostgreSQL database on AWS RDS for Django
🗄️ What is AWS RDS?
AWS RDS (Relational Database Service) is a managed database service that handles setup, backups, and maintenance automatically. It's ideal for Django applications requiring reliable, scalable PostgreSQL databases in the cloud.
# Django will connect to RDS like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'HOST': 'your-rds-endpoint.amazonaws.com',
}
}
RDS Key Features
Automated Backups
Daily automatic database backups
Retention: 1-35 days
Point-in-time recovery
Scalability
Easy storage and compute scaling
Vertical: Upgrade instance
Horizontal: Read replicas
Security
Encryption and network isolation
VPC isolation
SSL connections
Encryption at rest
High Availability
Multi-AZ deployment option
Automatic failover
99.95% uptime SLA
🔹 Step 1: Access RDS Dashboard
Navigate to the RDS service in your AWS Console. RDS is located under the Database category and provides a centralized interface for creating and managing all your database instances.
How to Access:
- Log in to AWS Management Console
- Search for "RDS" in the services search bar
- Click on "RDS" to open the dashboard
- Click "Create database" button
🔹 Step 2: Choose Database Engine
Select PostgreSQL as your database engine. PostgreSQL is recommended for Django due to its advanced features, excellent Django ORM support, and robust performance for web applications.
Engine Options:
- PostgreSQL (Recommended): Best Django support
- MySQL: Alternative option
- MariaDB: MySQL fork
For Django: Choose PostgreSQL latest version
🔹 Step 3: Select Template
Choose the appropriate template based on your use case. For learning and development, the Free Tier template is perfect. It automatically configures settings to keep you within free tier limits.
# Template Options:
1. Production
- High availability
- Multi-AZ deployment
- Higher cost
2. Dev/Test
- Single instance
- Lower cost
- Good for testing
3. Free Tier (Recommended for learning)
- db.t2.micro instance
- 20GB storage
- Single-AZ
- Free for 12 months
🔹 Step 4: Configure Database Settings
Set up your database identifier, master username, and password. These credentials will be used by Django to connect to your database, so keep them secure and memorable.
# Required Settings:
DB Instance Identifier: mydjangodb
Master Username: admin
Master Password: YourSecurePassword123!
# Important Notes:
- DB identifier must be unique in your AWS account
- Username cannot be 'postgres' (reserved)
- Password must be 8-41 characters
- Include uppercase, lowercase, numbers, and symbols
Security Tips:
- Use a strong, unique password
- Store credentials securely (use environment variables)
- Never commit passwords to version control
🔹 Step 5: Configure Instance Size
Select the instance class that determines your database's computing power and memory. For free tier and learning purposes, db.t2.micro provides sufficient resources for small Django applications.
# Instance Classes:
Free Tier:
- db.t2.micro (1 vCPU, 1GB RAM)
- Suitable for development and learning
Paid Options:
- db.t3.small (2 vCPU, 2GB RAM)
- db.t3.medium (2 vCPU, 4GB RAM)
- db.m5.large (2 vCPU, 8GB RAM)
Recommendation: Start with db.t2.micro
🔹 Step 6: Storage Configuration
Configure storage type and size for your database. General Purpose SSD provides good performance for most Django applications. The free tier includes 20GB of storage, which is sufficient for learning projects.
# Storage Settings:
Storage Type: General Purpose SSD (gp2)
Allocated Storage: 20 GB (free tier maximum)
Storage Autoscaling: Disabled (for free tier)
# Storage Types:
- General Purpose (gp2): Balanced price/performance
- Provisioned IOPS (io1): High performance
- Magnetic: Legacy, not recommended
🔹 Step 7: Connectivity Settings
Configure network settings to allow your Django application to connect to the database. Public accessibility should be enabled if connecting from your local machine, but use security groups to restrict access.
# Connectivity Configuration:
Virtual Private Cloud (VPC): Default VPC
Subnet Group: Default
Public Access: Yes (for development)
VPC Security Group: Create new
Security Group Settings:
- Name: django-db-sg
- Inbound Rule: PostgreSQL (port 5432)
- Source: Your IP address (for security)
Security Best Practices:
- Only allow your IP address initially
- Use VPC for production environments
- Enable SSL/TLS connections
- Regularly update security group rules
🔹 Step 8: Additional Configuration
Set up database name, backup retention, and monitoring options. These settings help you manage your database effectively and ensure data safety through automated backups and performance monitoring.
# Additional Settings:
Database Name: djangodb
Port: 5432 (default PostgreSQL port)
Backup Retention: 7 days
Monitoring: Enable Enhanced Monitoring
Auto Minor Version Upgrade: Yes
# Optional Settings:
- Encryption: Enable for production
- Performance Insights: Enable for monitoring
- Deletion Protection: Enable for production
🔹 Step 9: Create Database
Review all settings and create your RDS instance. The creation process takes 5-10 minutes. Once complete, you'll receive an endpoint URL that Django will use to connect to your database.
Creation Process:
- Review all configuration settings
- Click "Create database" button
- Wait for status to change to "Available"
- Note down the endpoint URL
# Your RDS Endpoint will look like:
mydjangodb.c9akciq32.us-east-1.rds.amazonaws.com
# Save these details:
- Endpoint URL
- Port: 5432
- Database name: djangodb
- Master username: admin
- Master password: (your password)
🔹 Verify Database Creation
After creation, verify your database is running and accessible. Check the RDS dashboard for the instance status and ensure all configurations are correct before connecting from Django.
Verification Checklist:
- ✓ Status shows "Available"
- ✓ Endpoint URL is visible
- ✓ Security group allows your IP
- ✓ Public accessibility is enabled