- Newest
- Most votes
- Most comments
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
Relevant content
- asked 6 months ago
- asked 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
thank you for your answer, Just to be more clear on the approach with "ECS Service with Task Count".
Are you pointing to the number of tasks which can be run at a time in the cluster which is "base" configuration in Cluster CapacityProviderStrategyItem https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ecs-cluster-capacityproviderstrategyitem.html
Or you are saying I should change in service "DesiredCount" https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ecs-service.html#cfn-ecs-service-desiredcount
I only want that n number of tasks should run concurrently in a cluster and other messages should wait in SQS, when one of the task in complete in ECS then the next message should trigger the ECS service.