DEV Community

SteveJin
SteveJin

Posted on • Updated on

SWS Console: Routing multiple private EC2 instances to AWS ALB.

In a previous post related to EC2 DMS, I created a feature that I had discussed with a colleague. As I began exploring technical discussions in online communities, I noticed that people deploying projects on EC2 instances were grappling with similar concerns. One of the challenging concepts that emerged was the configuration of a single ALB to route traffic to multiple instances.

To make this clearer, I'll explain using the image below.

Image description

The scenario is as follows: Let's assume we are implementing Microservices Architecture (MSA) by deploying payment, logging, and product servers on separate EC2 instances. The crucial aspect here is to route traffic to the appropriate server when a request comes to a single ALB, ensuring that requests reach the intended server.

The limitation of the existing EC2 DMS setup was that it was implemented with a one-to-one mapping of API servers to ALBs. Consequently, the target group rules were broadly defined, directing all requests to a single EC2 instance.

Visit the Steve Web Service homepage

Visit EC2 DMS Documentation

To address this issue with EC2 DMS, we devised the following flow, as depicted in the image below:

Image description

  1. SWS Project (VPC) is selected.

  2. Select NEW ALB.

  3. Choose CUSTOM for Target Path Pattern and input rules. In this case, users set the prefix path for each server's controller, and specify the rule accordingly. For example, if a request starts with /api/payment, it will be routed to the payment EC2 instance.

  4. Enter the Target Health Check Path. For instance, if the path /api/payment/health is requested, a simple text such as "OK" should be displayed without any authentication or authorization checks.

  5. Target Priority determines the priority, ranging from 1 to 999. Higher numbers indicate lower priority.

  6. The rest follows the creation process of EC2 DMS. → Go directly to EC2 DMS creation method.

We implemented the above idea, ultimately assisting people in routing traffic to multiple instances on a single ALB through EC2 DMS. By simply selecting the target ALB and following the same process, we could help route traffic to multiple instances on a single ALB.

If users were to set up the above process manually, they would need to learn various aspects, from creating ALBs to setting path patterns in target groups.

However, achieving our goal with just these settings seems straightforward, doesn't it?

Visit the Steve Web Service homepage

Go to the documentation on routing multiple instances to an ALB with EC2 DMS

We will continue to create tools that enable users to build cloud architectures without extensive AWS Cloud knowledge, allowing developers to focus more on business needs. Furthermore, we aim to provide value so that even small development teams can make the most of AWS resources.

Our next article will address another problem-solving history. End.

Visit the Steve Web Service homepage

Image description

Top comments (0)