How do I assign a static source IP address for all instances in a load balanced Elastic Beanstalk environment?
Last updated: 2020-06-25
I want to assign a single static IP address to my load balanced AWS Elastic Beanstalk environment. Then, I want to use that IP address to uniquely identify traffic coming from the Elastic Beanstalk environment.
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, which is a static IP address required by the NAT gateway.
In the following steps, Elastic Beanstalk launches your Amazon Elastic Compute Cloud (Amazon EC2) instances into private subnets that use a NAT gateway with an attached Elastic IP address, as a default route. The load balancer is in public subnets, and 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, 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 Base configuration 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 Modify.
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 Save.
- Choose Create environment.
The Elastic Beanstalk environment that you created now has all outbound traffic originating from a single Elastic IP address.