简体   繁体   中英

Connecting AWS EC2 API to AWS RDS on same VPC, works externally

New to AWS, and I am attempting to connect an API on my EC2 instance with my RDS. Attempts return a 500 Error

What I am able to do successfully:

Connect to the RDS with an API hosted on an external server. Run API's on my EC2 instance, just not ones that connect to database.

What solutions I have attempted: Added new MYSQL/Aurora Inbound and Outbound rules to include: EC2 Private IPv4 Address/32 EC2 Public IPv4/32 EC2 Security Group

Because I can reach the database externally and run PHP scripts on the server, I am leading that the issue is with the EC2 Connecting with the RDS though I am sure it could be something else.

*I am using PHP APIs to connect to MySQL RDS

Thank you for your time and assistance.

If you connect the same way as the external server (maybe via port 3306) then the EC2 should connect via port 3306 too.

If your security group is blocking port 3306, and you are connecting via the public endpoint, then you may not be able to connect to the database.

I recommend disabling public port 3306 access on the RDS, and only allow "internal" IP address to access the database via port 3306, that way you can configure the EC2 to access the RDS using the internal IP address.

By internal I mean the LAN IP of the RDS, assuming they are in the same VPC and AZ (cross AZ can be allowed too, just depends on how you set it up).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM