How to simulate sending periodic task on Elastic Beanstalk server?

Viewed 1247

I have set up an Elastic Beanstalk server, worker tier. It has a cron.yaml to run a task every hour, like so:

version: 1
cron:
 - name: "broadcast-users"
   url: "/broadcast"
   schedule: "0 * * * *"

I know that it works via SQS sending a message to the worker queue which then gets picked up by that route - but I don't know what that message looks like. I would like to be able to test the cron job easily, without waiting for the scheduled time to come.

Does anybody what the message would look like from SQS to kick off this cron job? (Or how I can inspect the contents of the messages being sent to SQS?)

Thanks!

4 Answers

Amazon answered this question in their knowledge center (here). In a nutshell, you can SSH into a worker and use curl to immediately test a job via it's URL...

curl -H "Content-Type: application/json" -X POST http://localhost/<path>

...where <path> is the path to the job you want to test. You can also pass parameters using the -d option:

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

Goto the AWS SQS gui (e. g. https://eu-central-1.console.aws.amazon.com/sqs/v2/home#/queues) and select your queue. If you don't know your queue, navigate to EBS worker configuration and look into the section Worker. Watch out for the Worker queue URL and select the last part of the url. Should look something like this awseb-e-3j7sjaqxre-stack-AWSEBWorkerQueue-3WR7QFDPTDEH1. Search for this in the queue list, select and click the Send and receive messages button.

In the Message Body textarea put elasticbeanstalk scheduled job.

Add three Message Attributes

Name: beanstalk.sqsd.path
Type: String
Custom Type: (empty)
Value: /jobs/example-job <- cron.url from your cron.yaml

Name: beanstalk.sqsd.task_name
Type: String
Custom Type: (empty)
Value: example-job <- cron.name from your cron.yaml

Name: beanstalk.sqsd.scheduled_time
Type: String
Custom Type: (empty)
Value: '2020-12-06T11:07:00+01:00' <- It did not work without this entry

Send message!

I don't know why, but the job did not start without the beanstalk.sqsd.scheduled_time attribute. Even though the attribute value is ignored! The job started immediately.

Related