How do I assign a static source IP address for all instances in a load balanced Elastic Beanstalk environment?

Last updated: 2019-04-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. How can I do this?

Short Description

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. All outbound traffic from these instances is routed through the NAT gateway. All outbound traffic originating from your backend instances can be uniquely identified by an Elastic IP address, which is a static IP address required by the NAT gateway.

Resolution

In the following steps, your Amazon Elastic Compute Cloud (Amazon EC2) instances are launched in a private subnet that uses a NAT gateway, with an attached Elastic IP address, as a default route. The load balancer is in a public subnet, and all external traffic to and from the load balancer is routed through an internet gateway.

Note: Before getting started, set up a NAT gateway.

  1. Open the Elastic Beanstalk console.
  2. 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.
  3. Choose Actions, and then choose Create environment.
  4. Choose Web server environment, and then choose Select.
  5. Choose the options in the Environment information and Base configuration sections based on the needs of your environment.
  6. Choose Configure more options.
  7. For Configuration presets, choose High availability. This sets your environment to a load balanced environment.
  8. 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.
  9. Choose Save.
  10. Choose Create environment.

The Elastic Beanstalk environment that you created now has all outbound traffic originating from a single Elastic IP address.


Did this article help you?

Anything we could improve?


Need more help?