Scheduled Tasks on ECS Fargate

An alternative to scheduled tasks for unsupported regions for ECS Fargate

Posted by Ricardo Trindade on February 9, 2019

This one provides an alternative to scheduled tasks for applications running ECS Fargate.

To schedule a task to run at a specific time you can use CloudWatch events (e.g. data collection, analyze payments, generate some report).

On the AWS console, it looks something like the image below.

Scheduled tasks image

You can use the containerOverrides command to make run the specific task and scheduled it with a regular cron expression.

However, if your application is running on (us-west-1, ap-south-1, ap-northeast-2, and eu-west-2) this is still not supported.

Click here for more information

A possible workaround (not so elegant though), is to use AWS Lambda to trigger the task for you.

The gist below is adapted for a rails application, that I've built in Python for the simplicity of having boto3 already included on Lambda. Feel free to adapt it to your needs.

Now that the lambda is assembled you can trigger it to run it with CloudWatch events.

cloud watch example

And there you have it, an alternative to run scheduled tasks while AWS doesn't provide support for all regions on Fargate.

So what did you think of it? Hit me up on Twitter with your thoughts and opinions.