Skip to main content

Create a Scalable Webhook

Overview

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

  1. An Altostra Account (Don't have one yet? Just login here)
  2. Altostra CLI installed (npm i -g @altostra/cli or see docs)
  3. Altostra extension for Visual Studio Code (VSCode Marketplace or see docs)
  4. A connected AWS cloud account ( Web Console settings or see docs)
  5. An Environment connected to your AWS Account (Web Console environments or see docs) - We'll call it Dev for brevity, but you can pick any of your environments

Create a new project

  1. In Visual Studio Code, open the directory in which you wish to create the project.
  2. Switch to the Altostra view
  3. Click "Initialize Project"
  4. In the Templates list, click Scalable Webhook

generate-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.

scalable-webhook-architecture

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.

deploy-scalable-webhook

Let's Test!

First, let's find out our api gateway address:

Run 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"

api-gateway

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' \
--data-raw '{
"eventType": "CLICKED",
"emailId": "email-1234"
}'

You should get this response:

HTTP/2 200
content-type: application/json
content-length: 0

Now you can go to your DynamoDB table and check for entries:

dynamoo-db

Congratulation! You've got a full blown working scalable webhook!

Ready to Get Started?

Get Started for Free
© 2023 Altostra, Inc.