Serverless Deno support with Architect

Brian Leroux’s avatar

by Brian Leroux
@brianleroux
on

Deno example code

This post was last updated May, 2020 as Deno hit 1.0

Deno is a next-generation JavaScript runtime built in Rust on top of V8. It employs an interesting least-privilege security model, uses standard ES Modules, sports a standard browser API, and supports TypeScript out of the box. It’s really nice!

Quickstart

Let’s get started! First, let’s create a new Architect project:

npm init @architect ./denoapp --runtime deno

The init script generates a Lambda function in src/http/get-index/index.ts

import { Context, Event } from 'https://deno.land/x/lambda/mod.ts'

export async function handler(event: Event, context: Context) {
  return {
    statusCode: 200,
    headers: {'content-type': 'text/html; charset=utf8'},
    body: `Welcome to deno ${Deno.version.deno} 🦕`
  };
}

View source

Notice: we’re using native modules and TypeScript syntax!

Work locally

Make sure you have Deno installed locally. Running npm start will start the local Sandbox, and automatically use your installed Deno runtime.

Deploy to AWS

Deploying to AWS with arc deploy will work just as expected! 🎉

That’s it!

Now you’re up and running with serverless Deno. You can find the full source code for this tutorial here.

Bonus: here is a bare metal SAM version for you to check out.


Next steps