2

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

Leonti
  • 171
  • 3

3 Answers3

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.

Tim
  • 30,383
  • 6
  • 47
  • 77
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
Student
  • 101
  • 1
0

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.

Andrey
  • 548
  • 2
  • 8