如何在 AWS 中创建 NAT 网关?

How to create a NAT Gateway in AWS?

所以我应该(理想情况下)为每个 AZ 创建 1 个 NAT 网关,并在每个 AZ 中关联一个私有子网。 NAT 网关采用 allocation_id:

The allocation ID of an Elastic IP address to associate with the NAT gateway. If the Elastic IP address is associated with another resource, you must first disassociate it.

EIP 附加到 an Instance or a Network Interface

那么创建 NAT 网关需要创建什么?

  1. 一个EIP...
  2. ...与实例或网络接口关联。

我关联的这个实例或网络接口是什么?不太懂。

我想象我有一堆私有子网网络服务器,它们也需要访问互联网。这些网络服务器是他们谈论的与 EIP 关联的实例吗?或者什么?

我可以只创建一个 NAT 网关和一个 EIP 而没有其他任何东西将 EIP 连接到 instance/network-interface 吗?

resource "aws_network_interface" "multi-ip" {
  subnet_id   = aws_subnet.main.id
  private_ips = ["10.0.0.10", "10.0.0.11"]
}

resource "aws_eip" "one" {
  vpc                       = true
  # WHAT IS THIS
  # WHAT NETWORK INTERFACE DO I NEED TO CREATE
  network_interface         = aws_network_interface.multi-ip.id
  associate_with_private_ip = "10.0.0.10"
}

您可以在VPC控制台中创建NAT网关。您为其指定一个 public 子网和现有(或让 AWS 创建)EIP:

然后你必须在你的私有路由中创建一个路由 table 到 NAT 创建,

并且根据您是否创建了新路由 table,您可以将路由 table 与您需要的任何私有子网相关联: