Templates
Strapi Serverless

Access the RDS database

7min

The Strapi app and the RDS database reside in a VPC private network and all traffic from the outside is blocked by default. This means that you cannot directly access the service or the database from the Internet.

However, if you need to access the database from your local machine there is a way to do so by following the instructions below:

1. Create EC2 key pair

To create a new EC2 key-pair, go to AWS console, choose EC2 service and from the left panel, choose Key Pairs, and clickĀ Create key pairĀ in the top right. The name you choose here is the one used to configure the VPC resource in the Microtica Developer Portal.

Create EC2 key pair
Create EC2 key pair
ļ»æ

EC2 key-pair

You will need to create an EC2 key-pair from the AWS console. We donā€™t create it automatically due to security reasons. This key should always be in your possession and kept in a secure place. It will allow you to access your EC2 instances through SSH.

2. Allow SSH access from your public IP address

In the AWS console, go to EC2 service, select the VPC-nat instance. In theĀ SecurityĀ tab click on the security group.

Allow SSH access from your public IP address
Allow SSH access from your public IP address
ļ»æ

Edit the inbound rules by whitelisting your public IP address for port 22 (SSH port). Save the changes.

Whitelist your public IP address
Whitelist your public IP address
ļ»æ

3. Configure the VPC resource in the Microtica Developer Portal

The next thing you need to do is to add the name of the key pair youā€™ve just created by updating the configuration of theĀ VPC resourceĀ in the Strapi environment. Go to your Strapi environment, underĀ ResourcesĀ selectĀ VPCĀ resource >Ā Resource Settings. Enter theĀ keyNameĀ you created previously and click onĀ Save and DeployĀ button.

Configure the VPC resource in Microtica
Configure the VPC resource in Microtica
ļ»æ

4. Connect with the database over SSH

Now you have everything ready to establish a connection with the database. To get the necessary information, follow the steps below:

  • Select the VPC resource and in Resource Outputs you can get theĀ NAT instance IPĀ and use it as an SSH hostname. Set SSH username to ec2-user.
Connect with the database over SSH
Connect with the database over SSH
ļ»æ

ļ»æ

  • Select theĀ StrapiĀ resource and inĀ Resource OutputsĀ you can get the databaseĀ endpoint,Ā port, andĀ username. The database password is securely stored in AWS Secret Manager specified in theĀ DatabaseSecretĀ output parameter.
Resource outputs in Microtica
Resource outputs in Microtica
ļ»æ
  • And last, use your preferred client (e.g. pgAdmin, MySQLWorkbench) to connect with the Strapi database.

If you prefer using CLI to access the database, you should first establish a tunnel to your database and then connect with the database with the following commands:

PostgreSQL
ļ»æ

ļ»æ