无法从 SQL 客户端连接 Amazon Aurora Serverless [英] Not able connect Amazon Aurora Serverless from SQL client

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

问题描述

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

来自 AWS 论坛,

<块引用>

您不能为 Aurora Serverless 数据库集群提供公共 IP 地址.您可以从一个 Aurora Serverless 数据库集群only基于 Amazon VPC 服务的虚拟私有云 (VPC).

来源:

2.要从项目访问,

首先我像这样从我的终端创建一个 ssh 隧道

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

然后像这样用db配置运行我的项目test.php

$conn = pg_connect("host=127.0.0.1 port=5555 dbname=postgres user=postgres password=password_goes_here");//其他代码在此处用于从您的数据库中获取数据如果(!$conn){echo "发生错误.
";出口;}$result = pg_query($conn, "SELECT * FROM 品牌");如果(!$结果){echo "发生错误.
";出口;}而 ($row = pg_fetch_row($result)) {echo "品牌 ID: $row[0] 品牌名称: $row[1]";echo "
";}

Today I've created Amazon Aurora Serverless cluster for PostGreSql in us-west-2, ensured the VPC and security groups in a 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.

From AWS froum,

You can't give an Aurora Serverless DB cluster a public IP address. You can access an Aurora Serverless DB cluster only from within a virtual private cloud (VPC) based on the Amazon VPC service.

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

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,

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

解决方案

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.

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. To access from any client(Navicat in my case),

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. To access from project,

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

Then run my project with db configuration like this way 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.
";
    exit;
}

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆