By using AWS re:Post, you agree to the Terms of Use
/Fargate "idle instance"/

Fargate "idle instance"


Hi, Will I be charged for Fargate idle instance? We are going to run activity as Fargate task within a step functions. Scaling parameters

min_count=1 desire_count=1 Max_count=17 Scaling up if average CPU usage more than 50% and scaling down if usage less than 50%.

  Questions are
  • The above setup has a min and desire count =1, will we be charged for the CPU/Memory/storage usage 24 hrs a day, 7 days a week? The activity program pulls message from a SQS queue and start processing and on most part of the day, it should be idle.
  • I understand, there is aws cli command to set desire_count=0 but the messages comes in randomly over the day (i.e., we can not turn desire_count >0 during a period of time and turn it off). Is there a better way to design the system to save cost?

    Thank you.

4 Answers
Accepted Answer

You can additionally start fargate tasks via a Step Function which could be triggered via event bridge/lambda. You would not need a constantly running task in that design

answered 3 months ago

Appreciate the quick response. the task is very much CPU/Memory/Storage bound. We need to run either 2CPU 4GRAM, 100G storage to finish the file processing in 50 mins or 4CPU 8GRam 100G storage to finish processing in 25 mins.

Running Lambda with container plus EFS is not our choice because provisioned throughput cost too much and bursting throughput does not meet our processing requirement either.

With above discussion. Because the long processing time, we can totally tolerate the time to instantiate fargate from 0 count to >1 since the container seems to start pretty quickly (1-2 mins).

  • If we are able to have some process listening to some SQS queue or triggered by event bridge and set the desire_count >0 or =0. Would that be a feasible design?
  • Can you please point out some AWS ECS/Fargate java api to change desire_count? I see AWSEcsCiient and ECSAsyncClient but these classes creates services/tasks. I am looking for some API to "change" the desire_count.

All suggestions are welcome!

answered 3 months ago

Yes you will be charged at a minimal for the 1 fargate task 24/7.

However for such use cases, Lambda seems to be a better fit. Have you considered it such as using Container Images in Lambda, as shown here?

Edit --

There is currently an open request on ECS Fargate to scale to 0, which is not generally available yet.

If you have other EKS cluster, Karpenter might be able to help.

answered 3 months ago

Assuming each Task handles a single message at a time, try scaling it using the queue's ApproximateNumberOfMessagesVisible metric and allow scaling to 0. This assumes also that you can tolerate the latency that will be imposed by auto scaling.

Another option is to trigger a Lambda from the queue that will invoke a Fargate task. To make sure that you do not loose a message in case the task fails, the function can invoke a state machine in StepFunctions to run the task and retry it.

answered 3 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