无法无服务器连接到 AWS Aurora DB -- mysql 引擎

Not able to connect to AWS Aurora DB server-less -- mysql engine

我创建了一个公开可用的 AWS Aurora DB 无服务器,我正在尝试使用 python 连接到该数据库。但是我无法连接,我怀疑是VPC。

请建议我是否需要检查其他任何内容,我也有以下这些查询;

代码片段:

import mysql.connector as mysq
import sys, os, boto3 as aws, pandas as pd, pymysql
from sqlalchemy import create_engine, inspect

ENDPOINT = "random.cluster-random.ap-south-1.rds.amazonaws.com"
PORT = "3306"
USER = "random"
REGION = "ap-south-1"
DBNAME = "random"
PASSWORD = "random"

方法一:

client = aws.client('rds')
token = client.generate_db_auth_token(DBHostname=ENDPOINT, Port=PORT, DBUsername=USER, Region=REGION)
print(token)

try:
    conn =  mysq.connect(host=ENDPOINT, user=USER, passwd=token, port=PORT, database=DBNAME)

    cur = conn.cursor()
    cur.execute("""SELECT now()""")
    query_results = cur.fetchall()
    print(query_results)
except Exception as e:
    print("Database connection failed due to {}".format(e))

方法二:

CONNECTION_STRING = 'mssql+pymssql' + '://' + USER + ':' + PASSWORD + '@' + ENDPOINT + ':' + str(PORT) + '/' + DBNAME
engine = create_engine(CONNECTION_STRING)
print(inspect(engine).get_table_names())

方法三:

conn = pymysql.connect(host=ENDPOINT, user=USER,port=int(PORT), passwd=PASSWORD, db=DBNAME)

谢谢, 尼克尔

Aurora serverless 没有 public ip。表格 docs.

You can't give an Aurora Serverless v1 DB cluster a public IP address. You can access an Aurora Serverless v1 DB cluster only from within a VPC.

Aurora v2 相同。

所以你必须在你的 home/work 网络和你的 VPC 之间设置一个 VPN,或者通过一些 ec2 实例堡垒主机使用 SSH 隧道。