EC2 Instance Connection of RDS DB

0

I made an RDS MYSQL database and am trying to connect it to mysql workbench. I am getting the error Failed to Connect to MySQL at database...amazonaws.com:3306 with user admin. I have gone through the steps of ensuring it is Publicly accessible and adding a security rule with my http://checkip.amazonaws.com/ host ip to rds-ec2. I am wondering what further steps I can do to ensure that I would be able to mysql workbench

1 Antwort
0

Hello.

Is the subnet used by RDS a public subnet?
Even if public access is enabled in RDS, access will fail if the instance is not launched in a public subnet.

Additionally, enabling public access is not recommended for security reasons.
Therefore, I think it is better to connect using port forwarding using the functionality of Systems Manager Session Manager as described in the following document.
https://aws.amazon.com/jp/blogs/mt/use-port-forwarding-in-aws-systems-manager-session-manager-to-connect-to-remote-hosts/

profile picture
EXPERTE
beantwortet vor 6 Monaten
  • Hi Riku, thank you for your response. I believe I was able to connect using ssh connection in mysql workbench. Will this still cause a similar problem, will I need to do this to connect to python code

  • Is it possible for you to summarize what you are currently trying to do and what you cannot do? Am I correct in my understanding that you cannot connect to RDS with mysql workbench? Could you please share what code you are using in Python and what error you are getting?

  • Yes. I am trying to connect to python and this is the code I am using import pymysql

    Replace with your RDS instance details

    host = 'database-2..rds.amazonaws.com' user = 'admin' 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()

    I am getting the error Error: (2003, "Can't connect to MySQL server on 'database-2.us-east-2.rds.amazonaws.com' (timed out)")

    I have a vpc called db-vpc with a route from destination (0.0.0.0/0) to target an internet gateway called db-igw which is also attached to to the db-vpc. I then have an rds connected to db-vpc that is publicly accessible and has a vpc security group called default_ which contains an inbound rule of type all traffic from source 0.0.0.0/0

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen