0

I have a VPC setup with a few EC2 instances inside. I'm attempting to connect to a MySQL database on an EC2 instance outside the VPC, with no luck.

I have the security groups on the VPC EC2 instances set to outbound 0.0.0.0/0 which I assumed would let it connect to any outbound connection. I also followed a tutorial on creating a NAT, but wasn't exactly sure how to use it to connect to an external database.

In any case, if anyone has experience and knows the proper way to connect to a database outside the VPC, it would be greatly appreciated!

1

You need to set the Security Group to allow inbound connections over port 3306 (or whatever port you configured) to your destination.

If it's from your workstation, then you would need to get your public IP (ie go to whatismyip.com) and allow that.

Example:
INBOUND:
3306 TCP from Destination 10.10.10.10/32

I would recommend NOT using 0.0.0.0/0 as that will allow ANYONE to access your MYSQL database.

If you're feeling adventurous, you can configure a site to site VPN from your office to the VPC and communicate over private IP's. This is the more secure and preferred method.

  • Just for clarification sake, what I had to do was allow inbound connections on the MySQL instance over port 3306 and used the public IP address to connect to it from the EC2 instance inside the VPC. Thanks. – Brian Weinreich Oct 21 '13 at 20:39
0

From the perspective of a VPC, EC2 instances are like servers anywhere else on the Internet. Thus, to reach them, you need to use a NAT server or associate an EIP with the VPC instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.