---
title: "Data source: AWS RDS"
sidebar_label: "AWS RDS"
description: Connect DBLab Engine to an Amazon RDS Postgres database using either master password authentication or IAM database authentication.
---

:::info
As the first step, you need to set up a machine for DBLab Engine instance. See the [guide](/docs/dblab-howtos/administration/install-dle-manually).
:::

:::tip See also
To get started using DBLab Engine for Amazon RDS databases, see the [Database Lab tutorial for Amazon RDS](/docs/tutorials/database-lab-tutorial-amazon-rds).
:::

There are two options to connect to the RDS database. The right choice depends on the **Database authentication** method assigned to your RDS database.

Options:
- Using **password authentication (master password)**. This option can be used for all **Database authentication** methods enabled for your database and requires setting the master password of the database in the DBLab Engine configuration file
- **IAM database authentication**. This option can be used only with **Password and IAM database authentication** — it requires AWS user credentials and does not require the master password. Use this option for granular control of the access to your database

If you want to use **IAM database authentication**, read how to enable it [here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Enabling.html).

## Option 1: Password authentication

:::tip
You need to know the **master password**. If you have lost the password, you can reset it. Read how to reset it [here](https://aws.amazon.com/premiumsupport/knowledge-center/reset-master-user-password-rds/).
:::

:::tip Quick path (DBLab Engine 4.2+)
On a new instance the UI Configuration page opens in Simple mode: paste the source URL and password and the engine proposes the rest. The same detection is available from the terminal with [`dblab local-install`](/docs/reference-guides/dblab-client-cli-reference#command-local-install). The manual steps below remain fully supported.
:::

Copy the contents of configuration example [`config.example.logical_generic.yml`](https://gitlab.com/postgres-ai/database-lab/-/blob/v4.2.0/engine/configs/config.example.logical_generic.yml) from the DBLab Engine repository to `~/.dblab/engine/configs/server.yml` and update the following options:
- Set a secure `server:verificationToken` — it will be used to authorize API requests to the Engine. The 4.2 example uses the placeholder `${DBLAB_VERIFICATION_TOKEN}`: either replace it with the token, or keep it and pass the variable to the container with `--env-file /etc/dblab/engine.env` (a root-owned file with mode 600 holding `DBLAB_VERIFICATION_TOKEN=...`; see [Environment variables](/docs/reference-guides/database-lab-engine-configuration-reference#environment-variables)); the engine does not start while the variable is unset
- Set connection options in `retrieval:spec:logicalDump:options:source:connection`:
    - `dbname`: database name to connect to
    - `host`: database server host
    - `port`: database server port
    - `username`: database user name
    - `password`: database master password (can also be set as the `PGPASSWORD` environment variable of the Docker container)
- Set a proper version in Postgres Docker image tag (change the image itself only if you know what you are doing):
    - `databaseContainer:dockerImage`

Launch DBLab Engine:
```bash
sudo docker run \
  --name dblab_server \
  --label dblab_control \
  --privileged \
  --publish 127.0.0.1:2345:2345 \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /var/lib/dblab:/var/lib/dblab/:rshared \
  --volume ~/.dblab/engine/configs:/home/dblab/configs \
  --volume ~/.dblab/engine/meta:/home/dblab/meta \
  --volume ~/.dblab/engine/logs:/home/dblab/logs \
  --volume /sys/kernel/debug:/sys/kernel/debug:rw \
  --volume /lib/modules:/lib/modules:ro \
  --volume /proc:/host_proc:ro \
  --detach \
  --restart on-failure \
  postgresai/dblab-server:4.2.0
```

:::info
Parameter `--publish 127.0.0.1:2345:2345` means that only local connections will be allowed.

To allow external connections, consider either using additional software such as NGINX or Envoy or changing this parameter. Removing the host/IP part (`--publish 2345:2345`) allows listening to all available network interfaces.
See more details in the official [Docker command-line reference](https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose).
:::


## Option 2: IAM database authentication

### Prepare AWS user and IAM database access policy
1. Create an AWS user (or use an existing one)
2. Save and assign AWS access environment variables:
    - `export AWS_ACCESS_KEY="access_key"`
    - `export AWS_SECRET_ACCESS_KEY="secret_access_key"`
Read how you can get the AWS access keys for the existing user [here](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)
3. Create and attach an IAM Policy for IAM Database Access to an AWS user. Read how you can do it [here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.IAMPolicy.html)

:::info
Alternatively, you can add `AmazonRDSFullAccess`, `IAMFullAccess` policies to an AWS user (not recommended).
:::

### Set up and run DBLab Engine
Copy the contents of configuration example [`config.example.logical_rds_iam.yml`](https://gitlab.com/postgres-ai/database-lab/-/blob/v4.2.0/engine/configs/config.example.logical_rds_iam.yml) from the DBLab Engine repository to `~/.dblab/engine/configs/server.yml` and update the following options:
- Set a secure `server:verificationToken` — it will be used to authorize API requests to the Engine. The 4.2 example uses the placeholder `${DBLAB_VERIFICATION_TOKEN}`: either replace it with the token, or keep it and pass the variable to the container with `--env-file /etc/dblab/engine.env` (a root-owned file with mode 600 holding `DBLAB_VERIFICATION_TOKEN=...`; see [Environment variables](/docs/reference-guides/database-lab-engine-configuration-reference#environment-variables)); the engine does not start while the variable is unset
- Set connection options `retrieval:spec:logicalDump:options:source:connection`:
    - `dbname`: database name to connect to
    - `username`: database user name
- Set AWS params in `retrieval:spec:logicalDump:options:source:rdsIam`:
    - `awsRegion`: RDS instance region
    - `dbInstanceIdentifier`: RDS instance identifier
- Set a proper version in Postgres Docker image tag (change the image itself only if you know what you are doing):
    - `databaseContainer:dockerImage`

### Download AWS RDS certificate
This type of data retrieval requires a secure connection to a database. To set it up, we need to download a certificate from AWS.

```bash
wget https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem -P ~/.dblab/
```

### Run DBLab Engine
Run DBLab Engine (set proper **AWS access keys** and update **Verification token**):
```bash
sudo docker run \
  --name dblab_server \
  --label dblab_control \
  --privileged \
  --publish 127.0.0.1:2345:2345 \
  --volume ~/.dblab/engine/configs:/home/dblab/configs \
  --volume ~/.dblab/engine/meta:/home/dblab/meta \
  --volume ~/.dblab/engine/logs:/home/dblab/logs \
  --volume /var/run/docker.sock:/var/run/docker.sock \
  --volume /var/lib/dblab:/var/lib/dblab/:rshared \
  --volume /sys/kernel/debug:/sys/kernel/debug:rw \
  --volume /lib/modules:/lib/modules:ro \
  --volume /proc:/host_proc:ro \
  --volume ~/.dblab/rds-combined-ca-bundle.pem:/cert/rds-combined-ca-bundle.pem \
  --env AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY}" \
  --env AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}" \
  --detach \
  --restart on-failure \
  postgresai/dblab-server:4.2.0
```

:::info
Parameter `--publish 127.0.0.1:2345:2345` means that only local connections will be allowed.

To allow external connections, consider either using additional software such as NGINX or Envoy or changing this parameter. Removing the host/IP part (`--publish 2345:2345`) allows listening to all available network interfaces.
See more details in the official [Docker command-line reference](https://docs.docker.com/engine/reference/commandline/run/#publish-or-expose-port--p---expose).
:::

## Restart in the case of failure

```bash
# Stop and remove the DBLab Engine control container.
sudo docker rm -f dblab_server

# Clean up data directory.
sudo rm -rf /var/lib/dblab/dblab_pool/data/*

# Remove dump directory.
sudo umount /var/lib/dblab/dblab_pool/dump
sudo rm -rf /var/lib/dblab/dblab_pool/dump
```

## Alternative: RDS/Aurora refresh tool

For large production databases, running `pg_dump` directly against production can hold xmin horizon for hours and create significant load. The [RDS/Aurora refresh tool](/docs/dblab-howtos/administration/data/rds-refresh) provides an alternative approach that dumps from a temporary RDS clone instead, leaving production untouched.
