Setting up a Lambda#
The AWS CDK is the most convenient way to create a new project on AWS Lambda. For example, it lets you directly define integrations such as APIGateway, a tool to make our lambda publicly available as an API, in your code.
Webhook verification#
Using the SDK (recommended)#
Edit lambda/index.ts, the file containing our core lambda logic:
We'll set the QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY environment variables together when deploying our Lambda.
Manual Verification#
In this section, we'll manually verify our incoming QStash requests without additional packages. Also see our manual verification example.
- Implement the handler function
- Implement the
verifyfunction:
You can find the complete example here.
Deploying a Lambda#
Using the AWS CDK (recommended)#
Because we used the AWS CDK to initialize our project, deployment is straightforward. Edit the lib/<your-stack-name>.ts file the CDK created when bootstrapping the project. For example, if our lambda webhook does video processing, it could look like this:
Every time we now run the following deployment command in our terminal, our changes are going to be deployed right to a publicly available API, authorized by our QStash webhook logic from before.
You may be prompted to confirm the necessary AWS permissions during this process, for example allowing APIGateway to invoke your lambda function.
Once your code has been deployed to Lambda, you'll receive a live URL to your endpoint via the CLI and can see the new APIGateway connection in your AWS dashboard:

The URL you use to invoke your function typically follows this format, especially if you follow the same stack configuration as shown above:
https://<API-GATEWAY-ID>.execute-api.<API-REGION>.amazonaws.com/prod/
To provide our QSTASH_CURRENT_SIGNING_KEY and QSTASH_NEXT_SIGNING_KEY environment variables, navigate to your QStash dashboard:

and make these two variables available to your Lambda in your function configuration:

Tada, we just deployed a live Lambda with the AWS CDK! 🎉
Manual Deployment#
- Create a new Lambda function by going to the AWS dashboard for your desired lambda region. Give your new function a name and select
Node.js 20.xas runtime, then create the function.

- To make this Lambda available under a public URL, navigate to the
Configurationtab and clickFunction URL:

-
In the following dialog, you'll be asked to select one of two authentication types. Select
NONE, because we are handling authentication ourselves. Then, clickSave.You'll see the function URL on the right side of your function overview:

- Get your current and next signing key from the Upstash Console.

- Still under the
Configurationtab, set theQSTASH_CURRENT_SIGNING_KEYandQSTASH_NEXT_SIGNING_KEYenvironment variables:

- Add the following script to your
package.jsonfile to build and zip your code:
- Click the
Upload frombutton for your Lambda and deploy the code to AWS. Select./dist/index.zipas the upload file.

Tada, you've manually deployed a zip file to AWS Lambda! 🎉
Testing the Integration#
To make sure everything works as expected, navigate to your QStash request builder and send a request to your freshly deployed Lambda function:

Alternatively, you can also send a request via CURL: