Skip to main content

Overview

The RDS module creates Amazon RDS database instances (PostgreSQL, MySQL, or MariaDB) with security groups, subnet groups, parameter groups, and automated password generation.

Features

Multiple Database Engines

Support for PostgreSQL, MySQL, and MariaDB

Automated Backups

Configurable backup retention and maintenance windows

Encryption

Encryption at rest with KMS (enabled by default)

Security Groups

Automatic security group with CIDR and security group ID allow lists

Password Generation

Automatic secure password generation if not provided

Multi-AZ

Optional Multi-AZ deployment for high availability

Usage Examples

Basic PostgreSQL Instance

If password is not provided, a random 24-character password is generated and stored in Terraform state as a sensitive output.

Production PostgreSQL with Multi-AZ

MySQL Database

With Custom Parameters

Publicly accessible RDS instances should only be used for testing. Always use private subnets for production databases.

Inputs

Outputs

Connection Strings

Using Terraform Outputs

PostgreSQL Connection

MySQL Connection

From Application

Security Best Practices

Private Subnets

Always deploy RDS in private subnets without public access.

Encryption

Enable encryption at rest using KMS keys for sensitive data.

Strong Passwords

Use auto-generated passwords or strong custom passwords (min 24 characters).

Least Privilege

Restrict security group access to only required sources.

Backup Retention

Set appropriate backup retention (7-35 days for production).

Deletion Protection

Enable deletion protection for production databases.

Performance Tuning

Instance Sizing

Storage Auto-Scaling

Performance Insights

Enable for production databases:
View insights in AWS Console:

Backup and Recovery

Automated Backups

Manual Snapshot

Restore from Snapshot

Troubleshooting

Cannot Connect to Database

Check security group rules:
Verify subnet routing:
Test connection from EC2:

Performance Issues

Check Performance Insights:
  • RDS Console → Performance Insights
  • Look for slow queries and high wait events
Review CloudWatch metrics:

Storage Full

Enable auto-scaling:
Or increase manually:

Cost Optimization

Start with smaller instances and scale based on CloudWatch metrics. Over-provisioning wastes money.Development: db.t3.micro (~15/month)∗∗Production:∗∗db.m5.large( 15/month) **Production:** db.m5.large (~150/month)
gp3 provides better baseline performance at lower cost:
  • 100 GB gp2: ~$11.50/month
  • 100 GB gp3: ~$10.00/month
Shorter retention saves on backup storage costs:
  • Development: 7 days
  • Production: 14-30 days
Multi-AZ doubles RDS costs. Only use in production:
  • Single-AZ: $150/month
  • Multi-AZ: $300/month

VPC Module

Create VPC and subnets for RDS

EKS Module

Connect RDS to EKS workloads

K8s Scheduler Configuration

Configure database connection

Infrastructure Guide

Complete deployment workflow