In this tutorial we'll create a fully functional scalable webhook from a template. Webhooks are a design pattern for allowing one or more apps to trigger another app with real-time information when something happens (like a stock price change or a user login, for example).
You can read more about scalable webhooks on our blog post)
A scalable webhook consists of the following resources:
- API Gateway to receive our calls
- An enqueuing Lambda function to validate and write the request into the Queue
- An SQS queue to hold all the messages until we can handle them
- A processing Lambda function to do the actual work at the rate we need
- A simple DynamoDB table to store our data
Let's get started!
Things you'll need for this tutorial
- An Altostra Account (Don't have one yet? Just login here)
- Altostra CLI installed (
npm i -g @altostra/clior see docs)
- Altostra extension for Visual Studio Code (VSCode Marketplace or see docs)
- A connected AWS cloud account ( Web Console settings or see docs)
- An Environment connected to your AWS Account (Web Console environments or see docs) - We'll call it
Devfor brevity, but you can pick any of your environments
Create a new project
- In Visual Studio Code, open the directory in which you wish to create the project.
- Switch to the Altostra view
- Click "Initialize Project"
- In the Templates list, click Scalable Webhook
The template is applied to the current project, and now you've got the architecture of a scalable webhook, with basic code implementation.
Deploy the Project
Now that we have the project, first we push a new version:
alto push v0.1
A Version is basically your infrastructure and code before they've been adapted to a specific environment. A Version can be deployed to any environment. You can read more about Altostra versions here.
And then, we deploy the project from that version to the development environment:
alto deploy sampleDeployment:v0.1 --env Dev
A Stack is a live release of your version in a specific environment - in this case, the Dev environment.
For information about deploying projects, read the Deploy a Project guide.
That's it - the project is deployed.
First, let's find out our api gateway address:
alto console. It will take you directly to your project page in the Altostra's web console.
Click on the stack name
sampleDeploymet - and you'll get to the current deployed stack.
Click on the arrow at the right end of the first line - this will send you directly to your AWS stack.
Click the ApiGateway, and select the
messages endpoint under
Prod stage and copy the "invoke URL"
Now, lets send a sample request:
curl --location --request POST -i 'https://3f7yjl6dd2.execute-api.us-east-1.amazonaws.com/Stage/messages' \
--header 'Content-Type: application/json' \
You should get this response:
Now you can go to your DynamoDB table and check for entries:
Congratulation! You've got a full blown working scalable webhook!