简体   繁体   中英

How to connect AWS aurora (posgresSQL) using prisma

I am working with nest.js to build an API. I created a serverless RDS aurora for postgresSQl to use it as a database.

This is my aurora(postgresSQL) database instance (Connectivity and Security) 在此处输入图像描述

  • This is my database Configuration在此处输入图像描述

  • This is my security group detail在此处输入图像描述

Then I try connect by using endpoint,database,user etc, by using prisma in nest.js:

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = "postgresql://postgres:password@med.cluster-cnonikf1pbgi.ap-southeast-1.rds.amazonaws.com:5432/Medi?schema=public&ssl=true"
}

But when I run this command:

npx prisma migrate dev --name init

I got an error like this:

Error: P1001: Can't reach database server at `med.cluster-cnonikf1pbgi.ap-southeast-1.rds.amazonaws.com`:`5432`

Please make sure your database server is running at `med.cluster-cnonikf1pbgi.ap-southeast-1.rds.amazonaws.com`:`5432`.

I was able to connect directly to my Aurora Cluster without the need of a special gateway or ec2 instance. This worked for me:

  1. Make sure you have "Public access" set to "Publicly accessible". You should see this option when created the db but you can also modify it once the db has already been created by going to RDS -> Databases -> Select a db instance and not the cluster (the cluster does not seem to provide this option) -> Click "Modify" button in top right -> scroll down to the "Connectivity" Section -> Expand it and you'll see the option to change this setting.

  2. Ensure the VPC "security group" that you have assigned to your DB grants external access to your DB. The same "Connectivity" section from step 1 also shows the VPC security group that your DB is using. Take note of it's name. You can view the details of your security group by going to the "VPC" service config page: VPC -> security groups -> click on your security group -> examine the inbound rules -> if needed create a new rule by click in "edit inbound rules" -> add rule. If you want to give access to just your IP you can choose "My IP", which will prefill your current IP address.

Some resources I found helpful:

Connecting from inte.net into VPC

Trouble Shooting Connectivity

You cannot connect to a server less aurora cluster outside of the VPC it is running in. You tried to access the DB from your local machine, right? For local development you must create an EC2 instance in the same VPC of the aurora cluster and connect with SSH to the EC2 instance to connect then to the database. To you local database management tools you can also setup SSH port forwarding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM