This project contains a backend starter template for running NestJS GraphQL APIs on AWS Lambda with security and performance best practices.
- GraphQL configuration (Code-first approach)
- Prisma Database config with migrations
- Docker database for local development
- AWS Deployment with Serverless Framework
- AWS Lambda NodeJS 18x configuration and optimizations
- GitHub actions for CI/CD
- Authentication/Authorization
- Opinionated, mature backend framework with active community
- Supports dependency injection out of the box
- First-class typescript support
- Provides a query language that lets clients specify the data they need
- Strong support in frontend frameworks like React
- Pay-per-use pricing is ideal for early-stage startups where traffic and access patterns are unknown
- Cold starts can be minimized by keeping package bundles small, caching server between invocations and keeping lambdas warm
- Strong community of plugins and supports for NodeJS/Typescript
- ORM with great developer experience
- Excellent Typescript support
- Hosted serverless Postgres database
- NodeJS
- NVM
brew install nvm
- Yarn
- Docker
- VSCode
- AWS Account
-
Create a
.env
file using .env.example as an example -
nvm use
-
yarn install
-
Launch Supabase in Docker with
npx supabase start
-
Run database migrations locally in a separate terminal if it's a first time setup with
npx prisma migrate dev
-
Seed the database with
npx prisma db seed
-
Start the NestJS server with
yarn start:dev
-
Call the endpoints in requests.http to test the API.
yarn test:e2e
yarn build # with webpack
# run binary locally
node dist/main.js
Test AWS Lambda packaging and run locally with:
npx serverless offline
Note - create all AWS and Supabase resources in the us-east-1
AWS region.
-
Setup your AWS Credentials for deployments
-
Create a free-tier Supabase database.
-
Create an AWS SSM Parameter in the AWS console named
/dev/database/url
with the secure string type and save the DB connection string.Confirm it exists with:
aws ssm get-parameter --name /dev/database/url --with-decryption
-
Install dependencies:
nvm use 18 yarn install
-
Deploy the app to AWS:
npx serverless deploy
Update requests.http with the output of the deployment to call the API.
# create migrations
npx prisma migrate dev --name <MIGRATION_NAME>
# run migration
npx prisma migrate dev
# reset development database
npx prisma migrate reset
Note - an ERD diagram for the database schema will be generated under /docs
- see diagram.
Production database migrations should be run in a CI/CD pipeline but can also be run locally with:
npx prisma migrate deploy
See the Prisma docs for more information.