AWS - 如何连接两个不同区域的两个 EC2 实例?

AWS - how to connect two EC2 instances in two different regions?

我正在使用 AWS EC2(还没有其他 AWS 服务),并且我有这个设置:

Region 1 (N. Virginia): instance A, in VPC YYY, has public IP 123
Region 2 (S. Paulo   ): instance B, in VPC ZZZ, has public IP 456

我需要从实例 B 向实例 A 发出 TCP 请求。

一开始以为只需要将实例B的publicIP(456)加入实例A的安全组即可,但是不行(无法建立TCP连接如我所料)。

我猜想,在区域之间,当一个实例试图访问另一个实例时使用不同于 de public 的另一个 IP,而不是私有 IP,因为私有 IP 是 VPC 本地的(对吧?)。

那么,如何实现呢?我应该在实例 A 的安全 group/firewall 中将哪个 IP 列入白名单?

或者,一般而言,执行此操作的最佳做​​法是什么? (连接它们之间不同Regions/VPC的两个实例)。

谢谢!

在不知道您的 VPC 配置的情况下,很难发表评论。您的实例 B 很可能位于 VPC 的私有子网中。假设你是 运行 Linux,你能从 B ping www.google.com 吗?如果可以,那么 curl www.whatsmyip.com 会给你 B 的 public 地址(在 curl 输出中搜索 IP)。使用该 IP 打开 A 的安全组以允许来自 B 的流量。

现在您可以让不同区域的 ec2 实例通过私有 IP 地址进行通信,设置 inter-region VPC 对等。

如官方 AWS 中所述 documentation:

You can establish peering relationships between VPCs across different AWS Regions (also called inter-Region VPC peering). This allows VPC resources including EC2 instances, Amazon RDS databases and Lambda functions that run in different AWS Regions to communicate with each other using private IP addresses, without requiring gateways, VPN connections, or separate network appliances. The traffic remains in the private IP space. All inter-region traffic is encrypted with no single point of failure, or bandwidth bottleneck. Traffic always stays on the global AWS backbone, and never traverses the public internet, which reduces threats, such as common exploits, and DDoS attacks. Inter-Region VPC Peering provides a simple and cost-effective way to share resources between regions or replicate data for geographic redundancy.