- Newest
- Most votes
- Most comments
Hello,
Based on what you’ve shared, one simple approach could be to use a Network Load Balancer. You can configure it to forward traffic on ports 80 and 443 to your application EC2, while directing traffic on the other port to the second EC2.
Some docs:
- What is a Network load Balancer? (https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html)
- How to create a target group? (https://docs.aws.amazon.com/elasticloadbalancing/latest/network/create-target-group.html)
Hope that helps! 😊
To achieve the architecture you're describing with one public Elastic IP (EIP) and multiple EC2 instances with routing based on ports, you'll need to use a combination of AWS services. Here's a recommended approach:
-
Elastic IP (EIP): Allocate one EIP to serve as your static public IP address.
-
Network Load Balancer (NLB): Use an NLB as your entry point. NLBs operate at the transport layer (TCP/SSL) and can route traffic based on ports. They also support Elastic IP addresses.
-
EC2 Instances: Set up your EC2 instances as described - one for HTTP/HTTPS traffic and another for your application endpoints.
-
Target Groups: Create separate target groups for each EC2 instance.
-
Listener Rules: Configure listener rules on the NLB to route traffic based on the incoming port:
- Route traffic on ports 80 and 443 to the target group containing your HTTP/HTTPS EC2 instance.
- Route traffic on port 1234 (and any other specific ports) to the target group containing your application endpoint EC2 instance.
-
Security Groups: Configure appropriate security groups for your EC2 instances to allow incoming traffic on the necessary ports.
-
VPC and Subnets: Ensure your NLB and EC2 instances are in the same VPC, with the NLB in public subnets and EC2 instances in private subnets for enhanced security.
This setup allows you to use a single Elastic IP while routing traffic to different EC2 instances based on the incoming port. The Network Load Balancer will handle the routing, and you can easily scale by adding more instances to the target groups as needed.
Remember to consider high availability by deploying your EC2 instances across multiple Availability Zones and configuring your NLB to be multi-AZ as well.
Sources
Use a Network Load Balancer for Amazon ECS - Amazon Elastic Container Service
Second PUBLIC IPv4 Address Associated in one Instance | AWS re:Post
Relevant content
- AWS OFFICIALUpdated 4 years ago
