I have implemented the Job Observer Pattern using SQS and ECS. Job descriptions are pushed to the SQS queue for processing. The job processing run on an ECS Cluster within an Auto-Scaling Group running ECS Docker Tasks.
Each ECS Task does:
I would like to scale down the cluster when there is no more work for each Instance, eventually to zero instances.
Looking at this similar post, the answers suggest scale-in would need to be handled outside of ASG in some way. Instances would self-scale-in, either by explicitly self-terminating or by toggling ASG Instance Protection off when there are no more messages.
This also doesn't handle the case of running multiple ECS Tasks on a single instance, as an individual task shouldn't terminate if other Tasks are running in parallel.
Am I limited to self scale-in and only one Task per Instance? Any way to only terminate once all ECS Tasks on an instance have exited? Any other scale-in alternatives?
Yes, you can set desire count to zero once the process complete, but there are few things that you need to consider. entrypoint that will deal with nodejs process and set service count to 0 when the nodejs process completed from SQS.
If you specify scaling policies, then Amazon EC2 Auto Scaling can launch or terminate instances as demand on your application increases or decreases. For example, the following Auto Scaling group has a minimum size of one instance, a desired capacity of two instances, and a maximum size of four instances.
You can use an instance refresh to update the instances in your Auto Scaling group instead of manually replacing instances a few at a time. This can be useful when a configuration change requires you to replace instances, and you have a large number of instances in your Auto Scaling group.
Amazon ECS uses the target capacity value to manage the CloudWatch metric the service creates to facilitate cluster auto scaling. Amazon ECS manages the CloudWatch metric, so that the Auto Scaling group is treated as a steady state so that no scaling action is required. The values can be from 0-100%.
Another solution for the problem is the AWS Batch service announced at the end of 2016.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With