A lightweight, zero-dependency Deno library for AWS Lambda that implements the AWS Lambda Runtime API.
Designed for use with deno compile to create binaries deployable to AWS Lambda
using the
provided.al2023
runtime.
While aws-lambda-web-adapter is officially recommended by Deno for web applications, it requires an HTTP server. This project enables you to create general-purpose Lambda functions in Deno for services like EventBridge, SQS, and other non-HTTP event sources without the overhead of an HTTP server.
import { start } from "jsr:@atty303/aws-lambda-runtime";Create a simple Lambda function:
import { Context, Handler, start } from "jsr:@atty303/aws-lambda-runtime";
interface Event {
name: string;
}
const handler: Handler<Event> = async (event, context) => {
return {
statusCode: 200,
body: JSON.stringify({
message: `Hello, ${event.name}!`,
requestId: context.awsRequestId,
}),
};
};
start(handler);type Handler<A> = (
event: A,
context: Context,
) => unknown | Promise<unknown>;The main handler function type that processes Lambda events.
type Context = {
awsRequestId: string;
invokedFunctionArn?: string;
deadlineMs: number;
functionName?: string;
functionVersion?: string;
memoryLimitInMB?: string;
logGroupName?: string;
logStreamName?: string;
clientContext?: unknown;
identity?: unknown;
getRemainingTimeInMillis(): number;
};The Lambda context object containing runtime information.
Starts the Lambda runtime with the provided handler function. This function runs indefinitely, processing incoming Lambda invocations.
Parameters:
handler: The function to handle Lambda events
Example:
import { start } from "jsr:@atty303/aws-lambda-runtime";
const myHandler = async (event, context) => {
// Your handler logic here
return { success: true };
};
start(myHandler);Create a template.yaml:
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
MyFunction:
Type: AWS::Serverless::Function
Metadata:
BuildMethod: makefile
Properties:
CodeUri: .
Handler: bootstrap
Runtime: provided.al2023
Architectures:
- arm64
Environment:
Variables:
DENO_DIR: /tmpCreate a Makefile:
.PHONY: build-MyFunction
build-MyFunction:
deno compile -A --target aarch64-unknown-linux-gnu -o $(ARTIFACTS_DIR)/bootstrap src/main.tsBuild and deploy with SAM:
sam deployYou can use terraform-aws-modules/lambda/aws to build and deploy your function:
module "my_lambda" {
source = "terraform-aws-modules/lambda/aws"
version = "~> 8"
function_name = "my-function"
handler = "bootstrap"
runtime = "provided.al2023"
architectures = ["arm64"]
environment_variables = {
DENO_DIR = "/tmp"
}
source_path = [{
path = "function_dir"
commands = [
"set -e",
"deno compile -A --target aarch64-unknown-linux-gnu --output dist/bootstrap src/main.ts",
":zip dist",
]
}]
}- mise installed
mise install
hk install --mise