Postgres
Reference doc for the `sst.aws.Postgres` component.
The Postgres
component lets you add a Postgres database to your app using
Amazon RDS Postgres.
Create the database
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.
Cost
By default this component uses a Single-AZ Deployment, On-Demand DB Instances of a
db.t4g.micro
at $0.016 per hour. And 20GB of General Purpose gp3 Storage
at $0.115 per GB per month.
That works out to $0.016 x 24 x 30 + $0.115 x 20 or $14 per month. Adjust this for the
instance
type and the storage
you are using.
The above are rough estimates for us-east-1, check out the RDS for PostgreSQL pricing for more details.
RDS Proxy
If you enable the proxy
, it uses Provisioned instances with 2 vCPUs at $0.015 per hour.
That works out to an additional $0.015 x 2 x 24 x 30 or $22 per month.
The above are rough estimates for us-east-1, check out the RDS Proxy pricing for more details.
Constructor
Parameters
-
name
string
-
args
PostgresArgs
-
opts?
ComponentResourceOptions
PostgresArgs
database?
Type Input
<
string
>
Default Based on the name of the current app
Name of a database that is automatically created.
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.
instance?
Type Input
<
string
>
Default “t4g.micro”
The type of instance to use for the database. Check out the supported instance types.
password?
Type Input
<
string
>
Default A random password is generated.
The password of the master user.
proxy?
storage?
Type Input
<
“
${number} GB
”
|
“
${number} TB
”
>
Default “20 GB”
The amount of storage to use for the database.
By default, gp3 storage volumes are used without additional provisioned IOPS. This provides a good baseline performance for most use cases.
The minimum storage size is 20 GB. And the maximum storage size is 64 TB.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.instance?
Type InstanceArgs
|
(
args
:
InstanceArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the database instance in the RDS Cluster.
transform.parameterGroup?
Type ParameterGroupArgs
|
(
args
:
ParameterGroupArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the RDS parameter group.
transform.subnetGroup?
Type SubnetGroupArgs
|
(
args
:
SubnetGroupArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the RDS subnet group.
username?
Type Input
<
string
>
Default “postgres”
The username of the master user.
version?
Type Input
<
string
>
Default “16.4”
The Postgres engine version. Check out the available versions in your region.
vpc
Type Input
<
Vpc
|
Object
>
The VPC subnets to use for the database.
Or create a Vpc
component.
And pass it in. The database will be placed in the private subnets.
vpc.subnets
Type Input
<
Input
<
string
>
[]
>
A list of subnet IDs in the VPC.
Properties
database
Type Output
<
string
>
The name of the database.
host
Type Output
<
string
>
The host of the database.
id
Type Output
<
string
>
The identifier of the Postgres instance.
nodes
Type Object
nodes.instance
Type Instance
password
Type Output
<
string
>
The password of the master user.
port
Type Output
<
number
>
The port of the database.
proxyId
Type Output
<
string
>
The name of the Postgres proxy.
username
Type Output
<
string
>
The username of the master user.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
database
string
The name of the database.
-
host
string
The host of the database.
-
password
string
The password of the master user.
-
port
number
The port of the database.
-
username
string
The username of the master user.
Methods
static get
Parameters
The name of the component.name
string
The arguments to get the Postgres database.args
PostgresGetArgs
-
opts?
ComponentResourceOptions
Returns Output
<
Postgres
>
Reference an existing Postgres database with the given name. This is useful when you create a Postgres database in one stage and want to share it in another. It avoids having to create a new Postgres database in the other stage.
Imagine you create a database in the dev
stage. And in your personal stage frank
,
instead of creating a new database, you want to share the same database from dev
.
Here app-dev-mydatabase
is the ID of the database, and app-dev-mydatabase-proxy
is the ID of the proxy created in the dev
stage. You can find these by outputting
the database ID and proxy ID in the dev
stage.
PostgresGetArgs
id
Type Input
<
string
>
The ID of the database.
proxyId?
Type Input
<
string
>
The ID of the proxy.