How to run cron job in AWS EBS worker tier?

Elastic Beanstalk a product in Amazon Web Services (AWS), which gives you the ability to deploy applications with ease, auto-scale as you need to and you can tune and tweak however should you ever want to.

We use EBS at Mallow, and one issue that comes up frequently is how to run scheduled background tasks or jobs in an EBS environment. In this post, we’ll explore how to set up scheduled tasks using the cron.yaml configuration file in an EBS Worker Tier environment.

Running cron job in AWS is simple and easy. There is no need for any external tools, for all types of application(ruby, python, node.js, etc)

Include cron.yaml with following content into project root path. The worker automatically executes job from this file

version: 1
cron:
— name: “job-name”
     url: “/path-to post method”
     schedule: “* * * * *”

* name – is unique for each job
* url – app method to send HTTP post request
* schedule – cron expression for time to execute(in this example the job executed every minute)

  • You can configure multiple cron job in one file with unique names.
  • If you want to update cron, you can update and re-deploy your application it will automatically updates. Successfull cron deployment logs in  INFO event in environement log. You can find cron logs in cron.log file

If you need multiple cron jobs, you can do this by having multiple blocks in the cron section of this file.

Note:

1. It will be executed based on the UTC time zone. If you need to adjust time to your time zone if needed.

2. It executes messages from SQS queue. If there are large number of messages in the queue, then process will delay. So AWS recommends separate worker for this.

3. Exclude cron post method from your web tier, otherwise it leads un restrickted post request.

4. Careful while copying cron.yaml file from AWS site, some characters might get included instead of ‘-‘.

Thanks for reading.

Prakash S,
ROR Developer,
Mallow Technologies.

Leave a Comment

Your email address will not be published. Required fields are marked *