1

I have an AWS ECS cluster whose only purpose is to run a scheduled task every 12 hours. Currently, I leave the cluster scaled to 1 instance so the task has somewhere to run. I would instead like to leave the cluster at 0 instances and configure it to auto-scale up to 1 instance when the scheduled task runs, then back down to 0 when the task finishes.

My research indicates that ECS auto-scaling is typically used to scale instances according to metrics such as resource utilization, so what I want may not be possible. The closest solution I've found is to create a scheduled action for the auto-scaling group, as described here; I could schedule the cluster to scale up every 12 hours, just before the scheduled task runs, though I'm not sure how I would ensure that the cluster only scales back down after the task finishes. (This is essentially the solution suggested by this answer, but it's over two years old and I'm hoping the situation has changed to allow what I want.)

So ideally, the cluster should scale in response to the scheduled task itself. Is this possible?

jth
  • 11
  • 2

2 Answers2

1

Can you run the task in a Fargate container?

With Fargate you don't have to run and manage any EC2 instances, simply schedule the job to run in Fargate and be done with it. It runs standard docker images, same as on your EC2-based ECS cluster. The only limitation is that it can't do any privileged operations like mounting network filesystems or spawning child containers. But if you don't need that you should seriously consider it.

Hope that helps :)

MLu
  • 23,798
  • 5
  • 54
  • 81
  • Thanks for the suggestion. Unfortunately it appears that a Fargate task is limited to 10 GB storage (see [Amazon ECS Service Limits](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_limits.html)), and my task requires much more than that (probably 500 GB to be safe). – jth Aug 20 '19 at 01:12
0

As you say you need 500GB of storage you may consider orchestrating it through AWS Step Function. Trigger the Step Function every 12 hours and every time it does the following:

  1. Create AWS Batch job, specifying the instance type and disk space required. You can even use Spot instances to reduce cost.

  2. Wait until the job is completed.

  3. Report success / retry on failure.

In the Step Functions console there actually is a sample project Manage a batch job that does exactly that.

Alternatively you can do the same without AWS Batch if you want and create a custom Lambda function to spin up the instance, wait for success, start the task, wait for success, tear down the instance, wait for success. But you may just as well use Batch to do all that for you.

Hope that helps :)

MLu
  • 23,798
  • 5
  • 54
  • 81
  • Thank you for suggesting an alternative solution. I've run out of time to work on this issue right now, but hopefully I will return to it at some point in the future, and I will revisit this thread when I do. – jth Aug 22 '19 at 20:28