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?
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:
version: 1 cron: - name: "schedule" url: "/schedule" schedule: "0 */12 * * *"
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:
2023-01-17T03:28:31Z init: initializing aws-sqsd 3.0.4 (2022-03-18) 2023-01-17T03:28:31Z schedule-parser: Successfully loaded 1 scheduled tasks from file /var/app/current/cron.yaml . 2023-01-17T03:28:31Z leader-election: initialized leader election 2023-01-17T03:28:31Z scheduler: initialized 1 job's pending time 2023-01-17T03:28:31Z pollers: start initializting poller timer... 2023-01-17T03:28:31Z pollers: start auto running poller... 2023-01-17T03:28:31Z leader-election: Starting leader election 2023-01-17T03:28:31Z leader-election: current role: worker 2023-01-17T03:28:31Z scheduler: Starting scheduler 2023-01-17T03:28:31Z start: polling https://sqs.us-east-1.amazonaws.com/111122223333/yourWorkerQueue
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:
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 periodic task.
Note: Periodic tasks don't work for worker environments that are configured with Amazon SQS FIFO (First-In-First-Out) queues.
- AWS OFICIALAtualizada há 4 meses
- AWS OFICIALAtualizada há 7 meses
- Como faço para restringir as permissões do IAM de um usuário do Elastic Beanstalk a aplicativos específicos?AWS OFICIALAtualizada há 4 anos
- AWS OFICIALAtualizada há 2 anos