How can I add cron jobs to the worker tier of my Elastic Beanstalk environment and troubleshoot issues with cron jobs that won't get added?

Last updated: 2021-05-07

I want to add cron jobs to the worker tier of my AWS Elastic Beanstalk environment.


Add cron jobs to a worker tier

To add a cron job to the worker tier of your Elastic Beanstalk environment, include a cron.yaml file at the root of your source code. For example:

version: 1
 — name: "schedule"
   url: "/schedule"
   schedule: "0 */12 * * *"

Note: In the preceding example, the schedule cron job initiates a POST request to the /schedule endpoint in the worker environment at every 12th hour.

If your cron jobs still don't appear in the worker tier, then complete the steps in the following Troubleshoot issues with cron jobs section.

Troubleshoot issues with cron jobs

1.    In the event stream of your Elastic Beanstalk environment, check for an event similar to the following:

Successfully loaded 1 scheduled tasks from cron.yaml

2.    In your /var/log/eb-commandprocessor.log file, check for a log similar to the following:

{"status":"SUCCESS","api_version":"1.0","results":[{"status":"SUCCESS","msg":"","returncode":0,"events":[{"msg":"Successfully loaded 1 scheduled tasks from cron.yaml.","severity":"INFO","timestamp":1562000593}]}]}

3.    In your /var/log/aws-sqsd/default.log file, confirm that the Amazon Simple Queue Service (Amazon SQS) daemon is running and polling the correct queue.

If the Amazon SQS daemon starts correctly, you should see logs similar to the following:

2019-07-04T14:11:21Z init: initializing aws-sqsd 2.4 (2018-09-06)
2019-07-04T14:11:21Z pollers: start initializting poller timer...
2019-07-04T14:11:21Z pollers: start auto running poller...
2019-07-04T14:11:21Z start: polling

4.    In your /var/log/aws-sqsd/default.log file, check for the HTTP POST request that the Amazon SQS daemon sends to http://localhost/ on port 80. This request is sent when the daemon polls a queue item.

You should see a message similar to the following:

2019-07-05T13:54:52Z message: sent to http://localhost:80/

5.    To confirm that messages are delivered to the SQS queue, check the metric NumberOfMessagesReceived for the queue associated with the worker environment.

Note: You can also manually send a message to the queue to check the cron job.

6.    To invoke the scheduled task manually, run the following command:

curl -d param1=value1 -d param2=value2 -H "Content-Type: application/json" -X POST http://localhost/scheduled-task-path

The -d (--data) flag can hold the data that you're trying to pass to the cron job.

Note: Periodic tasks don't work for worker environments that are configured with Amazon SQS FIFO queues.

Did this article help?

Do you need billing or technical support?