Just a sample minimalist starter to run a modern AWS-deployed serverless TypeScript application with some quality-of-life tooling such as ESLint and Prettier. Packages and deploys using Serverless Framework and bundles it using esbuild.
Configurations for ESLint and Prettier are reasonable starting points. The TypeScript config is very strict to get the most out of TS features. Serverless Framework is optimized (ARM architecture; short log retention; no versioning), CORS-activated, and set to safer-than-default settings.
The application separates AWS Lambda-specific handler stuff in src/handler.ts
and business/application logic in src/index.ts
. Tests for the business/application logic are in the tests
folder and use AVA.
- Recent Node.js (ideally 18+) installed.
- Amazon Web Services (AWS) account with sufficient permissions so that you can deploy infrastructure. A naive but simple policy would be full rights for CloudWatch, Lambda, API Gateway, and S3.
- Ideally some experience with Serverless Framework as that's what we will use to deploy the service and infrastructure.
Clone, fork, or download the repo as you normally would. Run npm install
.
npm start
: Run application locallynpm test
: Test the business/application logic with AVAnpm run build
: Package application with Serverless Frameworknpm run deploy
: Deploy application to AWS with Serverless Frameworknpm run teardown
: Remove stack from AWS
Using npm start
you can start using the local endpoint http://localhost:3000/dev/greet
to call the service.
curl http://localhost:3000/dev/greet -X POST -d '{ "name": "Zelda, Princess of Hyrule" }'
Which should respond back with:
"Hi Zelda, Princess of Hyrule!"