Stacktape
Stacktape


Relational (SQL) Databases



Stacktape allows you to deploy a fully managed relational (SQL) database, with support for PostgreSQL, MySQL, MariaDB, Oracle, and SQL Server. The service handles capacity scaling, hardware provisioning, database setup, patching, logging, and backups, so you can focus on your application.

Under the hood, Stacktape uses Amazon RDS. It supports three engine categories with different topologies and scaling behaviors:

  • Basic RDS engines: A single-node database that is the most cost-effective option. It supports optional read replicas for higher performance and a Multi-AZ standby instance for resilience.
  • Aurora engine: A multi-node, highly available cluster with increased durability and fault tolerance. It automatically balances read requests across nodes for better performance.
  • Aurora Serverless engine: Similar to the Aurora engine, but with automatic, usage-based scaling. It can scale down to zero when inactive, saving costs.

Databases are always deployed in a private network within your stack's VPC. You can configure accessibility to control whether the database is accessible from the internet or only from other resources in the VPC.

Basic usage

To connect to a relational database, you typically use a connection string. Stacktape can automatically inject the necessary credentials and connection details into your application's environment when you use the connectTo property.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('database.password')
engine:
type: postgres
properties:
version: '16.2'
primaryInstance:
instanceSize: db.t3.micro
apiServer:
type: multi-container-workload
properties:
resources:
cpu: 1
memory: 1024
containers:
- name: api-container
packaging:
type: stacktape-image-buildpack
properties:
entryfilePath: src/main.ts
connectTo:
- myDatabase

A single-node PostgreSQL database.

import express from 'express';
import { Pool } from 'pg';
const pgPool = new Pool({
connectionString: process.env.STP_MY_DATABASE_CONNECTION_STRING // env variable was automatically injected by Stacktape
});
const app = express();
app.get('/time', async (req, res) => {
const result = await pgPool.query('SELECT NOW()');
const time = result.rows[0];
res.send(time);
});
app.listen(3000, () => {
console.info('Server running on port 3000');
});

A container workload connecting to the database.

Database credentials

You can configure the credentials for the database's master user. It's recommended to use a secret to manage these credentials securely.

resources:
myRelationalDatabase:
type: relational-database
properties:
credentials:
masterUserName: $File('.env').DB_USER_NAME # OPTIONAL
masterUserPassword: $Secret('dbCredentials.password')
engine:
type: postgres
properties:
version: '16.2'
port: 5432
primaryInstance:
instanceSize: db.t2.micro
RelationalDatabaseCredentials  API reference
masterUserPassword
Required
masterUserName
Default: db_master_user

Engine

The database engine determines the database type, performance, availability, and pricing.

Depending on the properties they provide, we group engine types into following groups:

  • RDS Engine group - single node fully managed databases.
    • Supported engines:
      • postgres
      • mysql
      • mariadb
      • oracle-ee
      • oracle-se2
      • sqlserver-ee
      • sqlserver-ex
      • sqlserver-se
      • sqlserver-web
  • Aurora Engine group - multi node highly available cluster with replicated storage.
    • Supported engines:
      • aurora-postgresql
      • aurora-mysql
  • Aurora Serverless V2 Engine - serverless engine with replicated storage. Compute resources scale based on actual demand.
    • Supported engines:
      • aurora-postgresql-serverless-v2
      • aurora-mysql-serverless-v2

Engine version

You must choose a version that is compatible with your chosen engine.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: postgres
properties:
version: '16.2'
port: 5432
primaryInstance:
instanceSize: db.t3.micro

Available versions

aurora-mysql

8.0.mysql_aurora.3.11.0

8.0.mysql_aurora.3.10.2

8.0.mysql_aurora.3.10.1

8.0.mysql_aurora.3.10.0

8.0.mysql_aurora.3.09.0

8.0.mysql_aurora.3.08.2

8.0.mysql_aurora.3.08.1

8.0.mysql_aurora.3.08.0

8.0.mysql_aurora.3.04.4

8.0.mysql_aurora.3.04.3

8.0.mysql_aurora.3.04.2

8.0.mysql_aurora.3.04.1

8.0.mysql_aurora.3.04.0

5.7.mysql_aurora.2.12.5

5.7.mysql_aurora.2.12.4

5.7.mysql_aurora.2.12.3

5.7.mysql_aurora.2.12.2

5.7.mysql_aurora.2.12.1

5.7.mysql_aurora.2.12.0

5.7.mysql_aurora.2.11.6

5.7.mysql_aurora.2.11.5

5.7.mysql_aurora.2.11.4

5.7.mysql_aurora.2.11.3

5.7.mysql_aurora.2.11.2

5.7.mysql_aurora.2.11.1

aurora-mysql-serverless-v2

8.0.mysql_aurora.3.11.0

8.0.mysql_aurora.3.10.2

8.0.mysql_aurora.3.10.1

8.0.mysql_aurora.3.10.0

8.0.mysql_aurora.3.09.0

8.0.mysql_aurora.3.08.2

8.0.mysql_aurora.3.08.1

8.0.mysql_aurora.3.08.0

aurora-postgresql

17.6

17.5

17.4

16.10

16.9-limitless

16.9

16.8-limitless

16.8

16.6-limitless

16.6

16.4-limitless

16.4

16.3

16.2

16.1

15.14

15.13

15.12

15.10

15.8

15.7

15.6

14.19

14.18

14.17

14.15

14.13

14.12

14.11

14.6

13.22

13.21

13.20

13.18

13.16

13.15

13.14

13.9

12.22

12.9

11.21

11.9

aurora-postgresql-serverless-v2

17.6

17.5

16.10

16.9-limitless

16.9

16.8-limitless

16.8

16.6-limitless

16.6

16.4-limitless

16.4

16.3

15.14

15.13

15.12

15.10

15.8

15.7

14.19

14.18

14.17

14.15

14.13

14.12

13.22

13.21

13.20

13.18

13.16

13.15

mariadb

11.8.5

11.8.3

11.4.9

11.4.8

11.4.7

11.4.5

11.4.4

11.4.3

10.11.15

10.11.14

10.11.13

10.11.11

10.11.10

10.11.9

10.11.8

10.6.24

10.6.23

10.6.22

10.6.21

10.6.20

10.6.19

10.6.18

10.5.29

10.5.28

10.5.27

10.5.26

10.5.25

mysql

8.4.7

8.4.6

8.4.5

8.4.4

8.4.3

8.0.44

8.0.43

8.0.42

8.0.41

8.0.40

8.0.39

8.0.37

5.7.44-rds.20250818

5.7.44-rds.20250508

5.7.44-rds.20250213

5.7.44-rds.20250103

5.7.44-rds.20240808

5.7.44-rds.20240529

5.7.44-rds.20240408

oracle-ee

19.0.0.0.ru-2025-10.spb-1.r1

19.0.0.0.ru-2025-10.rur-2025-10.r1

19.0.0.0.ru-2025-07.spb-1.r1

19.0.0.0.ru-2025-07.rur-2025-07.r1

19.0.0.0.ru-2025-04.spb-1.r1

19.0.0.0.ru-2025-04.rur-2025-04.r1

19.0.0.0.ru-2025-01.rur-2025-01.r2

19.0.0.0.ru-2025-01.spb-1.r1

19.0.0.0.ru-2025-01.rur-2025-01.r1

19.0.0.0.ru-2024-10.rur-2024-10.r1

19.0.0.0.ru-2024-07.rur-2024-07.r1

19.0.0.0.ru-2024-04.rur-2024-04.r1

19.0.0.0.ru-2024-01.rur-2024-01.r1

19.0.0.0.ru-2023-10.rur-2023-10.r1

19.0.0.0.ru-2023-07.rur-2023-07.r1

19.0.0.0.ru-2023-04.rur-2023-04.r1

19.0.0.0.ru-2023-01.rur-2023-01.r2

19.0.0.0.ru-2023-01.rur-2023-01.r1

19.0.0.0.ru-2022-10.rur-2022-10.r1

19.0.0.0.ru-2022-07.rur-2022-07.r1

19.0.0.0.ru-2022-04.rur-2022-04.r1

19.0.0.0.ru-2022-01.rur-2022-01.r1

19.0.0.0.ru-2021-10.rur-2021-10.r1

19.0.0.0.ru-2021-07.rur-2021-07.r1

19.0.0.0.ru-2021-04.rur-2021-04.r1

19.0.0.0.ru-2021-01.rur-2021-01.r2

19.0.0.0.ru-2021-01.rur-2021-01.r1

19.0.0.0.ru-2020-10.rur-2020-10.r1

19.0.0.0.ru-2020-07.rur-2020-07.r1

19.0.0.0.ru-2020-04.rur-2020-04.r1

oracle-se2

19.0.0.0.ru-2025-10.spb-1.r1

19.0.0.0.ru-2025-10.rur-2025-10.r1

19.0.0.0.ru-2025-07.spb-1.r1

19.0.0.0.ru-2025-07.rur-2025-07.r1

19.0.0.0.ru-2025-04.spb-1.r1

19.0.0.0.ru-2025-04.rur-2025-04.r1

19.0.0.0.ru-2025-01.rur-2025-01.r2

19.0.0.0.ru-2025-01.spb-1.r1

19.0.0.0.ru-2025-01.rur-2025-01.r1

19.0.0.0.ru-2024-10.rur-2024-10.r1

19.0.0.0.ru-2024-07.rur-2024-07.r1

19.0.0.0.ru-2024-04.rur-2024-04.r1

19.0.0.0.ru-2024-01.rur-2024-01.r1

19.0.0.0.ru-2023-10.rur-2023-10.r1

19.0.0.0.ru-2023-07.rur-2023-07.r1

19.0.0.0.ru-2023-04.rur-2023-04.r1

19.0.0.0.ru-2023-01.rur-2023-01.r2

19.0.0.0.ru-2023-01.rur-2023-01.r1

19.0.0.0.ru-2022-10.rur-2022-10.r1

19.0.0.0.ru-2022-07.rur-2022-07.r1

19.0.0.0.ru-2022-04.rur-2022-04.r1

19.0.0.0.ru-2022-01.rur-2022-01.r1

19.0.0.0.ru-2021-10.rur-2021-10.r1

19.0.0.0.ru-2021-07.rur-2021-07.r1

19.0.0.0.ru-2021-04.rur-2021-04.r1

19.0.0.0.ru-2021-01.rur-2021-01.r2

19.0.0.0.ru-2021-01.rur-2021-01.r1

19.0.0.0.ru-2020-10.rur-2020-10.r1

19.0.0.0.ru-2020-07.rur-2020-07.r1

19.0.0.0.ru-2020-04.rur-2020-04.r1

postgres

18.1

17.7

17.6

17.5

17.4

17.2

16.11

16.10

16.9

16.8

16.6

15.15

15.14

15.13

15.12

15.10

14.20

14.19

14.18

14.17

14.15

13.23

13.22

13.21

13.20

13.18

12.22-rds.20250814

12.22-rds.20250508

12.22-rds.20250220

12.22

11.22-rds.20250814

11.22-rds.20250508

11.22-rds.20250220

11.22-rds.20241121

sqlserver-ee

16.00.4215.2.v1

16.00.4210.1.v1

16.00.4205.1.v1

16.00.4195.2.v1

16.00.4185.3.v1

16.00.4175.1.v1

16.00.4165.4.v1

16.00.4150.1.v1

16.00.4140.3.v1

16.00.4135.4.v1

16.00.4131.2.v1

16.00.4125.3.v1

16.00.4120.1.v1

16.00.4115.5.v1

16.00.4105.2.v1

16.00.4095.4.v1

16.00.4085.2.v1

15.00.4445.1.v1

15.00.4440.1.v1

15.00.4435.7.v1

15.00.4430.1.v1

15.00.4420.2.v1

15.00.4415.2.v1

15.00.4410.1.v1

15.00.4395.2.v1

15.00.4390.2.v1

15.00.4385.2.v1

15.00.4382.1.v1

15.00.4375.4.v1

15.00.4365.2.v1

15.00.4355.3.v1

15.00.4345.5.v1

15.00.4335.1.v1

15.00.4322.2.v1

15.00.4316.3.v1

15.00.4312.2.v1

15.00.4236.7.v1

15.00.4198.2.v1

15.00.4153.1.v1

15.00.4073.23.v1

15.00.4043.16.v1

14.00.3505.1.v1

14.00.3500.1.v1

14.00.3495.9.v1

14.00.3485.1.v1

14.00.3480.1.v1

14.00.3475.1.v1

14.00.3471.2.v1

14.00.3465.1.v1

14.00.3460.9.v1

14.00.3451.2.v1

14.00.3421.10.v1

14.00.3401.7.v1

14.00.3381.3.v1

14.00.3356.20.v1

14.00.3294.2.v1

14.00.3281.6.v1

13.00.6470.1.v1

13.00.6465.1.v1

13.00.6460.7.v1

13.00.6455.2.v1

13.00.6450.1.v1

13.00.6445.1.v1

13.00.6441.1.v1

13.00.6435.1.v1

13.00.6430.49.v1

13.00.6419.1.v1

13.00.6300.2.v1

sqlserver-ex

16.00.4215.2.v1

16.00.4210.1.v1

16.00.4205.1.v1

16.00.4195.2.v1

16.00.4185.3.v1

16.00.4175.1.v1

16.00.4165.4.v1

16.00.4150.1.v1

16.00.4140.3.v1

16.00.4135.4.v1

16.00.4131.2.v1

16.00.4125.3.v1

16.00.4120.1.v1

16.00.4115.5.v1

16.00.4105.2.v1

16.00.4095.4.v1

16.00.4085.2.v1

15.00.4445.1.v1

15.00.4440.1.v1

15.00.4435.7.v1

15.00.4430.1.v1

15.00.4420.2.v1

15.00.4415.2.v1

15.00.4410.1.v1

15.00.4395.2.v1

15.00.4390.2.v1

15.00.4385.2.v1

15.00.4382.1.v1

15.00.4375.4.v1

15.00.4365.2.v1

15.00.4355.3.v1

15.00.4345.5.v1

15.00.4335.1.v1

15.00.4322.2.v1

15.00.4316.3.v1

15.00.4312.2.v1

15.00.4236.7.v1

15.00.4198.2.v1

15.00.4153.1.v1

15.00.4073.23.v1

15.00.4043.16.v1

14.00.3505.1.v1

14.00.3500.1.v1

14.00.3495.9.v1

14.00.3485.1.v1

14.00.3480.1.v1

14.00.3475.1.v1

14.00.3471.2.v1

14.00.3465.1.v1

14.00.3460.9.v1

14.00.3451.2.v1

14.00.3421.10.v1

14.00.3401.7.v1

14.00.3381.3.v1

14.00.3356.20.v1

14.00.3294.2.v1

14.00.3281.6.v1

13.00.6470.1.v1

13.00.6465.1.v1

13.00.6460.7.v1

13.00.6455.2.v1

13.00.6450.1.v1

13.00.6445.1.v1

13.00.6441.1.v1

13.00.6435.1.v1

13.00.6430.49.v1

13.00.6419.1.v1

13.00.6300.2.v1

sqlserver-se

16.00.4215.2.v1

16.00.4210.1.v1

16.00.4205.1.v1

16.00.4195.2.v1

16.00.4185.3.v1

16.00.4175.1.v1

16.00.4165.4.v1

16.00.4150.1.v1

16.00.4140.3.v1

16.00.4135.4.v1

16.00.4131.2.v1

16.00.4125.3.v1

16.00.4120.1.v1

16.00.4115.5.v1

16.00.4105.2.v1

16.00.4095.4.v1

16.00.4085.2.v1

15.00.4445.1.v1

15.00.4440.1.v1

15.00.4435.7.v1

15.00.4430.1.v1

15.00.4420.2.v1

15.00.4415.2.v1

15.00.4410.1.v1

15.00.4395.2.v1

15.00.4390.2.v1

15.00.4385.2.v1

15.00.4382.1.v1

15.00.4375.4.v1

15.00.4365.2.v1

15.00.4355.3.v1

15.00.4345.5.v1

15.00.4335.1.v1

15.00.4322.2.v1

15.00.4316.3.v1

15.00.4312.2.v1

15.00.4236.7.v1

15.00.4198.2.v1

15.00.4153.1.v1

15.00.4073.23.v1

15.00.4043.16.v1

14.00.3505.1.v1

14.00.3500.1.v1

14.00.3495.9.v1

14.00.3485.1.v1

14.00.3480.1.v1

14.00.3475.1.v1

14.00.3471.2.v1

14.00.3465.1.v1

14.00.3460.9.v1

14.00.3451.2.v1

14.00.3421.10.v1

14.00.3401.7.v1

14.00.3381.3.v1

14.00.3356.20.v1

14.00.3294.2.v1

14.00.3281.6.v1

13.00.6470.1.v1

13.00.6465.1.v1

13.00.6460.7.v1

13.00.6455.2.v1

13.00.6450.1.v1

13.00.6445.1.v1

13.00.6441.1.v1

13.00.6435.1.v1

13.00.6430.49.v1

13.00.6419.1.v1

13.00.6300.2.v1

sqlserver-web

16.00.4215.2.v1

16.00.4210.1.v1

16.00.4205.1.v1

16.00.4195.2.v1

16.00.4185.3.v1

16.00.4175.1.v1

16.00.4165.4.v1

16.00.4150.1.v1

16.00.4140.3.v1

16.00.4135.4.v1

16.00.4131.2.v1

16.00.4125.3.v1

16.00.4120.1.v1

16.00.4115.5.v1

16.00.4105.2.v1

16.00.4095.4.v1

16.00.4085.2.v1

15.00.4445.1.v1

15.00.4440.1.v1

15.00.4435.7.v1

15.00.4430.1.v1

15.00.4420.2.v1

15.00.4415.2.v1

15.00.4410.1.v1

15.00.4395.2.v1

15.00.4390.2.v1

15.00.4385.2.v1

15.00.4382.1.v1

15.00.4375.4.v1

15.00.4365.2.v1

15.00.4355.3.v1

15.00.4345.5.v1

15.00.4335.1.v1

15.00.4322.2.v1

15.00.4316.3.v1

15.00.4312.2.v1

15.00.4236.7.v1

15.00.4198.2.v1

15.00.4153.1.v1

15.00.4073.23.v1

15.00.4043.16.v1

14.00.3505.1.v1

14.00.3500.1.v1

14.00.3495.9.v1

14.00.3485.1.v1

14.00.3480.1.v1

14.00.3475.1.v1

14.00.3471.2.v1

14.00.3465.1.v1

14.00.3460.9.v1

14.00.3451.2.v1

14.00.3421.10.v1

14.00.3401.7.v1

14.00.3381.3.v1

14.00.3356.20.v1

14.00.3294.2.v1

14.00.3281.6.v1

13.00.6470.1.v1

13.00.6465.1.v1

13.00.6460.7.v1

13.00.6455.2.v1

13.00.6450.1.v1

13.00.6445.1.v1

13.00.6441.1.v1

13.00.6435.1.v1

13.00.6430.49.v1

13.00.6419.1.v1

13.00.6300.2.v1

RDS engine

The RDS engine is the default, single-node, and most cost-effective option. While it's not highly available by default, you can configure a standby instance in a different Availability Zone or add read replicas to improve performance and resilience.

RdsEngine  API reference
type
Required
properties.primaryInstance
Required
properties.version
Required
properties.dbName
properties.port
properties.storage
properties.readReplicas
properties.disableAutoMinorVersionUpgrade

Instance size

You can configure the instance size for both the primary instance and its read replicas.

This determines the CPU, memory, and networking capacity of the database instance. For a list of available instance sizes, see the AWS RDS instance types documentation.

Note: Not all instance sizes are available for all engines, versions, and regions. Some instance families (like t3 or t4) are intended for development and testing, not production workloads.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: postgres
properties:
version: '16.2'
port: 5432
primaryInstance:
instanceSize: db.t3.micro

Multi-AZ mode

You can enable Multi-AZ mode for both primary instances and read replicas.

When enabled, a standby replica is created in a different AZ. If the primary instance fails, traffic is automatically failed over to the standby. This also minimizes downtime during maintenance.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: postgres
properties:
version: '16.2'
port: 5432
primaryInstance:
instanceSize: db.t2.micro
multiAz: true
RdsEnginePrimaryInstance  API reference
instanceSize
Required
multiAz

Read replicas

Read replicas can handle read-only traffic to reduce the load on the primary instance. They are kept in sync with the primary through asynchronous replication. Each read replica has its own endpoint.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: postgres
properties:
version: '16.2'
port: 5432
primaryInstance:
instanceSize: db.t3.micro
readReplicas:
- instanceSize: db.t3.micro
- instanceSize: db.t3.micro
RdsEngineReadReplica  API reference
instanceSize
Required
multiAz

Storage

Storage will automatically scale up when free space is low. For more details on storage autoscaling, see the AWS documentation.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: postgres
properties:
version: '16.2'
port: 5432
primaryInstance:
instanceSize: db.t3.micro
storage:
initialSize: 40
maxSize: 400
RdsEngineStorage  API reference
initialSize
Default: 20
maxSize
Default: 200

Aurora engine

The Aurora engine is a fully managed, AWS-developed database engine that offers clustering, high availability, and increased performance. It replicates storage six ways across three Availability Zones and automatically load-balances read operations between nodes. If a primary instance fails, a read replica is automatically promoted to take its place.

resources:
auroraSlsPostgres:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbSecret.password')
engine:
type: aurora-postgresql
properties:
version: '16.2'
instances:
- instanceSize: db.t3.medium
port: 5432
AuroraEngine  API reference
type
Required
properties.instances
Required
properties.version
Required
properties.dbName
Default: defdb
properties.port
properties.disableAutoMinorVersionUpgrade
AuroraEngineInstance  API reference
instanceSize
Required

Aurora Serverless V2 engine

The Aurora Serverless V2 engine is similar to the standard Aurora engine but adds automatic, usage-based scaling. It's more responsive and less disruptive when scaling than the V1 engine. The database can scale down to zero, so you don't pay for compute capacity when it's not in use.

Scaling is measured in Aurora Capacity Units (ACUs), where each ACU provides approximately 2GB of RAM and one virtual CPU.

AuroraServerlessV2Engine  API reference
type
Required
properties.version
Required
properties.dbName
Default: defdb
properties.minCapacity
Default: 0.5
properties.maxCapacity
Default: 10
properties.disableAutoMinorVersionUpgrade
resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbSecret.password')
engine:
type: aurora-postgresql-serverless-v2
properties:
version: '16.4'
maxCapacity: 8

Backups

Automated backups are taken daily. You can retain them for up to 35 days. To disable automated backups for RDS engines, set this to 0. This setting does not affect manual snapshots.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: my_secret_password
engine:
type: postgres
properties:
version: '16.2'
primaryInstance:
instanceSize: db.t3.micro
automatedBackupRetentionDays: 5

Logging

By default, logs are enabled and retained for 90 days. The available log types depend on the database engine. You can log connections, queries, errors, and more.

RelationalDatabaseLogging  API reference
disabled
retentionDays
Default: 90
logTypes
engineSpecificOptions
logForwarding
resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: my_secret_password
engine:
type: postgres
properties:
version: '16.2'
primaryInstance:
instanceSize: db.t3.micro
logging:
retentionDays: 30
engineSpecificOptions:
log_connections: true

Forwarding logs

You can forward logs to third-party services. See Forwarding Logs for more information.

Closing zombie connections

Connections from resources that are no longer running (like stopped containers) can become "zombie" connections. In modern, ephemeral architectures, it's important to have a strategy for handling them.

From container workloads

When connecting from a container, you should close the connection before the container exits. You can do this by listening for the SIGTERM signal.

const connectionPool = createConnectionPool();
// remember to close the connection even on errors
process
.on('uncaughtException', () => {
connectionPool.close();
process.exit(1);
})
.on('unhandledRejection', () => {
connectionPool.close();
process.exit(1);
});
process.on('SIGTERM', () => {
connectionPool.close();
process.exit(0);
});

From batch jobs

Similarly, for batch jobs, you should close the connection before the job finishes.

const connectionPool = createConnectionPool();
connectionPool.connect();
// remember to close the connection even on errors
process
.on('uncaughtException', () => {
connectionPool.close();
process.exit(1);
})
.on('unhandledRejection', () => {
connectionPool.close();
process.exit(1);
});
doSomethingWithYourConnection();
connectionPool.close();

From Lambda functions

For Lambda functions, you have two options:

1. Initialize and close the connection inside the handler.

This prevents zombie connections but can be slow, as creating a new connection for each invocation can add significant latency.

import { Client } from 'pg';
const handler = async (event, context) => {
const pgClient = new Client({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT
});
await pgClient.connect();
const result = await pgClient.query('SELECT NOW()');
const time = result.rows[0];
await pgClient.end();
return { result: time };
};
export default handler;

2. Initialize the connection outside the handler.

This reuses the connection across invocations, which is more performant. However, it can lead to zombie connections because you can't hook into the Lambda container's shutdown process. To mitigate this, you should:

  • Lower your database's connection timeout settings.
  • Add logic to your application to re-establish the connection if it's been closed by the database.
import { Client } from 'pg';
const pgClient = new Client({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT
});
(async () => {
await pgClient.connect();
})();
const handler = async (event, context) => {
const result = await pgClient.query('SELECT NOW()');
const time = result.rows[0];
return { result: time };
};
export default handler;

Accessibility

You can control which resources can access your database. In addition to requiring user credentials, you can restrict access based on the network.

DatabaseAccessibility  API reference
accessibilityMode
Default: internetRequired
forceDisablePublicIp
whitelistedIps

Internet mode

This is the default and least restrictive mode. The database can be accessed from anywhere on the internet.

VPC mode

The database can only be accessed from resources within the default VPC, such as functions, batch jobs, and container workloads. You can also whitelist specific IP addresses to allow access from the internet.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: aurora-postgresql
properties:
version: '16.2'
instances:
- instanceSize: db.t3.medium
port: 5432
accessibility:
accessibilityMode: vpc
myFunction:
type: function
properties:
packaging:
type: stacktape-lambda-buildpack
properties:
entryfilePath: path/to/my/function.ts
joinDefaultVpc: true

Scoping workloads in VPC mode

This mode is similar to VPC mode but more restrictive. In addition to being in the same VPC, a resource must explicitly list the database in its connectTo property to gain access.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: aurora-postgresql
properties:
version: '16.2'
instances:
- instanceSize: db.t3.medium
port: 5432
accessibility:
accessibilityMode: scoping-workloads-in-vpc
myFunction:
type: function
properties:
packaging:
type: stacktape-lambda-buildpack
properties:
entryfilePath: path/to/my/function.ts
joinDefaultVpc: true
connectTo:
- myDatabase

Whitelisted IPs only mode

The database can only be accessed from the IP addresses and CIDR blocks in the whitelistedIps list.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: $Secret('dbPassword')
engine:
type: aurora-postgresql
properties:
version: '16.2'
instances:
- instanceSize: db.t3.medium
port: 5432
accessibility:
accessibilityMode: whitelisted-ips-only
whitelistedIps:
- '147.25.33.12'

Maintenance window

Maintenance activities, such as OS patching or engine upgrades, will be performed during this window. The database may be briefly unavailable during maintenance. To avoid downtime, use a multi-AZ deployment or an Aurora engine.

The format is day:start_time-day:end_time in UTC (e.g., Sun:02:00-Sun:04:00). By default, the maintenance window is set to a region-specific time on Sundays.

resources:
myDatabase:
type: relational-database
properties:
credentials:
masterUserPassword: my_secret_password
engine:
type: postgres
properties:
version: '16.2'
primaryInstance:
instanceSize: db.t3.micro
preferredMaintenanceWindow: Sun:04:00-Sun:05:00

Referenceable parameters

The following parameters can be easily referenced using $ResourceParam directive directive.

To learn more about referencing parameters, refer to referencing parameters.

connectionString
  • Fully-formed connection string that can be used to access the primary instance. For aurora databases, this is connectionString to cluster endpoint, which can be used for both reads and writes. Includes host, port, username, password and dbName.

  • Usage: $ResourceParam('<<resource-name>>', 'connectionString')
jdbcConnectionString
  • Fully-formed connection string in JDBC form that can be used to access the primary instance. Includes host, port, username, password and dbName.

  • Usage: $ResourceParam('<<resource-name>>', 'jdbcConnectionString')
host
  • Hostname (address) of the primary instance that can be used for both reads and writes. For aurora databases, this is hostname of a cluster endpoint, which can be used for both reads and writes.

  • Usage: $ResourceParam('<<resource-name>>', 'host')
port
  • Port of the database.

  • Usage: $ResourceParam('<<resource-name>>', 'port')
dbName
  • Name of the automatically created database (can be configured using the dbName property).

  • Usage: $ResourceParam('<<resource-name>>', 'dbName')
readerHost
  • Hostname (address) used for reads only. (only available for aurora-postgresql and aurora-mysql engines). If you have multiple instances, it is advised to use readerHost for reads to offload the primary (read/write) host. ReaderHost automatically balances requests between available instances. Connections are auto-balanced among available reader hosts.

  • Usage: $ResourceParam('<<resource-name>>', 'readerHost')
readerConnectionString
  • Same as connectionString but targets readerHosts (only available for aurora-postgresql and aurora-mysql engines). Connections are auto-balanced among available reader hosts.

  • Usage: $ResourceParam('<<resource-name>>', 'readerConnectionString')
readerJdbcConnectionString
  • Same as readerConnectionString but in JDBC format (only available for aurora-postgresql and aurora-mysql engines).

  • Usage: $ResourceParam('<<resource-name>>', 'readerJdbcConnectionString')
readReplicaHosts
  • Comma-separated list of read replica hostnames (only available if read replicas are configured). Read replicas can only be used for read operations.

  • Usage: $ResourceParam('<<resource-name>>', 'readReplicaHosts')
readReplicaConnectionStrings
  • Comma-separated list of connection strings (URLs) used to connect to read replicas (only available when read replicas are configured). Read replicas can only be used for read operations.

  • Usage: $ResourceParam('<<resource-name>>', 'readReplicaConnectionStrings')
readReplicaJdbcConnectionStrings
  • Same as readReplicaConnectionStrings but in JDBC format (only available when read replicas are configured).

  • Usage: $ResourceParam('<<resource-name>>', 'readReplicaJdbcConnectionStrings')

Pricing

Pricing depends heavily on the engine you choose.

RDS engines:

  • Instances: Prices vary by instance size and region. See the AWS pricing pages for PostgreSQL, MySQL, MariaDB, Oracle, and SQL Server.
  • Storage: $0.115 - $0.238 per GB per month.
  • Backups: Free for automated backups that don't exceed your total database storage. Additional backup storage is $0.095 per GB per month.

Aurora engines:

  • Instances: Prices start at $0.073 per hour. See the Aurora pricing page for details.
  • Storage: $0.10 - $0.19 per GB per month.
  • I/O Rate: $0.20 - $0.28 per million read/write operations.
  • Backups: Free for automated backups that don't exceed your total database storage. Additional backup storage is $0.021 - $0.037 per GB per month.

Aurora Serverless:

  • ACUs (Aurora Capacity Units): Each ACU costs $0.06 - $0.10 per hour.
  • Storage, I/O, and Backups: Same as the standard Aurora engine.

Data transfer charges (all engines):

  • Inbound: Free.
  • Outbound (same AZ): Free.
  • Outbound (different AZ): $0.01 per GB.
  • Outbound (internet): First 1GB is free, then $0.09 - $0.15 per GB.

Free Tier (first 12 months):

  • 750 hours of db.t2.micro usage per month.
  • 20GB of SSD storage.
  • 20GB of backup storage.

API reference

RelationalDatabase  API reference
type
Required
properties.credentials
Required
properties.engine
Required
properties.accessibility
properties.deletionProtection
properties.automatedBackupRetentionDays
Default: 1
properties.preferredMaintenanceWindow
properties.alarms
properties.disabledGlobalAlarms
properties.logging
overrides
RdsEngineProperties  API reference
Parent:RdsEngine
primaryInstance
Required
version
Required
dbName
port
storage
readReplicas
disableAutoMinorVersionUpgrade
AuroraEngineProperties  API reference
instances
Required
version
Required
dbName
Default: defdb
port
disableAutoMinorVersionUpgrade
AuroraServerlessEngineProperties  API reference
version
dbName
Default: defdb
minCapacity
Default: 2
maxCapacity
Default: 4
pauseAfterSeconds
disableAutoMinorVersionUpgrade
PostgresLoggingOptions  API reference
log_connections
log_disconnections
log_lock_waits
log_min_duration_statement
Default: 10000
log_statement
Default: ddl
MysqlLoggingOptions  API reference
server_audit_events
Default: QUERY_DDL
long_query_time
Default: 10

Contents