Overview
TheDatabaseFactory creates database resources with type-safe configurations. It supports Aurora (Serverless v2 clusters), RDS instances, Global Aurora, and DynamoDB tables.
For S3 storage buckets, use the StorageFactory instead.
Basic Usage
Database Types
Aurora
Aurora Serverless v2 cluster running PostgreSQL or MySQL:- Serverless v2 writer and optional read replicas
- Capacity scales automatically with load
- High availability across Availability Zones
- Automatic backups with snapshot removal policy
RDS Instance
Traditional database instance for predictable workloads:- Fixed instance size
- Lower baseline cost for small workloads
- Free tier eligible (t4g.micro)
Global Aurora
Multi-region database for global applications:- Cross-region replication
- Low-latency global reads
- Automatic failover
DynamoDB
Serverless NoSQL database:- Serverless (pay per request)
- Single-digit millisecond latency
- Automatic scaling
- Global tables support
Configuration Parameters
Common Parameters (Relational)
Use
databaseEngine for simple string-based configuration. Use engine only when you need to pass a CDK engine object with custom parameters.Aurora Parameters
Instance Parameters
DynamoDB Parameters
Common Patterns
Production Aurora
Development Database
Cache Table
Session Store
Accessing Database Information
Relational Databases
DynamoDB
Connecting to Compute
Lambda with Database
ECS with Database
Granting Access
Relational Databases
Access is automatically granted when usingconnections. For manual grants:
DynamoDB
Security
Automatic Security Features
- Encryption at rest: All databases encrypted by default
- Encryption in transit: SSL/TLS enforced
- Secrets Manager: Credentials stored securely
- VPC isolation: Databases in private subnets
- Security groups: Automatic least-privilege rules
Database Insights
Best Practices
- Use Aurora Serverless for variable workloads
- Use Instance for predictable, small workloads
- Enable Database Insights in production
- Use DynamoDB for key-value and session data
- Use
connectionsfor automatic IAM and security group setup - Enable deletion protection in production
Next Steps
Storage Factory
Create S3 buckets for file storage
Compute Factory
Deploy Lambda and ECS compute resources
Payload Pattern
Full-stack Payload CMS deployment
Standard Pattern
Production web application pattern