How to easily develop and deploy TypeScript Lambda functions

Introducing CDK TypeScript resource

Why?

All-TypeScript codebase including infrastructure as a code with CDK and application code is a pleasure to use.
Deployment of it, not so much.

You can transpile your code to a new directory, copy package.json there, install production dependencies, and then have CDK send that whole folder to lambda. It's painful to set up, and it will bring a ton of unnecessary code (everything in node_modules) along.
Webpack is better - it can take an entrypoint and create a small bundled file that includes only what you need.
Unfortunately, no one likes to set up complex and diverging webpack configurations, especially in a monorepo with tens if not hundreds of tiny packages.

What?

We wanted TypeScript Lambda experience to be seamless - if a developer wants to create a new function, he should create a typescript file, add it to CDK and that's it. Now you can do it like so:

import { TypeScriptFunction } from "cdk-typescript-tooling";
// ...
const statusHandle = new TypeScriptFunction(scope, "Purchase-Status-Endpoint", {
  entry: require.resolve("@sales/purchase-endpoint/src/handler.ts"),
});

It takes all the parameters that you know from @aws-cdk/aws-lambda, like runtime, environment, timeout, and so on, because we extend it.

Expose easily through HTTP

Why?

In our development exposing lambdas through http is a very frequent case. The code around it for most cases stays exactly the same and increases the noise.
We define the function:

const handler = new TypeScriptFunction(stack, "Add-Function", {
  entry: require.resolve("@calculator/add/src/handler.ts"),
});

Add HttpApi using LambdaProxyIntegration

const statusApi = new apiGateway2.HttpApi(stack, "PurchaseStatusHttpApi", {
  defaultIntegration: new apiGateway2Integrations.LambdaProxyIntegration({
    handler,
  }),
});

Add the url to CfnOutput to, among others, see the url in CI/CD logs.

new CfnOutput(stack, "addUrl", {
  value: statusApi.url,
});

What?

Define your function with withHttp option like so:

new TypeScriptFunction(stack, "Add-Function", {
  entry: require.resolve("@calculator/add/src/handler.ts"),
  withHttp: true,
});

...and the other two steps will be done for you automatically.

You can watch me build an example using the TypeScriptFunction from cdk-typescript-tooling here:

The code source created while recording that video is here:

xolvio/cdk-typescript-tooling-example-live
Contribute to xolvio/cdk-typescript-tooling-example-live development by creating an account on GitHub.

The package is available here:

cdk-typescript-tooling
AWS is great. Lambdas changed the way we think about programming. CDK makes it all even better.

Let us help you on your journey to Quality Faster

We at Xolv.io specialize in helping our clients get more for less. We can get you to the holy grail of continuous deployment where every commit can go to production — and yes, even for large enterprises.

Here are the things we offer:

Services (we help you)

  • Custom Software Development
    Whether you're looking to create a proof-of-concept or build an entire new capability, we can help you get there at speed and with high quality.
  • Apollo GraphQL Consulting
    We can help in all areas related to Apollo GraphQL and surrounding technologies including Apollo Federation, One-graph unification, Domain Driven Design, µService deployment, automated testing, security, performance, and more.
  • Continuous Delivery Coaching
    We have made it our business to help organizations modernize their technologies stacks and processes to gain speed, stability, and quality improvements, especially in enterprises where legacy systems seem impossible to deal with.

Products (you help yourself)

  • XSpecs
    XSpecs is a full-team collaborative toolset that simplifies the writing of specifications and integrates them into your team's existing workflow. This helps you improves velocity, decreases bugs, and increases quality.
  • Quality Faster
    A complete full-team, full-cycle and full-stack guide to help you and your team increase the speed at which you deliver software while simultaneously increasing quality.

Have something else in mind? Get in touch.


  • Testing with DynamoDB Toolbox

  • Creating Tables with DynamoDB Toolbox

  • Instantly update your Lambda functions (development)