This project is a derivative of aws-nodejs-typescript template from the Serverless framework. Instead of using esbuild it uses webpack.
For detailed instructions, please refer to the documentation.
Depending on your preferred package manager, follow the instructions below to deploy your project.
Requirements: NodeJS
lts/fermium (v.14.15.0). If you're using nvm, runnvm useto ensure you're using the same Node version in local and in your lambda's runtime.
cp .env.dist .envUpdate the .env with appropriate values
- Run
npm ito install the project dependencies - Run
npm run deployto deploy this stack to AWS - Run
npm run removeto destroy the Lambda deployed
- Run
yarnto install the project dependencies - Run
yarn deployto deploy this stack to AWS - Run
yarn removeto destroy the Lambda deployed
This repository contains a GraphQL API that can be run locally. It can be explored via Apollo Studio.
⚠️ As is, this template, once deployed, opens a public endpoint within your AWS account resources. Anybody with the URL can actively execute the API Gateway endpoint and the corresponding lambda. You should protect this endpoint with the authentication method of your choice.
In order to test the hello function locally, run the following command:
npm run devif you're using NPMyarn devif you're using Yarn
The project code base is mainly located within the src folder. This folder is divided in:
functions- containing code base and configuration for your lambda functionslibs- containing shared code base between your lambdas
.
├── src
│ ├── functions # Lambda configuration and source code folder
│ │ ├── api
│ │ │ ├── handler.ts # lambda source code
│ │ │ ├── index.ts # lambda Serverless configuration
│ │ │ └── context.ts # GraphQL context
│ │ │ └── db.ts # Common database layer access (Prisma instance)
│ │ │ └── schema
│ │ │ └── builder.ts # Schema builder
│ │ │ └── index.ts # GraphQL schema
│ │ │
│ │ └── index.ts # Import/export of all lambda configurations
│ │
│ └── libs # Lambda shared code
│ └── apiGateway.ts # API Gateway specific helpers
│ └── handlerResolver.ts # Sharable library for resolving lambda handlers
│ └── lambda.ts # Lambda middleware
│
├── package.json
├── serverless.ts # Serverless service file
├── tsconfig.json # Typescript compiler configuration
└──tsconfig.paths.json # Typescript paths
| Webpack | Esbuild | |
|---|---|---|
| Bundle Size | ~16.0KB | ~44.0KB |
- @serverless/typescript - provides up-to-date TypeScript definitions for your
serverless.tsservice file - fork-ts-checker-webpack-plugin - Type checking without a burden on build performance.
- serverless-webpack-prisma - Deletes unnecessary prisma from bundling to Lambda.
Any tsconfig.json can be used, but if you do, set the environment variable TS_NODE_CONFIG for building the application, eg TS_NODE_CONFIG=./tsconfig.app.json npx serverless webpack