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?
Publicly Accessible = Yes? Have you been able to connect to the database in any other way (eg using an SQL client)?telnet endpointUrl 5432. Also in the RDS's security group, make sure that your public ip address is allowed in the In Bound rules