[英]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.我正在使用 nest.js 构建一个 API。我为 postgresSQl 创建了一个无服务器 RDS aurora 以将其用作数据库。
This is my aurora(postgresSQL) database instance (Connectivity and Security)这是我的 aurora(postgresSQL) 数据库实例(连接性和安全性)
Then I try connect by using endpoint,database,user etc, by using prisma in nest.js:然后我尝试使用端点、数据库、用户等进行连接,方法是在 nest.js 中使用 prisma:
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.我能够直接连接到我的 Aurora 集群,而不需要特殊的网关或 ec2 实例。 This worked for me:
这对我有用:
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.
您应该在创建数据库时看到此选项,但您也可以在创建数据库后修改它,方法是转到 RDS -> 数据库 -> Select 数据库实例而不是集群(集群似乎不提供此选项) -> 单击右上角的“修改”按钮 -> 向下滚动到“连接”部分 -> 展开它,您将看到更改此设置的选项。
Ensure the VPC "security group" that you have assigned to your DB grants external access to your DB.确保您分配给数据库的 VPC“安全组”授予对数据库的外部访问权限。 The same "Connectivity" section from step 1 also shows the VPC security group that your DB is using.
第 1 步中的相同“连接”部分还显示了您的数据库正在使用的 VPC 安全组。 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.
您可以通过转到“VPC”服务配置页面查看安全组的详细信息:VPC -> 安全组 -> 单击您的安全组 -> 检查入站规则 -> 如果需要,通过单击“创建新规则”编辑入站规则”-> 添加规则。 If you want to give access to just your IP you can choose "My IP", which will prefill your current IP address.
如果您只想访问您的 IP,您可以选择“我的 IP”,这将预填您当前的 IP 地址。
Some resources I found helpful:我发现一些有用的资源:
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?您无法连接到正在运行的 VPC 之外的无服务器极光集群。您尝试从本地计算机访问数据库,对吗? 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.
对于本地开发,您必须在 aurora 集群的同一 VPC 中创建一个 EC2 实例,并通过 SSH 连接到 EC2 实例,然后再连接到数据库。 To you local database management tools you can also setup SSH port forwarding.
对于本地数据库管理工具,您还可以设置 SSH 端口转发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.