本文介绍了无法从SQL客户端连接Amazon Aurora Serverless的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我已经在us-west-2中为PostGreSql创建了Amazon Aurora Serverless集群,确保了VPC和安全组位于一种方式,它应该是可公开访问的.但是我无法使用Navicat/PgAdmin4桌面客户端中的aurora端点连接该群集.然后,我从与Aurora Serverless相同的安全组/vpc中的EC2实例进行尝试,然后它起作用了.

Today I've created Amazon Aurora Serverless cluster for PostGreSql in us-west-2, ensured the VPC and security groups ina way that, it should be publicly accessibly. But I'm not able to connect that cluster using the aurora endpoint from my Navicat/PgAdmin4 desktop client. Then I tried from the EC2 instance that are in same security group/vpc as like as Aurora Serverless, then it worked.

在AWS froum中,

From AWS froum,

来源: https://forums.aws.amazon.com/thread.jspa?messageID=862860&tstart=0

似乎它使用了内部AWS网络设置,该设置当前仅支持来自VPC内部的连接,并且它必须与部署无服务器集群的VPC相同.

Seems it uses an internal AWS networking setup that currently only supports connections from inside a VPC, and it must be the same VPC where the serverless cluster is deployed.

所以现在基本上我的问题是,

So now basically my question is that,

是否有任何变通办法将Aurora Serverless与Navicat或PgAdmin4之类的任何客户端连接?

Is there any workaround to connect Aurora Serverless with any client like Navicat or PgAdmin4?

推荐答案

我通过一些调整发现了一个很酷的hack,非常适合我的开发目的,我知道我不需要我的生产环境.

I found a cool hack that is working perfectly for my development purpose with some tweaks and I know I don't need this on my production environment.

因此,我们知道Aurora Serverless仅在VPC内运行.因此,请确保您尝试连接到VPC内的Aurora,并且分配给Aurora群集的安全组具有允许访问的适当规则.如前所述,我已经拥有一个EC2实例,Aurora Serverless和两者之间的VPC.因此,我可以从EC2中访问它,但不能从本地PC/本地sql客户端访问它.要解决此问题,请执行以下两个步骤.

So as we know Aurora Serverless works only inside VPC. So make sure you are attempting to connect to Aurora within the VPC and the security group assigned to the Aurora cluster has the appropriate rules to allow access. As I mention earier that I already have an EC2 instance, Aurora Serverless and a VPC around both. So I can access it from my EC2 but not from my local pc/ local sql client. To fix that I did below two steps.

1.要从任何客户端(在我的情况下为Navicat)进行访问,

a.首先需要添加 GENERAL 数据库配置,例如aurora终结点主机,用户名,密码等.b.然后,需要添加 SSH 配置,例如EC2计算机用户名,hostip和.pem文件路径

a. First need to add GENERAL db configurations like aurora endpoint host, username, password etc.b. Then, need to add SSH configuration, like EC2 machine username, hostip and .pem file path

2.要从项目访问,

首先,我以这种方式在终端上创建一个 ssh隧道

First I create a ssh tunnel from my terminal like this way,

ssh ubuntu@my_ec2_ip_goes_here -i rnd-vrs.pem -L 5555:database-1.my_aurora_cluster_url_goes_here.us-west-2.rds.amazonaws.com:5432

然后像这样 test.php

$conn = pg_connect("host=127.0.0.1 port=5555 dbname=postgres user=postgres password=password_goes_here");

// other code goes here to get data from your database
if (!$conn) {
    echo "An error occurred.\n";
    exit;
}

$result = pg_query($conn, "SELECT * FROM brands");
if (!$result) {
    echo "An error occurred.\n";
    exit;
}

while ($row = pg_fetch_row($result)) {
    echo "Brand Id: $row[0]  Brand Name: $row[1]";
    echo "<br />\n";
}

这篇关于无法从SQL客户端连接Amazon Aurora Serverless的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 20:19