使用 VPN 网关在本地将 AWS EC2 连接到 Google 云 SQL 实例

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

我有一个带有 EC2 的 AWS 帐户,我正在尝试连接到 Google 云平台内的云 SQL 服务器(MySQL 5.6)。

我已经在 AWS 和 GCP 之间成功设置了 VPN,并且可以在 AWS 上的 ec2 和 GCP 上的虚拟机之间通过 nc 回显消息。

由于 GCP 管理的数据库未放置在我选择的 VPC 内,我按照 this 指南为数据库提供私有 IP,然后将其与我的 google VPC 对等。我通过使用数据库的私有 IP 从 GCP 中的虚拟机通过 pymsql 访问数据库来测试这项工作。

然而,我的问题来自于以相同的方式将 AWS 内部的 EC2 连接到云 SQL 数据库,我遵循了 this 指南以允许从外部来源,但我似乎对如何使用 AWS 路由将路由设置到数据库所在的对等网络感到困惑。

问题已解决!

在我的云路由器的Advertised routes Settings中,我误解了Advertise all subnets visible to the Cloud Router (Default)的功能 我需要改为选择 Create custom routes" And then the sub-option Advertise all subnets visible to the Cloud Router.

这让我可以将 Cloud SQL 子网添加到我的路由器,以便该 IP 块传播到 AWS。