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:
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.
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.
In the AWS console, go to EC2 service, select the VPC-nat instance. In theĀ SecurityĀ tab click on the security group.
Edit the inbound rules by whitelisting your public IP address for port 22 (SSH port). Save the changes.
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.
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.
ļ»æ
- 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.
- 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:
ļ»æ