Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Schedule Docker image to be run periodically on AWS ECS?

How do I schedule a docker image to be run periodically (hourly) using ECS and without having to use a continually running EC2 instance + cron? I have a docker image containing third party binaries and the python project.

The latter approach is not viable long-term as it's expensive for the instance to be running 24/7, while only being used for a small fraction of the day given invocation of the script only lasts ~3 minutes.

like image 626
Sean Pianka Avatar asked May 11 '18 17:05

Sean Pianka


1 Answers

For AWS ECS cluster, it is recommended to have atleast 1 EC2 server running 24x7. Have you looked at AWS Fargate whether it can run your docker container?. Also AWS Batch?. If Fargate and AWS Batch are not possible then for your requirement, I would recommend something like this without ECS.

  1. Build an EC2 AMI with pre-built docker and required softwares and libraries.

  2. Have AWS Instance Scheduler to spin up a EC2 server every hour and as part of user data, start a docker container with image you mentioned. https://aws.amazon.com/answers/infrastructure-management/instance-scheduler/

  3. If you know your task execution time maybe 5min. After 8 or 10min then bring server down with scheduler.

Above approach will blindly start a EC2 and stop it without knowing whether your python work is done successfully. We can still improve above with Lambda and CloudFormation templates combination. Let me know your thoughts :)

like image 141
Imran Avatar answered Oct 20 '22 13:10

Imran