AWS RDS Database
Complete AWS RDS setup guide for NEXTDEVKIT with SST configuration and managed PostgreSQL service.
AWS RDS is the default database for NEXTDEVKIT's SST AWS deployment, offering managed PostgreSQL with enterprise-grade features, auto-scaling, and high availability.
🚀 Why AWS RDS?
AWS RDS is chosen for SST AWS deployment because:
- 🛡️ Managed service: Automated backups, patching, and maintenance
- 📈 Auto-scaling: Automatic storage and compute scaling
- 🔒 Enterprise security: VPC isolation, encryption, and IAM integration
- 🌐 High availability: Multi-AZ deployment for production workloads
- ⚡ Performance: Optimized for high-performance applications
- 📊 Monitoring: CloudWatch integration and performance insights
🏗️ Architecture Overview
SST + RDS Architecture
NEXTDEVKIT uses SST to provision and manage AWS RDS infrastructure:
Component | Next.js App (Lambda) | AWS RDS (PostgreSQL) | AWS VPC (Network) |
---|---|---|---|
Core Features | 🚀 API Routes | 🗄️ Primary DB | 🔒 Private Subnets |
⚙️ Server | 📖 Read Replica | 🛡️ Security Groups | |
🧩 Components | 💾 Backups | ||
📊 Monitoring | |||
Supporting Services | ☁️ CloudFront (CDN) | 🔗 RDS Proxy (Connection) | 🔐 Secrets Manager |
🔧 SST Configuration
1. SST Config Setup
Change the default database provider in your sst.config.ts
to AWS RDS:
For example, you can change the instance type to other types like t4g.medium
or t4g.large
to get more performance.
And you need change the database name to your own database name.
// sst.config.ts
// Create RDS PostgreSQL Instance
const database = new sst.aws.Postgres("NextDevKitDB", {
instance: "t4g.micro", // Instance type
storage: "20 GB", // Storage size
version: "16.4", // PostgreSQL version
vpc, // VPC reference
proxy: true, // Enable RDS Proxy
password: $dev
? process.env.DATABASE_PASSWORD
: new sst.Secret("NextDevKitDBPassword").value,
dev: {
host: process.env.DATABASE_HOST,
port: Number(process.env.DATABASE_PORT || 5432),
database: process.env.DATABASE_NAME,
username: process.env.DATABASE_USERNAME,
password: process.env.DATABASE_PASSWORD,
},
});
🔧 Environment Configuration
1. Development Environment
Set up local development environment variables:
# .env.local
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=your-database-name
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=your-local-password
DATABASE_URL=postgresql://postgres:your-local-password@localhost:5432/your-database-name
2. Production Secrets
Configure production secrets using SST:
# Set production secrets
sst secret set NextDevKitDBPassword "your-secure-database-password"
Ohter fields is set up by the sst automatically.
const pool = new Pool({
host: Resource.NextDevKitDB.host,
port: Resource.NextDevKitDB.port,
user: Resource.NextDevKitDB.username,
password: Resource.NextDevKitDB.password,
database: Resource.NextDevKitDB.database,
});
export const db = drizzle(pool);
🗄️ Database Schema & Client
Database Client Configuration
Configure the database client for AWS RDS:
🚀 Deployment & Management
1. Deploy Infrastructure
Deploy your SST infrastructure:
# Deploy to development
npx sst deploy --stage dev
# Deploy to production
npx sst deploy --stage production
2. Database Migrations
Run database migrations after deployment:
# Generate migration
pnpm db:generate
NEXTDEVKIT uses lambda handler to run the migrations, it is automatically triggered by the deployment.
// sst.config.ts
if (!$dev) {
new aws.lambda.Invocation("DatabaseMigratorInvocation", {
input: Date.now().toString(),
functionName: migrator.name,
});
}
🔍 Monitoring & Observability
CloudWatch Integration
SST automatically sets up CloudWatch monitoring:
🛠️ Troubleshooting
Common Issues
Connection Timeouts:
- Check VPC security groups
- Verify RDS Proxy configuration
- Ensure Lambda has VPC access
Connection Limits:
- Use RDS Proxy for connection pooling
- Optimize connection lifecycle
- Monitor connection metrics
🔗 Related Resources
🎯 Next Steps
Now that you understand the database architecture, dive into the specific setup for your chosen platform: