Listening for webhooks isn’t exactly difficult but there are a number of things which might trip you up:
By building a simple Serverless application using both Lambda and SQS, you can solve a lot of these issues then consume the webhooks from the queue in your own time.
If anything fails whilst being consumed, it will get pushed straight back to the queue and can be retried again later on.
Assuming Serverless is setup, first we’ll start a new project.
Replace the contents serverless.yml
with the below then update your profile name and region.
This will define the NodeJS version, memory allocation, AWS profile, region, along with the lambda function name and SQS queue.
The name of the queue is passed into the environment variable AWS_SQS_QUEUE_URL
.
Replace the contents of handler.js
with the below.
The function will:
The SQS message will now contain the HTTP headers and body from the original request.
The output will show your webhook URL, the SQS queue name can be found in the AWS console.
Send a test webhook from the console.
Check the response in the SQS console.
To remove the function simply run: