Static IP using Elastic Beanstalk
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Overview
Amazon Elastic Beanstalk is a service offered by AWS to easily deploy and manage applications in the cloud. While it simplifies the deployment process significantly, Elastic Beanstalk environments do not directly support static IP addresses out of the box. A static IP is crucial for scenarios where you need to whitelist IPs, establish dedicated VPN connections, or meet regulatory requirements.
Why Static IPs?
Static IP addresses can provide several benefits:
- Consistency: The IP address remains constant, providing a reliable endpoint.
- Security: Whitelisting a fixed set of IPs reduces the attack surface.
- Compliance: Certain industry regulations may require fixed IP addresses.
Challenges with Static IPs in Elastic Beanstalk
Elastic Beanstalk manages its environment by automatically scaling resources, thereby changing IP addresses. This dynamic nature conflicts with the requirement for a static IP. However, there are ways to work around this limitation.
Implementing Static IP for Elastic Beanstalk
Use an Elastic Load Balancer (ELB) with VPC Peering
- Set Up a VPC: Create a Virtual Private Cloud to host your Elastic Beanstalk environment.
- Create an ELB: Set up an Elastic Load Balancer associated with your VPC.
- Associate Elastic IP: AWS allows the association of an Elastic IP with a Network Load Balancer (NLB). Attach an NLB to your Elastic Beanstalk environment.
- VPC Peering: If necessary, establish a VPC peering connection between your environment and other AWS services or external networks.
Utilize AWS Global Accelerator
AWS Global Accelerator can be used for assigning a fixed IP by routing traffic to your Elastic Beanstalk environment:
- Setup Accelerator: Create an AWS Global Accelerator.
- Point to ELB: Route traffic from the accelerator to your Elastic Load Balancer (ELB).
- Get Fixed IPs: AWS Global Accelerator provides two static IP addresses that can be used to interact with your Elastic Load Balancer.
Leverage AWS Lambda and API Gateway
Another indirect method involves using AWS Lambda functions with API Gateway:
- Create Lambda Functions: Set up an AWS Lambda function as a proxy to your Elastic Beanstalk environment.
- Configure API Gateway: Use API Gateway to manage requests and ensure a static endpoint, associating a fixed IP with your API Gateway to serve traffic to your Lambda function.
Example Implementation Using NLB
Below is a configuration for associating a static IP using a Network Load Balancer:
- !Ref SubnetId1
- !Ref SubnetId2
- Key: "load_balancing.cross_zone.enabled"
- The Network Load Balancer (NLB) is specified to distribute traffic across multiple instances.
- Elastic IP (EIP) is allocated, and an association defines the link between the EIP and the NLB.
- Monitor Costs: AWS services like Global Accelerator and Elastic IP can incur additional costs. Monitor your resources and evaluate the cost benefits.
- Infrastructure as Code: Use CloudFormation or Terraform scripts to manage your infrastructure setup.
- Security Groups: Ensure that your VPC and ELB security groups are configured to allow necessary inbound and outbound traffic.
- Testing: Extensively test your setup on a development environment before deploying to production to avoid disruptions.
Related reading
- Static outbound IP for AWS ECS Fargate task
- Static outgoing IP in Kubernetes
- Static outgoing IP in Kubernetes
- Static web hosting on AWS S3 giving me 403 permission denied
- Stop Wasting Money on CORS Preflight Requests: A Detailed Guide to API Cost Optimization
- Strange issue with System.Net.Http 4.2.0.0 not found
- Stopping and starting a deep learning google cloud VM instance causes tensorflow to stop recognizing GPU
- Store your events directly from kafka into database?, when or why using S3/HDFS before?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.