How can I add periodic tasks to the worker tier of my Elastic Beanstalk environment and troubleshoot issues with periodic tasks that won't get added?
3 minute read
I want to add periodic tasks to the worker tier of my AWS Elastic Beanstalk environment.
Note: Elastic Beanstalk uses the aws-elasticbeanstalk-ec2-role instance profile role. This comes with the managed permissions AWSElasticBeanstalkWebTier, AWSElasticBeanstalkWorkerTier, and AWSElasticBeanstalkMulticontainerDocker. AWSElasticBeanstalkWorkerTier is required for periodic tasks to work. For more information, see Managing Elastic Beanstalk instance profiles.
Add periodic tasks to a worker tier
To add a periodic task to the worker tier of your Elastic Beanstalk environment, include a cron.yaml file at the root of your source code. For example:
Note: In the preceding example, the schedule task periodically sends an Amazon Simple Queue Service (Amazon SQS) message that describes the task. The schedule task sends the message to the head of the queue every 12th hour. After the message transverses the queue, an instance picks up the task to HTTP POST the "/schedule" endpoint.
If your periodic tasks still don't appear in the worker tier, then complete the steps in the following Troubleshoot issues with periodic tasks section.
Troubleshoot issues with periodic tasks
1. In your /var/log/aws-sqsd/default.log platform file, check for a log similar to the following:
schedule-parser: Successfully loaded 1 scheduled tasks from file /var/app/current/cron.yaml .
2. In your /var/log/aws-sqsd/default.log file, confirm that the Amazon SQS daemon is running and polling the correct queue.
If the Amazon SQS daemon starts correctly, then you see logs similar to the following:
3. 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. When the daemon polls the queue item, it sends the request.
You see a message similar to the following:
2019-07-05T13:54:52Z message: sent to http://localhost:80/
4. To confirm that the Amazon SQS queue receives the messages, check the metric NumberOfMessagesReceived for the queue that's associated with the worker environment.
5. To invoke the scheduled task manually, run the following command: