Mysql – Connect to MySQL EC2 Instance outside of VPC

amazon ec2amazon-vpcdatabaseMySQL

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!

Best Answer

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.