This repository contains an AWS Lambda example demonstrating rate limiting implemented with Redis, Node.js, and TypeScript.
The application enforces a Time Limit based on the companyId provided in the request. It offers two distinct plan types: a free plan and a paid plan, each with its own monthly usage quotas.
Before you begin, ensure that you have the following prerequisites installed:
- Install project dependencies:
yarn install
- Start a local Redis instance (requires Docker):
yarn start-local-redis
- Run the development server:
yarn dev
- The Lambda function will listen for POST requests locally at http://localhost:300/lambda.
To deploy the Lambda function from your local machine, follow these steps:
- rename
env
to.env
and add your redis database url - Install the AWS CLI and Terraform CLI on your local machine.
- Create an AWS account and generate
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. - Configure your AWS credentials with
aws configure
- Initialize Terraform:
Terraform init
- Build and deploy the Lambda function:
sh build.sh
Automate the deployment of your Lambda function using GitHub Actions. The deployment workflow is defined in the .github/workflows/main.yaml file.
To set up Continuous Delivery (CD) using GitHub Actions:
- Install the
AWS CLI
andTerraform CLI
on your local machine. - Create an AWS account and generate
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. - Configure your AWS credentials with
aws configure
- Create an S3 bucket to store Terraform state using the provided script,
createBucket.sh
. - Add the following secrets to your GitHub Actions repository:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
REDIS_DB_PATH
- The
main.yaml
workflow will automatically trigger with every new push to the main branch.