Skip to content

feat(aws/rds): declare a read replica of an existing DBInstance - #3783

Open
cdriki wants to merge 1 commit into
alchemy-run:mainfrom
cdriki:feat/aws-rds-read-replica
Open

cdriki wants to merge 1 commit into
alchemy-run:mainfrom
cdriki:feat/aws-rds-read-replica

Conversation

@cdriki

@cdriki cdriki commented Nov 25, 2026 •

Copy link
Copy Markdown

AWS.RDS.DBInstance takes a sourceDBInstanceIdentifier, so a stack can add a read replica of a standalone instance it already runs, without moving the writer to Aurora.

const db = yield* AWS.RDS.DBInstance("Db", {
  engine: "postgres",
  dbInstanceClass: "db.t4g.medium",
  masterUsername: "app",
  masterUserPassword: password,
  backupRetentionPeriod: "7 days",
  dbSubnetGroupName: subnetGroup.dbSubnetGroupName,
});

const reader = yield* AWS.RDS.DBInstance("Reader", {
  sourceDBInstanceIdentifier: db.dbInstanceIdentifier,
  engine: "postgres",
  dbInstanceClass: "db.t4g.medium",
  vpcSecurityGroupIds: [readers.groupId],
});
  • Create calls CreateDBInstanceReadReplica. Settings it has no field for, such as backups and maintenance windows, go through the existing ModifyDBInstance sync. The source is never written to.
  • Changing the source replaces the replica. Removing it fails at plan time with InvalidDBInstanceReadReplica, instead of replacing the replica with an empty database.
  • Props a replica inherits or can't use (dbName, masterUsername, masterUserPassword, storageEncrypted, kmsKeyId, migrations, …) fail at plan time.
  • Before the create call, the source must exist, run the same engine, keep automated backups, and not manage its master password in Secrets Manager, which AWS doesn't support for replicas outside SQL Server and Db2.
  • An instance already under the replica's identifier, e.g. after a deploy died mid-create, is kept only if it replicates the declared source.
  • Delete skips the final snapshot, which RDS refuses for a replica.
  • New attribute readReplicaSourceDBInstanceIdentifier.

Same-region only for now. Cross-region replicas also need SourceRegion and a KMS key, and the prop name leaves room for them. Instances without sourceDBInstanceIdentifier behave as before.

Closes #3784

@cdriki
cdriki force-pushed the feat/aws-rds-read-replica branch from 70ff8f6 to 590d972 Compare November 25, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@alchemy.run/aws: declare an RDS read replica of an existing DB instance

1 participant