How can I troubleshoot cron jobs in the worker tier of my Elastic Beanstalk environment?

Last updated: 2019-10-11

How can I troubleshoot cron jobs in the worker tier of my AWS Elastic Beanstalk environment?

Short Description

If your cron jobs don't appear in the worker tier, complete the steps in the Add cron jobs to a worker environment section. If your cron jobs still don't appear in the worker tier, then follow the steps in the Troubleshoot issues with cron jobs in your worker environment section.

Resolution

Add cron jobs to a worker environment

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. See the following example:

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

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

Troubleshoot issues with cron jobs in your worker environment

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 https://sqs.us-west-2.amazonaws.com/111122223333/yourWorkerQueue

4.    In your /var/log/aws-sqsd/default.log file, check for the HTTP POST request that the Amazon SQS daemon sends to the to http://localhost/ on port 80 when the dameon 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 getting 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 curl 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 you?

Anything we could improve?


Need more help?