跨 VPC 对等使用来自不同 VPC 的 AWS Nat Gateway

Ond*_*idr 2 routing amazon-web-services amazon-vpc vpc-peering amazon-nat-gateway

我想使用另一个 VPC 的 Nat 网关(不是 EC2 上的 Nat 实例!)将我的流量从对等 VPC 路由到 Internet。我的基础设施如下所示:

/---------------------VPC-LIVECHAT---------------------\
| /---Subnet A---\  /---Subnet B---\  /---Subnet C---\ |
| |              |  |              |  |              | |
| \-10.10.0.0/24-/  \-10.10.1.0/24-/  \-10.10.2.0/24-/ |
\------------------------------------------------------/
               |                        |
               | VPC Peering Connection |
               |                        |
/----------------------VPC-COMMON----------------------\
| /---Subnet A---\  /---Subnet B---\  /---Subnet C---\ |
| |  /--------\  |  |  /--------\  |  |  /--------\  | |
| |  | NAT GW |  |  |  | NAT GW |  |  |  | NAT GW |  | |
| |  \--------/  |  |  \--------/  |  |  \--------/  | |
| \-10.10.3.0/24-/  \-10.10.4.0/24-/  \-10.10.5.0/24-/ |
\------------------------------------------------------/
               |                        |
               | VPC Peering Connection |
               |                        |
/---------------------VPC-DATABASE---------------------\
| /---Subnet A---\  /---Subnet B---\  /---Subnet C---\ |
| |              |  |              |  |              | |
| \-10.10.6.0/24-/  \-10.10.7.0/24-/  \-10.10.8.0/24-/ |
\------------------------------------------------------/
Run Code Online (Sandbox Code Playgroud)

我的点子:

  • 我将在每个子网中设置带有子网和 Nat 网关的 VPC-COMMON(每个可用区一个子网)
  • 我将设置 VPC-LIVECHAT 和 VPC-DATABASE VPC,创建 VPC Peering 连接
  • 在 VPC-COMMON 子网中将有路由 0.0.0.0/0 -> Nat Gateway 在同一子网中
  • 在 VPC-LIVECHAT 和 VPC-DATABASE 子网(所有)中将有路由 VPC-COMMON CIDR -> VPC Peering Connection
  • 在 VPC-LIVECHAT 和 VPC-DATABASE 的每个子网中都会有路由 0.0.0.0/ -> VPC-COMMON 对应子网中的 Nat 网关(子网 A 将在 VPC-COMMON 子网 A 中使用 NAT GW 等等...)

我认为这个设置应该工作得很好,它只是路由 VLAN。但不是在 AWS 中。AWS 不希望我在路由表中的不同 VPC 中使用 Nat Gateway 并出现错误

“路由表 rtb-293fa54d 和接口 interface-c2002e9e 属于不同的网络”

我也不能在 AWS 中使用 Nat Gateway 的私有 IP,AWS 不支持路由目标中的 IP 地址(我真的很想知道为什么)。

我正在使用 CloudFormation,我的路由定义如下所示:

"RoutePrivate3ToNatInCommon" : {
    "Type" : "AWS::EC2::Route",
    "Condition" : "IsNotVpcCommon",
    "Properties" : {
        "DestinationCidrBlock" : "0.0.0.0/0",
        "RouteTableId" : { "Ref" : "PrivateSubnet3RoutingTable" },
        "NatGatewayId" : { "Fn::GetAtt" : [ "NatGatewaySettingsForNotCommon", "NatGatewayAZC" ] }
    }
}
Run Code Online (Sandbox Code Playgroud)

NatGatewaySettingForNotCommon 是我的自定义 lambda 支持的资源,它帮助我获取每个可用区的 Nat 网关列表。

有什么办法可以实现这个设置吗?每个区域我将有大约 10 个 VPC,每个区域有 3 个私有子网,我真的不想设置(并支付)30 个 Nat 网关。这看起来像常规的“非多云”网络设置,因此在云中实现它应该没有问题。或者是吗?

Mat*_*ser 6

AWS 不支持这种类型的配置。VPC 对等互连不支持“多跳”路由。VPC 对等不支持以下配置。

  • VPC A -> VPC B -> 互联网
  • VPC A -> VPC B -> VPC C

参考:无效的 VPC 对等连接配置