Fork this repository to quickstart lambda development with Typescript and CDK and the AWS SDK JS V3
- setup AWS CLI
- run
npm ci && cd infrastructure && npm ci && npm dedupe
npm texecutes test with jestnpm run buildcreates ./dist/lambda.js bundlenpm run zipcreates the ./dist/lambda.zip from ./dist/lambda.js rnpm run distruns all of the above stepsnpm run stackuses CDK to create or update CloudFormation infrastructure, see CDK readme. Add profile if necessary, e.g.-- --profile atombrenner. Will deploy lambda.zip if changed.npm run deployuses AWS CLI to just deploy the lambda.zip package code to the existing lambda functionnpm startwill run the lambda function locally
- CDK for managing infrastructure with AWS CloudFormation
- Babel
- esbuild
- Webpack
- Parcel
- Jest for testing
- Prettier for code formatting
- Husky for managing git hooks, e.g. run tests before committing
Switched to use esbuild for transpiling and bundling lambda typescript source.
Compared to webpack, esbuild configuration is minimal and simple and it is unbelievable fast.
The generated bundle is slightly larger than with webpack, but for AWS Lambdas a waste of a few kilobytes doesn't matter.
The important thing is, that all needed dependencies are bundled and all the noise from node_modules (tests, sources, readme, etc) is excluded.
As esbuild is only transpiling typescript, a separate call to tsc run is necessary in npm run dist.
- generate and use source-maps to have readable stack traces in production
--sourcemap --sources-content=falsegenerates a small source-map without embedded sources--keepnamesdoes not minifiy names which makes stack traces even more human readableNODE_OPTIONS=--enable-source-mapsenables experimental source-map support in AWS Lambda nodejs