First Look at Lambda Powertools TypeScript

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • dazn-lambda-powertools

    Powertools (logger, HTTP client, AWS clients, middlewares, patterns) for Lambda functions.

  • I'm a big fan of TypeScript and in fact co-authored a book about it. I don't find myself using Java or Python much, so while I've been interested in Lambda Powertools, I never tried it out until now. Lambda Powertools TypeScript joins middy and DAZN Lambda Powertools in the Lambda tooling space for the Node.js runtime. Two things that differentiate Lambda Powertools TypeScript from comparable libraries are it is sponsored by AWS and it supports decorators.

  • middy

    🛵 The stylish Node.js middleware engine for AWS Lambda 🛵

  • I'm a big fan of TypeScript and in fact co-authored a book about it. I don't find myself using Java or Python much, so while I've been interested in Lambda Powertools, I never tried it out until now. Lambda Powertools TypeScript joins middy and DAZN Lambda Powertools in the Lambda tooling space for the Node.js runtime. Two things that differentiate Lambda Powertools TypeScript from comparable libraries are it is sponsored by AWS and it supports decorators.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

    SurveyJS logo
  • TypeScript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • It's five extra lines - perhaps not a big deal. In any case, there's not a lot the Powertools team can do as it may well be years before decorators are supported for functions. Keep in mind if we do choose to use decorators and classes in Lambda, we need to be careful around the this reference.

  • esbuild

    An extremely fast bundler for the web

  • Decorators and TypeScript aren't supported out of the box in Lambda (without using deno) so we'll also need a transpilation step if we go this route. Fortunately this is a mostly solved problem for AWS CDK, AWS SAM and Serverless Framework users. If you want or need to roll your own, esbuild is a great place to start and seems to be the bundler of choice for this purpose.

  • deno-lambda

    A deno runtime for AWS Lambda. Deploy deno via docker, SAM, serverless, or bundle it yourself.

  • Decorators and TypeScript aren't supported out of the box in Lambda (without using deno) so we'll also need a transpilation step if we go this route. Fortunately this is a mostly solved problem for AWS CDK, AWS SAM and Serverless Framework users. If you want or need to roll your own, esbuild is a great place to start and seems to be the bundler of choice for this purpose.

  • aws-embedded-metrics-node

    Amazon CloudWatch Embedded Metric Format Client Library

  • Custom metrics have a pricing structure which can be expensive. Embedded Metrics Format can help manage the cost and is supported by Lambda Powertools TypeScript. Again, the docs here are pretty good, so no need for me to break it down. Instead let's look at the experience. I've added a custom metric of "collectionSuccess" to my collectionSuccess function. In my hypothetical app, some payments wind up in collections and here I'm marking whether or not the collection resulted in a payment.

  • powertools-lambda-typescript

    Powertools is a developer toolkit to implement Serverless best practices and increase developer velocity.

  • The documentation for Lambda Powertools TypeScript is pretty good and provides several examples with even more on GitHub.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • jsii

    jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!

  • Each version of Lambda Powertools is developed independently and the capabilities are custom-tailored to the distinct needs of the different runtimes. This is in contrast to AWS CDK using jsii to publish the same constructs to multiple runtimes. Although it may be frustrating to wait for some of these capabilities, this is likely the right approach as it would just add to the complexity to think about generic code that compiles to something that can decorate custom code supported in multiple runtimes.

  • cdk-async-testing-example

  • If you want to see my instrumented code, it is available in this branch.

  • aws-xray-sdk-node

    The official AWS X-Ray SDK for Node.js.

  • So what do we get for that? The Tracer module wraps the AWS X-Ray SDK (as a transitive dependency). It doesn't really add any net new capabilities, but makes the SDK easier to work with. In my experience, that SDK is a bit of a bear so this may be well worth it. We can decorate class methods to introduce new trace segments in a single line of code. We can also use the imperative form to add new traces where we see fit. We can capture AWS clients, but that simply exposes the X-Ray SDK.

  • I eagerly await the general availability of this library and will follow the roadmap to see what's coming up and how I can get involved.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts