geoffwilliams@home:~$

Deno on AWS Lambda

Sometimes you get to play with cool stuff at work for fun… I decided to try out Deno since Id heard some good things about it and knocked out a small demo project to test on AWS Lambda which has been on my todo list for a while now.

Hows the Deno experience?

Quite nice really. Compared to NodeJS its much simpler to get started. There is built-in TypeScript support and you dont need a bunch of random project files all over the place, so basically you can just start coding right away - its great.

There are some caveats tho:

  • Still in the early adaopter phase
  • Native compiled stuff wont work (node-gyp)
  • Rapid pace of change - deno bundle already deprecated

Hows the AWS Lambda experience?

Not great. Deno is not a supported runtime at the moment but searching brings us to https://github.com/denoland/deno-lambda/

What should I know about running on AWS Lambda?

  • 15 minute maximum runtime
  • Out-of-the-box support for a handfull of runtimes such as Python and NodeJS
  • Docker image support
  • Other runtimes can be supported buy zipfile upload

Docker images on Lambda?

The whole point of AWS Lambda is “serverless” computing, you just deal with code not servers. Docker images are a convenient and repeatable way to deploy code and since Lambda can just run whatever binary is in the image, its one way to bundle a runtime and and app together.

This approach works well for services like AWS ECS and Kubernetes which already deal with containers. Using Docker images in Lambda will work but is a little jarring to the whole serverless paradigm since you now have to setup ECR and host images. In my opinion Docker images in Lambda are a bit like having another flavour of ECS to deal with - a middle ground between serverless and container runtime.

deno-lambda GitHub

The cannonical way to deploy Deno on Lambda is the Git Repository.

It features 2x ways to deploy:

  1. Zipfile bundling - gave deprecation errors so I gave up
  2. Docker image - seems to make some assumptions about project structure incompatible with my demo project

Researching Lambda a bit more, the Docker image approach feels the least “lambda-ey” so I focussed on the zipfile building. Through this research I came up with a method to:

  1. Compile the entire deno project to a single static executable (deno compile)
  2. Build a zipfile suitable for upload to Lambda
  3. Automate the above with Terraform and S3

I reported this back so perhaps the instructions will get updated. In the meantime, I made a sample “Hello, World!” Deno project with all the required terraform scripts: https://github.com/GeoffWilliams/deno-lambda-terraform

If your also struggling to get your Deno app working on Lambda maybe give this a go?

Whats next?

I saw Bun mentioned a few times on youtube and its also on my list of things to look at. Its even newer then Deno but its meant to be approximately twice as fast and more of a drop-in replacement for node. Hopefully someone already has this working with Lambda!

Post comment