11min

Access the RDS database

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.

Document image

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.

Document image

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

Document image

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.

Document image

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.
Document image

ļ»æ

  • Select theĀ StrapiServerlessĀ 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.
Document image

ļ»æ

  • And last, use your preferred client (e.g. 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 with the following command:

Shell
|

Then you can use the mysql command-line tool to access the database:

Shell
|

ļ»æ