ConorIsAMelon
ConorIsAMelon

Reputation: 59

Is there a way to assign one static elastic IP to multiple instances?

Is there anyway that many ec2 instances can share the same IP? So that all outbound API requests from the ec2 instances, are coming from the same IP address? If the API provider were to whitelist the single static IP address, it would grant access to all of the instances.

Any ideas would be great!

Upvotes: 0

Views: 1751

Answers (1)

Jason
Jason

Reputation: 2695

If this is for outbound only, then it can be achieved using a NAT Gateway.

All the EC2 instances will sit behind the public NAT Gateway, the NAT Gateway is then assigned an Elastic IP Address.

All traffic from the EC2 instances will be routed via the NAT Gateway to the Internet Gateway and the target environment will see all the traffic originating from the Elastic Ip Address assigned to the NAT Gateway.

However, if traffic must go the other way (inbound), then this architecture will not work.

UPDATE: The NAT Gateway must reside in a public subnet, that subnet will have a route 0.0.0.0/0 to the Internet Gateway. The EC2 instances will reside in a private subnet and have a route 0.0.0.0/0 to the NAT Gateway in the public subnet.

Furthermore for High Availability it is recommended that you have at least 4 subnets, 2 in 2 different Availability Zones (AZ). A NAT Gateway does not span subnets and so at least two NAT Gateways should be used one in public subnet A which resides in the first AZ and the other in public subnet B which resides in the second AZ.

The architecture would be as follows:

enter image description here

Where Routing Table A (Associated with both public subnets) has a route to the Internet Gateway i.e.

  • 10.0.0.0/16 - local
  • 0.0.0.0/0 - igw-xxxxxxxxx

Routing Table B is associated with private subnet 10.0.10.0/24 has a route to the NAT Gateway in the public subnet (10.0.0.0/24) i.e.

  • 10.0.0.0/16 - local
  • 0.0.0.0/0 - nat-123456

Routing Table C is associated with private subnet 10.0.11.0/24 has a route to the NAT Gateway in the public subnet (10.0.1.0/24) i.e. 10.0.0.0/16 local 0.0.0.0/0 nat-654321

In this architecture each NAT Gateway will have it's own Elastic IP address which means 2 IP Addresses will be visible to the target, if high availability is not important then you could use 1 NAT Gateway in one public subnet. Note that, a NAT gateway supports 5 Gbps of bandwidth and automatically scales up to 45 Gbps. If you require more bandwidth, you can split your resources into multiple subnets and create a NAT gateway in each subnet.

For more detailed information on configuring a NAT within a VPC see the following page in the docs.

Upvotes: 7

Related Questions