Postgres
Reference doc for the `sst.aws.Postgres` component.
The Postgres
component lets you add a Postgres database to your app using
Amazon Aurora Serverless v2.
To connect to your database from your Lambda functions, you can use the AWS Data API. It does not need a persistent connection, and works over HTTP. You also don’t need a VPN to connect to it locally.
Create the database
Use a VPC
Change the scaling config
Link to a resource
You can link your database to other resources, like a function or your Next.js app.
Once linked, you can connect to it from your function code.
Constructor
Parameters
-
name
string
-
args?
PostgresArgs
-
opts?
ComponentResourceOptions
PostgresArgs
databaseName?
Type Input
<
string
>
Default Based on the name of the current app
Name of a database that is automatically created inside the cluster.
The name must begin with a letter and contain only lowercase letters, numbers, or underscores. By default, it takes the name of the app, and replaces the hyphens with underscores.
scaling?
Type Input
<
Object
>
Default {min: “0.5 ACU”, max: “4 ACU”}
The Aurora Serverless v2 scaling config. By default, the cluster has one DB instance that is used for both writes and reads. The instance can scale from the minimum number of ACUs to the maximum number of ACUs.
An ACU or Aurora Capacity Unit is a combination of CPU and RAM. The cost of an Aurora Serverless v2 cluster is based on the ACU hours used. Additionally, you are billed for I/O and storage used by the cluster. Read more here.
Each ACU is roughly equivalent to 2 GB of memory. So pick the minimum and maximum based on the baseline and peak memory usage of your app.
scaling.max?
Type Input
<
“
${number} ACU
”
>
Default 4 ACU
The maximum number of ACUs, ranges from 0.5 to 128, in increments of 0.5.
scaling.min?
Type Input
<
“
${number} ACU
”
>
Default 0.5 ACU
The minimum number of ACUs, ranges from 0.5 to 128, in increments of 0.5.
For your production workloads, setting a minimum of 0.5 ACUs might not be a great idea due to the following reasons, you can also read more here.
- It takes longer to scale from a low number of ACUs to a much higher number.
- Query performance depends on the buffer cache. So if frequently accessed data cannot fit into the buffer cache, you might see uneven performance.
- The max connections for a 0.5 ACU Postgres instance is capped at 2000.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.cluster?
Type ClusterArgs
|
(
args
:
ClusterArgs
=>
void
)
Transform the RDS Cluster.
transform.instance?
Type ClusterInstanceArgs
|
(
args
:
ClusterInstanceArgs
=>
void
)
Transform the database instance in the RDS Cluster.
transform.subnetGroup?
Type SubnetGroupArgs
|
(
args
:
SubnetGroupArgs
=>
void
)
Transform the RDS subnet group.
version?
Type Input
<
string
>
Default “15.5”
The Postgres engine version. Check out the available versions in your region.
vpc?
Type Input
<
Object
>
Default The default VPC in your account.
The VPC to use for the database cluster.
By default, your account has a VPC in each account. This comes with a public subnet. If you don’t specify a VPC, it’ll use the default one. This is not recommended for production.
Or create a Vpc
component.
And pass it in.
vpc.privateSubnets
Type Input
<
Input
<
string
>
[]
>
A list of private subnet IDs in the VPC. The database will be placed in the private subnets.
vpc.securityGroups
Type Input
<
Input
<
string
>
[]
>
A list of VPC security group IDs.
Properties
clusterArn
Type Output
<
string
>
The ARN of the RDS Cluster.
database
Type Output
<
string
>
The name of the database.
nodes
nodes.cluster
Type Cluster
nodes.instance
Type ClusterInstance
secretArn
Type Output
<
string
>
The ARN of the master user secret.
SDK
The following are accessible through the SDK at runtime.
clusterArn
Type string
The ARN of the RDS Cluster.
database
Type string
The name of the database.
secretArn
Type string
The ARN of the master user secret.