Skip to main content

A thin shim for the Lambda Layer aws-lambda-adapter

This package works with Cloudflare Workers, Node.js, Deno, Bun
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
JSR Score
100%
Published
3 weeks ago (0.1.4)

Deno Lambda Adapter

A thin shim for the AWS Lambda layer awslabs/aws-lambda-adapter in Deno, re-wrapping events and context from into a Node.js compatible version.

You may read more about the story at #354.

Usage

  1. Take a brief look at Deno's official guide for AWS Lambda.
  2. Create a Dockerfile for your Lambda function, you may use our example below.
  3. Create an entry point handler.ts using registerHandler from this package.
  4. Build and push your Docker image to ECR.
  5. Create a Lambda function using the image.

Dockerfile

# This Dockerfile is a modified version from the example provided at
# https://docs.deno.com/runtime/tutorials/aws_lambda/
#
# Modifications:
# 1. debian -> alpine
# 2. `timeout 10s deno run` -> `deno cache`

# Set up base images
FROM public.ecr.aws/awsguru/aws-lambda-adapter:0.8.4 AS aws-lambda-adapter
FROM alpine AS runtime

COPY --from=aws-lambda-adapter /lambda-adapter /opt/extensions/lambda-adapter

ENV PORT=8000
EXPOSE 8000

RUN mkdir /var/deno/
ENV DENO_DIR=/var/deno/

# Copy the function code
WORKDIR "/var/task"
COPY . /var/task

# Install deno
RUN apk add --no-cache deno

# Warmup caches
RUN deno cache handler.ts

CMD ["deno", "run", "-A", "handler.ts"]

handler.ts

import { registerHandler } from "jsr:@vicary/lambda-adapter";

registerHandler(async (event, context) => {
  return "Hello World!";
});

Add Package

deno add jsr:@vicary/lambda-adapter

Import symbol

import * as mod from "@vicary/lambda-adapter";

---- OR ----

Import directly with a jsr specifier

import * as mod from "jsr:@vicary/lambda-adapter";

Add Package

npx jsr add @vicary/lambda-adapter

Import symbol

import * as mod from "@vicary/lambda-adapter";

Add Package

yarn dlx jsr add @vicary/lambda-adapter

Import symbol

import * as mod from "@vicary/lambda-adapter";

Add Package

pnpm dlx jsr add @vicary/lambda-adapter

Import symbol

import * as mod from "@vicary/lambda-adapter";

Add Package

bunx jsr add @vicary/lambda-adapter

Import symbol

import * as mod from "@vicary/lambda-adapter";