Skip to content
GitHub Discord

AWS Aurora DSQL Multi-Region

In this example, we deploy a multi-region Aurora DSQL cluster and connect to both clusters from a Lambda function.

Create the cluster with a witness region and a peer region. The witness must differ from both cluster regions.

sst.config.ts
const cluster = new sst.aws.Dsql("MultiRegion", {
regions: {
witness: "us-west-2",
peer: "us-east-2",
},
});

Connect to both clusters from your function using the DSQL connector. Learn more about DSQL Node.js connectors.

lambda.ts
import { AuroraDSQLClient } from "@aws/aurora-dsql-node-postgres-connector";
import { Resource } from "sst";
async function connectToCluster(endpoint: string) {
const client = new AuroraDSQLClient({ host: endpoint, user: "admin" });
await client.connect();
return client;
}
// Cluster in us-east-1
const usEast1 = await connectToCluster(Resource.MultiRegion.endpoint);
// Cluster in us-east-2
const usEast2 = await connectToCluster(Resource.MultiRegion.peer.endpoint);
sst.config.ts
const cluster = new sst.aws.Dsql("MultiRegion", {
backup: true,
regions: {
witness: "us-west-2",
peer: "us-east-2",
},
});
const fn = new sst.aws.Function("MyFunction", {
handler: "lambda.handler",
link: [cluster],
url: true,
});

View the full example.