Skip to main content

Overview

The RdsAurora construct creates an Aurora Serverless v2 PostgreSQL cluster with a writer, one reader, automated backups, and storage encryption. RDS Proxy connection pooling, customer-managed KMS keys, and scheduled secret rotation are opt-in.

Resource Class

Basic Usage

Configuration Options

Core Properties

The port default comes from ENGINE_DEFAULT_DATABASE_PORTS in @fjall/generator. Keep it unless you have a reason to move: RDS Proxy accepts client connections only on the engine default, so a custom port behind a proxy makes getHostPort() report the proxy port, not the cluster port, and synth emits a warning explaining the split.

Engine Configuration

The construct pins Aurora PostgreSQL 18.4. That pin moves with construct releases, so treat the version here as indicative and read rdsAurora.ts for the current value. engineVersion is only read to validate the auto-pause floor, so pass it whenever you set serverlessV2MinCapacity: 0.

Serverless v2 Capacity

Synth rejects a min capacity above the max, an auto-pause duration outside 5 minutes to 24 hours, and serverlessV2MinCapacity: 0 on an engineVersion below 16.3.

Writer Configuration

AuroraWriterConfig accepts enableDatabaseInsights, identifierSuffix, and availabilityZone.

Reader Configuration

Set count for identical readers or instances for per-reader configuration. The two are mutually exclusive. The first reader scales with the writer. Pass false for a cluster with no readers.

Proxy Configuration

ProxyConfig fields: requireTLS (default true), connectionBorrowTimeout in seconds (default 120), maxConnections and maxIdleConnections as percentages of the cluster maximum, and vpcSubnets (default private with egress).

Backup and Maintenance

RemovalPolicy.SNAPSHOT takes a final snapshot on delete. DESTROY is for disposable-data clusters only: the delete takes the data with it, with no snapshot and no recovery. Tags are copied to every automated and manual snapshot.

Security

IAM database authentication is enabled on every cluster.

Snapshot Restore

Database Insights

DatabaseInsightsConfig accepts mode ("standard" or "advanced", default "standard") and encryptionKey.

Alarms

Alarms are created only when alertsTopic is supplied.

Default Architecture

Passing nothing but vpc and databaseName creates:
  • 1 writer instance (Serverless v2)
  • 1 reader instance (Serverless v2, scaling with the writer)
  • Storage encryption with the AWS-managed KMS key aws/rds
  • Database Insights in standard mode
  • 14-day automated backups, tags copied to snapshots
  • Deletion protection on, removal policy SNAPSHOT
  • IAM database authentication
RDS Proxy is not created by default. Pass a proxy configuration to enable it. Secret rotation is not enabled by default. Opt in with credentials: { secretRotation: {} } for the 30-day default, or { automaticallyAfterDays: 7 } to shorten it.
Rotation uses the multi-user strategy, which needs a one-time manual step after deploy: populate the generated <construct-id>/master-secret with valid superuser credentials as JSON. Until you do, every rotation attempt fails and the database password stays unchanged. Synth emits a warning to the same effect whenever rotation is enabled.

Encryption

Storage encryption is always on. By default the cluster uses the AWS-managed KMS key aws/rds, which you cannot rotate, scope, or revoke yourself. Pass the USE_CMK marker to create a Fjall-managed customer-managed key instead.
You can also pass an existing IKey in place of USE_CMK.
Changing encryption.storageKey after creation replaces the cluster. Decide before the first deploy.
The storage key is created with protects: "outlives-stack", because the SNAPSHOT removal policy leaves a final snapshot behind and destroying its key would make that snapshot permanently unrestorable.

Network Security

The cluster is placed in private subnets with egress. Its security group starts closed, so grant access explicitly.
Set allowVpcAccess: true to open the database port to the entire VPC CIDR, which avoids cross-stack cyclic dependencies with Lambda.
publiclyAccessible: true moves the cluster into public subnets. Pair it with a narrow allowedIpCidr such as "203.0.113.4/32". Setting allowedIpCidr: "0.0.0.0/0" opens the database port to the entire internet and synth warns about it.

Reader Configuration

Default (1 reader)

Multiple readers

Per-reader configuration

No readers

Scale to Zero

Set serverlessV2MinCapacity: 0 with an auto-pause duration to let an idle cluster pause and bill nothing for compute. This needs Aurora PostgreSQL 16.3 or later, and you must pass engineVersion so synth can check the floor.
A live pooled connection pins the cluster above 0 ACU, so pair auto-pause with enableDataApi: true when the workload can run DDL over HTTPS instead of holding a VPC connection.

RDS Proxy

Enable RDS Proxy for connection pooling, faster failover, and fewer database connections.
maxConnections and maxIdleConnections are percentages of the cluster’s connection limit, not absolute counts. Enabling the proxy repoints database.connections at the proxy security group, so existing allowDefaultPortFrom grants keep working. Without a proxy, getHostEndpoint() returns the cluster writer endpoint.

Restoring from Snapshot

Create a new Aurora cluster from an existing cluster snapshot.
Key constraints when restoring from a snapshot:
  • The master username is immutable and baked into the snapshot. snapshotUsername must match the original cluster’s username exactly. Omit it and synth warns that it assumed a username.
  • The engine version is inherited from the snapshot. A mismatch between the snapshot’s engine version and the infrastructure code causes a CloudFormation failure.
  • The master password is reset shortly after the restore. Fjall generates a new credentials secret for the restored cluster, and CloudFormation applies its password once the cluster becomes available (the cluster briefly reports resetting-master-credentials). The snapshot-era password stops working at that point, so applications must read credentials from the generated secret.
This password reset applies only to restores performed through infrastructure code (snapshotIdentifier). Restores performed through AWS Backup (fjall restore rds) run outside CloudFormation and keep the snapshot-era password. See fjall restore.

Backup and Recovery

Custom backup retention

Point-in-time recovery

Aurora supports PITR for any point within the backup retention window:
  • Continuous backup to S3
  • Restore to any second within the retention window
  • Cross-region backup replication available

Monitoring

Enhanced monitoring

Database Insights

Enabled on every instance by default in standard mode. It reports:
  • SQL-level performance metrics
  • Top SQL statements
  • Database load by wait event
Pass databaseInsights: { mode: "advanced" } for longer retention, or databaseInsights: false to turn it off.

Methods

database.connections is a public Connections property, not a method. Use it for security-group grants.

Complete Example

Cost Optimisation

Serverless v2 bills per ACU-second, so cost tracks the capacity floor you set rather than an instance size. Figures are us-east-1 list price for compute only. Storage, I/O, backups beyond the free allowance, and RDS Proxy are billed separately, and prices vary by region. Three levers matter most:
  1. Set serverlessV2MinCapacity deliberately. The floor is what you pay when idle.
  2. Use auto-pause for development and preview clusters.
  3. Drop readers you do not query, using readers: false or a lower count.

Best Practices

  1. Enable RDS Proxy when the application opens many short-lived connections.
  2. Grant access with allowDefaultPortFrom rather than a hardcoded port.
  3. Pass encryption: { storageKey: USE_CMK } when you need a key you can rotate and revoke.
  4. Match backupRetention to your recovery objective (default 14 days).
  5. Route analytics and reporting queries at readers.
  6. Watch ACU usage and tune the capacity floor.
  7. Keep deletionProtection and the SNAPSHOT removal policy on for production.

Limitations

  • The capacity floor is 0.5 ACU unless auto-pause is enabled (serverlessV2MinCapacity: 0), which requires Aurora PostgreSQL 16.3 or later.
  • Auto-pause duration must be between 5 minutes and 24 hours.
  • RDS Proxy accepts client connections only on the engine default port. AWS does not allow configuring the proxy listener port.
  • The engine is pinned to Aurora PostgreSQL 18.4. Major version upgrades need planning.
  • Cross-region replicas need a Global Database. See RdsAuroraGlobal.
  • Changing the storage encryption key after creation replaces the cluster.

Next Steps

RDS Instance

Deploy a single-instance PostgreSQL or MySQL database when you do not need Serverless v2 scaling.

Database Factory

Provision Aurora, RDS Instance, DynamoDB, or ClickHouse from one declarative factory.

Security Group

Control which services and CIDRs can reach the cluster on port 5432.

KMS Key

Create and scope the customer-managed key that encrypts cluster storage.

Secrets Manager

Read the generated database credentials and configure rotation.

fjall restore

Restore an Aurora cluster from an AWS Backup recovery point.