@upstash/ratelimit
and Serverless Framework.
Prerequisites
- Install the Serverless Framework with
npm i serverless -g
Project Setup
Create a Serverless Framework application with the following options:package.json
with @upstash/ratelimit
as a dependency:
package.json
Database Setup
Create a Redis database using Upstash Console or Upstash CLI and copy theUPSTASH_REDIS_REST_URL
and UPSTASH_REDIS_REST_TOKEN
into your .env
file.
.env
Ratelimited Function Setup
Updatehandler.js
:
handler.js
serverless.yml
to pass the environment variables:
serverless.yml