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.js

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.

In combination with the AWS JavaScript SDK middleware stack that will be introduced in v3, all handlers’ codebase will reduce even more, keeping only business specific lines and moving all technical tasks to those middlewares.

DynamoDB-Toolbox

DynamoDB-Toolbox is wrapper for the DynamoDB AWS SDK. It provides a much more developer friendly API. To configure this wrapper, you need to define JavaScript classes representing each of the various entities stored in DynamoDB. Those classes then provide the development team with dedicated read and write functions. I find it particularly useful when dealing with entities containing composite keys as the construction and deconstruction of the key is process internally by this package. It is also very convenient when working with a single-table design as each attribute can be renamed for the entity specific naming. You’ll never have ugly PK or SK in your code anymore.

The missing element of DynamoDB-Toolbox is TypeScript definitions. The library is written in JavaScript at the moment. It’s being rewritten in TypeScript at the time of this article thanks to Jeremy Daly’s effort. In the meantime, you can use this gist and version it in your project to enjoy very detailed typed APIs.

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.yml or 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

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 putEvents calls 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.

Serverless Transformation

Serverless Tools, Techniques, and Case Studies

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store