1. Create a new project
Let’s create a new folder calledaws-lambda
and initialize a new project with
your favourite package manager. This example uses npm
because everyone will
have it installed with node already.
2. Install Dependencies
Using typescript requires installing a few dependencies. Here we are usingesbuild
to bundle our code, so we can upload it to AWS later.
3. Creating the handler function
In this example we will show how to receive a webhook from QStash and verify the signature without any additional dependencies. First, let’s import everything we need:verify
function for now. We
will add that next. In the handler we will prepare all necessary variables that
we need for verification. This includes the signature, the signing keys and the
url of the lambda function. Then we try to verify the request using the current
signing key and if that fails we will try the next one. If the signature could
be verified, we can start processing the request.
verify
function will handle the actual verification of the signature. The
signature itself is actually a JWT and includes claims about
the request. See here.
4. Create a Lambda function on AWS
Create a new Lambda function from scratch by going to the AWS console. (Make sure you select your desired region) Give it a name and selectNode.js 16.x
as runtime, then create the function.

Configuration
tab:

Auth Type = NONE
because we are handling authentication ourselves.
After creating the url, you should see it on the right side of the overview of
your function: 
5. Set Environment Variables
Get your current and next signing key from the Upstash Console On the sameConfiguration
tab from earlier, we will now set the required
environment variables: 
6. Deploy your Lambda function
We need to bundle our code and zip it to deploy it to AWS. Add the following script to yourpackage.json
file:
npm run build
this will build and zip the code.
Afterwards we can click the Upload from
button in the lower right corner and
deploy the code to AWS. Select ./dist/index.zip
as upload file.
