I want to assign a single static IP address to my load balanced AWS Elastic Beanstalk environment to identify traffic coming from it.
You can use a network address translation (NAT) gateway to map multiple IP addresses into a single, publicly exposed IP address. When your Elastic Beanstalk environment uses a NAT gateway, the backend instances in your environment are launched in private subnets. Elastic Beanstalk routes outbound traffic through the NAT gateway. You can identify the source of the outbound traffic from the backend instances by the Elastic IP address. The Elastic IP address is a static IP address required by the NAT gateway.
Elastic Beanstalk launches your Amazon Elastic Compute Cloud (Amazon EC2) instances into private subnets. These private subnets use a NAT gateway with an attached Elastic IP address as a default route. The load balancer is in public subnets. Elastic Beanstalk routes all external traffic to and from the load balancer through an internet gateway.
Important: Before getting started, set up a NAT gateway.
Open the Elastic Beanstalk console.
Choose Create New Application, and then complete the steps to create your application.
Note: If you're using an existing application, then skip to step 3 and configure your environment.
Choose Actions, and then choose Create environment.
Choose Web server environment, and then choose Select.
Choose the options in the Environment information and rest of the Platform and Application Code sections based on the needs of your environment.
Choose Configure more options.
For Configuration presets, choose High availability. This sets your environment to a load-balanced environment.
For the Network card, choose Edit, and then edit as follows:
- For VPC, choose your VPC.
- In the Load balancer settings section, for Visibility, choose Public.
- In the Load balancer subnets table, choose the public subnets.
- In the Instance settings section, clear Public IP address.
- In the Instance subnets table, choose only private subnets with the NAT gateway that you set up earlier
Choose Create environment.
The Elastic Beanstalk environment that you created now has all outbound traffic originating from a single Elastic IP address.