The 6 Top Libraries for AWS Serverless TypeScript Developers
If you’re an AWS Serverless TypeScript developer, here is a list of libraries you should know and use to improve your developer experience. The majority of the libraries listed in this article are runtime librairies rather than developer tooling.
Middy is a middleware stack configuration library. Using middy, you can standardize operations to be executed before, after and whenever an error is thrown in your lambda handler’s code without duplicating the code in every file. Middy ships multiple middlewares dedicated to specific tasks like parsing HTTP body from API Gateway, event validation with JSON Schema, error catching and correctly returning formatted HTTP responses… You can also write your own middleware.
SK in your code anymore.
JSON Schema to TS
JSON Schema to TS is a great package developed by Thomas Aribart, not necessarily dedicated to serverless projects, but very helpful in some specific serverless situations. It statically generates TypeScript types from JSON Schema definitions. JSON Schema is widely use in the serverless world: API Gateway v1 uses it to perform input validation and EventBridge uses it in its schema registry as well. When writing TypeScript handlers, you only need to define an event schema once using JSON Schema syntax. Your handlers’ codebase can then benefit from TypeScript corresponding types without versioning an actual TypeScript definition. This make sure you’re always up to date, and never duplicate your definitions among multiple syntaxes.
Serverless framework Typescript service file definitions
This is a project I started recently aiming to facilitate adoption of TypeScript service files and its advantages. Using a
serverless.ts file instead of the traditional
serverless.json empowers your development team with IDE hints on expected configuration types when modifying this file. It also allows easier imports from other files, as well as semantically valid references. You can learn more by reading the article I wrote detailing those advantages. The Serverless Framework TypeScript service file definitions is a neat little package, automatically updated on Serverless Framework release, containing actual types being validated within the framework internal logic. It ensures you’re always using the configuration Serverless expects! If you want to learn more about this package, have a look at the detailed explanation I published.
TypeBridge is a small library I started, currently in beta, very similar to DynamoDB-Toolbox. It’s scoped around EventBridge events and buses and aims to:
- programmatically define your application custom events with JSON Schema
- provide you with business oriented publisher and consumer typed APIs, validating your publish payloads and consumed events against the JSON schema
- automatically batch
putEventscalls when publishing more than 10 events at a time
- check for event payload size before publishing
It leverages JSON Schema definitions of your events and statically computes TypeScript definitions to be used in the put and consume APIs.
AWS Lambda Power Tuning
AWS Lambda Power Tuning is the outsider of this listing, but it’s awesome! This tool, developed by Alex Casalboni aims to optimize your lambda memory configuration in order to reduce execution costs. It’s not necessarily tied to Node.js runtimes. It isn’t part of your production code, but instead is used as a workbench tool that can be used at a particular time, or be part of a CI process. Lambda’s billing is computed using both memory size and duration. While a 1024MB lambda costs twice the price of a 512MB one running for the same period of time, if your actual handler’s code runs 3 times faster on the 1024MB lambda, your wallet will be better off with this configuration. This optimization becomes even more interesting with the recent introduction of ms granularity billing for lambda, where every ms counts (rather than previous 100ms granularity, making optimizing lambda’s duration much less of a preoccupation).
If you’d like to find out about other libraries, you can find a much more widespread list of serverless tools in Anibal’s awesome serverless Github repository.