What are different ways to limit the number of ECS tasks running concurrently

0

I have an architecture such that event bridge triggers the ECS task depending on the message received in SQS. It triggers the moment message is received in SQS. I want to have a limit on the total number of ECS task running concurrently in the cluster.

Please suggest some approaches to do so.

1 Answer
0
Accepted Answer

Hello.

Certainly! When you want to control the number of ECS tasks that can run concurrently in your architecture, especially when driven by external events like messages in SQS, you have a few options to implement this limit:

ECS Service with Task Count:

If you set up your tasks as an ECS Service (even if it's a short-lived task), you can control the number of desired tasks. This way, even if there are many triggers from the EventBridge, ECS will only run up to the desired count of tasks. However, you need to ensure the tasks' lifecycle fits this model.

Step Functions with Concurrency Control:

Use the Concurrency Control feature of Step Functions to limit how many of those state machine executions can be active at the same time. Trigger the state machine from EventBridge instead of directly launching the ECS task.

Use SQS Visibility Timeout and Delay:

Adjust the Visibility Timeout and/or Delay Seconds on the SQS queue to slow down the rate at which messages can be consumed. While this won't strictly limit the number of concurrent tasks, it can help reduce the chances of too many tasks being spawned at once.

Regards, Andrii

profile picture
EXPERT
answered 8 months ago
profile picture
EXPERT
reviewed 8 months 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