4

I currently have a Fargate cluster that contains a service. This service always has 1 task running and is polling from SQS. The service will scale the number of tasks if SQS grows/shrinks. However, the task has a lot of idle time, where there are no messages in the queue. To save on costs, is it possible to make the service go down to 0 task?

I have been trying to do this and the service will always try to start at least 1 task.

If this is not possible, then would it be best practice for me to not use a service and have a CloudWatch alarm on SQS and just create a task directly in the cluster when the size is greater than 0, and then shut down the task when the SQS is back to 0? Essentially mimicking the functionality of a service.

Gary Holiday
  • 3,297
  • 3
  • 31
  • 72
  • I think its possible. I remember having similar issue. I solved (I think I solved it) by using [step scaling policy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-applicationautoscaling-scalingpolicy-stepscalingpolicyconfiguration.html) with `ExactCapacity` as `AdjustmentType` type. When value of messages in queue was 0 the `ExactCapacity` was 0. – Marcin Apr 22 '20 at 06:09
  • https://stackoverflow.com/a/62721171/3288890 that might help – Adiii Jul 04 '20 at 02:25

1 Answers1

0

Yes you can. You can also use a Target Tracking Policy that allow you to scale more efficiently than a Step Scaling Policy.

See https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-using-sqs-queue.html for more details (it's about EC2 but works for ECS as well).

Fabien Roussel
  • 225
  • 1
  • 4
  • 10