Skip to content
A deno runtime for AWS Lambda
TypeScript Shell Dockerfile JavaScript
Branch: master
Clone or download
Latest commit ee06c3f Dec 5, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows Fix release action due to repo rename Nov 15, 2019
example Bump version to 0.26.0 Dec 6, 2019
runtime Remove unnecessary files Dec 6, 2019
tests Bump version to 0.26.0 Dec 6, 2019
.gitignore Add serverless example Dec 4, 2019
LICENSE Initial commit Nov 7, 2019
README.md Bump version to 0.26.0 Dec 6, 2019
hello.ts Simplify test code Nov 9, 2019

README.md

deno on AWS Lambda

A deno runtime for AWS Lambda.

ci status

Quick Start

From the AWS console:

  1. Download zip files from the releases page.

  2. Create a layer and upload deno-lambda-layer.zip.

Create layer

Layer created

Note its Version ARN.

  1. Create a lambda function from scratch with runtime "provide your own bootstrap".

Create function

Function created

  1. Add a layer using the ARN above.

Add layer to function

  1. Upload deno-lambda-example.zip as function code.

Upload function code

  1. "Save". "Test" (use the default event).

Execution successful


AWS Lambda calls the hello.handler function:

// hello.ts

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

export async function handler(event: Event, context: Context) {
  return {
    statusCode: 200,
    body: `Welcome to deno ${Deno.version.deno} 🦕`
  };
}

The default is hello.handler but this can be configured by the Handler setting.

Warning

The way the lambda platform works means that promises not awaited by the handler may never be completed. This is because the underlying container can be paused between invocations and will sometimes be shutdown.

export async function badHandler(event: Event, context: Context) {
  somethingAsync(); // not awaited
  return;
}

If you need to return immediately but want to invoke a longer running process you can async-invoke another lambda function (which does the await somethingAsync()).


Configuration

Lambda functions using the deno-lambda-layer:

  • Support Handler i.e. setting the handler file and function.
  • Use HANDLER_EXT to set supported extension e.g. js or bundle.js (default ts).
  • Set DENO_DIR for storing cached assets, default .deno_dir.

Further configuration TBD.

Function code

Create a zip file which contains:

  • an entry point which exports an async function (e.g. hello.ts)
  • any other files needed to run the entry file
  • (optional) .deno_dir directory*

*You can use a different directory by passing it as the DENO_DIR environment variable.

DENO_DIR remapping

Zip the source files and DENO_DIR. In order for compile artifacts to be recovered (avoiding runtime compilation) you need to do the following directory remapping:

# Compile the handler (and fetch dependencies into DENO_DIR).
DENO_DIR=.deno_dir deno fetch hello.ts

# This is the "remapping" step:
cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT
# Note: We do the inverse of this operation in bootstrap.

zip lambda.zip -x '.deno_dir/gen/file/*' -r .deno_dir hello.ts  # other source files

In a serverless.yml this can be automatically prior to each upload using the serverless-scriptable-plugin:

plugins:
  - serverless-scriptable-plugin

custom:
  scriptHooks:
    before:package:createDeploymentArtifacts: DENO_DIR=.deno_dir deno fetch api/candidate.ts && cp -R .deno_dir/gen/file/$PWD/ .deno_dir/LAMBDA_TASK_ROOT

See example/serverless.yml.

Examples


Many thanks to Yoshiya Hinosawa's blogpost for the initial work on this runtime.

You can’t perform that action at this time.