Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
375 views
in Technique[技术] by (71.8m points)

amazon web services - 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...