Here is my python code to connect to an rds mysql instance. I have ensured that connections are publicly accessible and have a security group named default_ that accepts all traffic from source 0.0.0.0/0. The code is giving the error Error: (2003, "Can't connect to MySQL server on 'database-2.cgsvu7bg7jl5.us-east-2.rds.amazonaws.com' (timed out)")
I do not know what to do from here because I think it should be configured. Let me know if there are any steps I can take to debug.
import pymysql
Replace with your RDS instance details
host = 'database-2.extra_info.rds.amazonaws.com'
user = 'admin'
password = 'my_password'
database = 'test'
try:
# Establish a connection to the database
connection = pymysql.connect(host=host, user=user, password=password, database=database)
# Create a cursor object to interact with the database
with connection.cursor() as cursor:
# Execute SQL queries or database operations here
# Example: Execute a SELECT query
cursor.execute("SELECT * FROM your_table_name")
results = cursor.fetchall()
for row in results:
print(row)
except Exception as e:
print("Error: {}".format(e))
finally:
# Close the database connection when done
connection.close()
How would I connect an existing vpc that has an internet gateway (currently using for an ec2 environment) to the rds?