How to easily develop and deploy TypeScript Lambda functions

Introducing CDK TypeScript resource


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.


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


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({

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

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


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:

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

The package is available here:

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

Let me know if you have any questions or thoughts in the comments below.

Let us help you on your journey to Quality Faster

We at 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.

Feel free to schedule a call or send us a message below to see how we can help.

User icon
Envelope icon


Schedule a 30m call
  • Adding TypeScript to the official Apollo Platform Tutorial app

    In todays video I go through a preparation of the official Apollo Platform Tutorial App for adding Chimp to it. I decided to divide that task into two steps - first is adding TypeScript to the codebase. Watch me work, struggle, fly through code, hopefully you will learn some tricks :)

  • AWS CDK Lambda and DynamoDB dependency management

    A discussion about issues we've stumbled upon and a solution that simplified our CDK workflow.

  • cypress-cucumber-preprocessor 4.1.0 - TSX and Multiline Step Arguments support

    We've just released a new version of the cypress-cucumber-preprocessor package with TSX/React testing and Multiline Step Arguments.