Reputation: 11
Sorry to bother you, but I have been struggling to use Python to connect to the AWS PostgreSQL database based on this instruction https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.Connecting.Python.html, as it always displays timeout error.
I have also set up a config file in ~/.aws folder to configure the boto3, with the following:
[default]
aws_access_key_id = X
aws_secret_access_key = X
import os
import boto3
import psycopg2
ENDPOINT="url"
PORT="5432"
USR="kaggle"
REGION="us-east-2a"
os.environ['LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN'] = '1'
session = boto3.Session(profile_name='default')
client = boto3.client('rds',region_name=REGION)
token = client.generate_db_auth_token(DBHostname=ENDPOINT, Port=PORT, DBUsername=USR, Region=REGION)
try:
conn = psycopg2.connect(host=ENDPOINT, port=PORT, user=USR, password=token)
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))
The error is:
Database connection failed due to could not connect to server: Connection timed out (0x0000274C/10060)
Is the server running on host "url" (IP) and accepting
TCP/IP connections on port 5432?
Upvotes: 1
Views: 3580
Reputation: 269081
It appears your scenario is:
Publicly Accessible = Yes
Things to check:
0.0.0.0/0
(but that is bad from a security perspective)Upvotes: 1