Search code examples
amazon-web-servicesgoogle-cloud-platformgoogle-cloud-sqlgoogle-cloud-vpnaws-vpn

Connecting an AWS EC2 to a Google Cloud SQL instance locally using VPN Gateway


I have an AWS account with an EC2 in it that I am trying to connect to a Cloud SQL Server (MySQL 5.6) inside of Google Cloud Platform.

I have successfully set up a VPN between AWS and GCP and can echo a message over nc between an ec2 on AWS and a vm on GCP.

As GCP managed DB's are not placed inside of a VPC of my choosing I followed this guide to give the DB a private IP and to then peer that with my google VPC. I tested this works by accessing the DB via pymsql from an VM in GCP using the private IP of the DB.

However my issues come from connecting the EC2 inside of AWS to the Cloud SQL DB in the same way, I have followed this guide to allow the use of the DB's private IP from an external source but I seem to be getting stuck with how to set the routing up to the peered network the DB is sitting in using AWS Routing.


Solution

  • The problem has been sorted!

    In the Advertised routes Settings of my Cloud Router, I had misunderstood the function of Advertise all subnets visible to the Cloud Router (Default) I needed to instead choose Create custom routes" And then the sub-option Advertise all subnets visible to the Cloud Router.

    This then allowed me to add the Cloud SQL subnet to my router to that IP block propagate over to AWS.