1 Answer
- Newest
- Most votes
- Most comments
0
Could you please provide more context on how you are using EventBridge to launch the ECS task, as well as information on the ECS infrastructure (EC2 or Fargate launch type)?
Typically, limiting the number of tasks running at a time will involve running the task within a service with auto-scaling settings. For example, the service could have a minimum of 0 tasks and a maximum of 10, and use a scaling policy based on the size of the SQS queue. A similar approach can be seen here: https://serverlessland.com/patterns/eventbridge-sqs-ecs-cdk?ref=search Another example discussing ECS auto-scaling here: https://aws.amazon.com/blogs/containers/amazon-elastic-container-service-ecs-auto-scaling-using-custom-metrics/
answered 6 months ago
Relevant content
- asked 6 months ago
- Accepted Answerasked 6 months ago
- asked a month ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 4 months ago
- AWS OFFICIALUpdated 2 years ago
I have an event bridge which triggers an ECS task when a message comes in SQS. So everytime a message comes in SQS it will trigger an ECS task. So i wanted to limit the number of tasks running concurrently so to manage the resources of ECS Fargate service.
There is currently no native way to manage the max concurrency of ECS tasks being launched in a cluster from an EventBridge rule. It should be possible to re-architect the solution to operate in a manner similar to what is described in the serverlessland linked pattern: Create an ECS service with autoscaling (minimum 0, maximum 10) and set scaling policies based on the length of the SQS queue. In this way, as items are added to the queue, a 1:1 relationship of running tasks to queue messages will exist up to a maximum of 10 tasks.