Dsql
The Dsql component lets you add an Amazon Aurora DSQL cluster to your app.
Single-region cluster
const cluster = new sst.aws.Dsql("MyCluster");Once linked, you can connect to it from your function code.
import { Resource } from "sst";import { AuroraDSQLClient } from "@aws/aurora-dsql-node-postgres-connector";
const client = new AuroraDSQLClient({ host: Resource.MyCluster.endpoint, user: "admin",});
await client.connect();const result = await client.query("SELECT NOW() as now");await client.end();Multi-region cluster
const cluster = new sst.aws.Dsql("MyCluster", { regions: { witness: "us-west-2", peer: "us-east-2" }});With private VPC endpoints
const vpc = new sst.aws.Vpc("MyVpc");
const cluster = new sst.aws.Dsql("MyCluster", { vpc: { instance: vpc, endpoints: { connection: true } }});Link to a function
new sst.aws.Function("MyFunction", { handler: "src/lambda.handler", link: [cluster]});You can also use Drizzle ORM to query your DSQL cluster. Check out the Drizzle example.
Cost
Aurora DSQL is serverless and uses a pay-per-use pricing model. You are charged for database activity measured in Distributed Processing Units (DPUs) at $8 per million DPUs, and storage at $0.33 per GB-month. When idle, usage scales to zero and you incur no DPU charges.
There is a free tier of 100,000 DPUs and 1 GB of storage per month.
For example, a single-region cluster averaging 1.3M DPUs per month with 15 GB of storage costs roughly 1.3 x $8 + 15 x $0.33 or $15 per month.
Check out the Aurora DSQL pricing for more details.
Constructor
new Dsql(name, args?, opts?)Parameters
-
namestring -
args?DsqlArgs -
opts?ComponentResourceOptions
DsqlArgs
regions?
Type Object
Configure multi-region cluster peering.
Creates a cluster in the current region and a peer cluster in another region, linked via a witness region. The witness must differ from both cluster regions.
Learn more about AWS DSQL regions.
const cluster = new sst.aws.Dsql("MyCluster", { regions: { witness: "us-west-2", peer: "us-east-2" }});regions.peer
Type Input<string>
The AWS region for the peer cluster.
regions.witness
Type Input<string>
The witness region. Must differ from both cluster regions.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.cluster?
Type ClusterArgs | (args: ClusterArgs, opts: ComponentResourceOptions, name: string) => void
Transform the DSQL cluster resource.
transform.connectionEndpoint?
Type VpcEndpointArgs | (args: VpcEndpointArgs, opts: ComponentResourceOptions, name: string) => void
Transform the EC2 VPC endpoint resource for DSQL connections.
transform.endpointSecurityGroup?
Type SecurityGroupArgs | (args: SecurityGroupArgs, opts: ComponentResourceOptions, name: string) => void
Transform the EC2 security group resource for the DSQL VPC endpoints.
transform.managementEndpoint?
Type VpcEndpointArgs | (args: VpcEndpointArgs, opts: ComponentResourceOptions, name: string) => void
Transform the EC2 VPC endpoint resource for DSQL management operations.
transform.peerCluster?
Type ClusterArgs | (args: ClusterArgs, opts: ComponentResourceOptions, name: string) => void
Transform the peer DSQL cluster resource.
vpc?
Type Vpc | Object
-
endpoints?Object
Create AWS PrivateLink interface endpoints in a VPC for private connectivity. This allows lambdas placed inside a VPC without NAT gateways to connect to the DSQL instance.
const myVpc = new sst.aws.Vpc("MyVpc");
const cluster = new sst.aws.Dsql("MyCluster", { vpc: myVpc});Customize VPC endpoints
const myVpc = new sst.aws.Vpc("MyVpc");
const cluster = new sst.aws.Dsql("MyCluster", { vpc: { instance: vpc, endpoints: { management: true, connection: true, } }});vpc.endpoints?
Type Object
vpc.endpoints.connection?
Type boolean
Default true
Endpoint for PostgreSQL client connections.
vpc.endpoints.management?
Type boolean
Default false
Endpoint for control plane ops (create, get, update, delete clusters).
vpc.instance
Type Vpc
Properties
endpoint
Type Output<string>
The endpoint of the cluster.
nodes
Type Object
The underlying resources this component creates.
nodes.cluster
Type Cluster
The DSQL cluster.
nodes.peerCluster
Type undefined | Cluster
The peer DSQL cluster (multi-region only).
peer
peer.endpoint
Type Output<string>
The endpoint of the peer cluster.
peer.region
Type Output<string>
The region of the peer cluster.
region
Type Output<string>
The region of the cluster.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource object in the SDK.
-
endpointstringThe endpoint of the cluster.
-
peerundefined|ObjectThe peer cluster info. Only available for multi-region clusters.
-
regionstringThe region of the cluster.
Methods
static get
Dsql.get(name, args, opts?)Parameters
-
namestring -
argsObject -
opts?ComponentResourceOptions
Returns Dsql
Reference an existing DSQL cluster by identifier. Useful for sharing a cluster across stages without creating a new one.
Single-region cluster
const cluster = $app.stage === "frank" ? sst.aws.Dsql.get("MyCluster", { id: "kzttrvbdg4k2o5ze2m2rrwdj7u" }) : new sst.aws.Dsql("MyCluster");Multi-region cluster
const cluster = sst.aws.Dsql.get("MyCluster", { id: "app-dev-mycluster", peer: { id: "kzttrvbdg4k2o5ze2m2rrwdj7u", region: "us-east-2", }});