4

I have a small job in docker (10 minutes) which I want to run daily in the morning.
What I'd like to achive from AWS is this:
1. Start EC2 instance.
2. Run my docker job.
3. Shutdown EC2 instance.

What I tried so far:
- Created an ECS task.
- Created an ECS cluster with 1 machine to run the task.

I can run the task manually and it works. ECS also allows you too have scheduled tasks which is perfect.
The only issue is that EC2 instance is still running all the time.
I can scale it down to 0 instances manually, but I'm looking for a way too scale it down automatically and scale it up till run the task.

What would be the best/easiest way to achieve it?

Cheers,
Leonti

1
  • Does the task need to complete or shutting it down directly would work? Jun 20, 2019 at 11:51

3 Answers 3

1

You can add scheduled actions in AutoScale groups.

http://docs.aws.amazon.com/autoscaling/latest/userguide/schedule_time.html

So this will allow you to create and destroy EC2 instances on schedule. Just make sure you configure your AMIs to join the right ECS cluster and leave some overlap time for the instance to boot and join the cluster before your scheduled ECS task starts.

Hope this helps.

1
  • How to specify that task should run just 10 mins and after that shutdown ? Nov 9, 2017 at 17:08
1

This is a 2017 question that has popped up again.

As of 2022, the best option here is to use Fargate to provision the container rather than EC2. ECS will spin up the required container on Fargate, use it as long as required, then it will be deprovisioned once the task stops.

2
  • You cannot run the privileged container in ECS Fargate Aug 15, 2023 at 15:08
  • @kamranonline can you please expand on what a privileged container is, and how a privileged container plays a part in this question?
    – Tim
    Aug 15, 2023 at 19:33
0

If you don't know how long your task will take, you can give your Docker container AWS creds and then set the desired instance count to 0 from within the container at the end of your task script:

aws autoscaling set-desired-capacity --auto-scaling-group-name YOUR_GROUP_NAME --desired-capacity 0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .