How can I route request from ALB to Specific ECS tsak?

0

We are running one ecs cluster. Where we have a ECS service with auto scaling enabled. Our one ECS task can handle lets say 3 processes. We know how many process is running in a ECS task. Now we want to route new request to ECS task where process is less than(<) 3. We are planning use ALB target group stickiness which route request to same target. But we want to route first request from ALB to a specific task. How can we achieve this?

Basically we need custom routing logic only for first request in ALB for a new client. Because stickiness will handle the next requests.

2 Answers
5

Hello,

I think you'll need to add an extra layer to achieve this, as your ALB alone won’t handle this logic. For example, you could use a Lambda function that checks ECS tasks for active processes, selects the task with fewer than 3 processes, and then forwards the request to the right ECS task. In front of this you will need an API Gateway to expose an HTTPS endpoint.

As for stickiness, while Lambda can manage the routing logic, it doesn’t handle stickiness directly. Stickiness is typically managed by the ALB, but you can configure your Lambda to set cookies for session persistence if needed.

Another option would be to use an ALB with your Lambda function behind it. In this setup, the ALB routes the request to Lambda, and then Lambda sends the request to the appropriate ECS task, which might make stickiness easier to manage.

Hope that helps!

profile pictureAWS
answered a month ago
profile picture
EXPERT
reviewed a month ago
0

Is there any other possible way?

answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions