Cloud & deploymentDeploy to AWS Lambda

Deploy to AWS Lambda

Run a standard Bun HTTP service on Lambda via a container image and the Lambda Web Adapter

Last updated on

What you get

An unmodified Bun.serve service packaged as a container image running on Lambda. The Lambda Web Adapter runs as an extension and translates Lambda events into plain HTTP requests, which requires the service to listen on 8080.

1. Keep the service in plain HTTP shape

index.ts
const server = Bun.serve({
  port: Number(Bun.env.PORT ?? 8080),
  routes: {
    '/': () => new Response('Hello from Bun on Lambda!'),
  },
});

console.log(`Listening on ${server.url}`);

Don't rewrite handlers for the Lambda event model; the adapter does the translation.

2. Dockerfile

Dockerfile
FROM public.ecr.aws/awsguru/aws-lambda-adapter:0.9.0 AS aws-lambda-adapter
FROM oven/bun:debian

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

WORKDIR /var/task
COPY package.json bun.lock ./
RUN bun install --production --frozen-lockfile
COPY index.ts ./

ENV PORT=8080
CMD ["bun", "index.ts"]

Add a .dockerignore with node_modules, .git, .env, coverage, etc. Pin validated versions or digests for both the adapter and the Bun image.

3. Build and push to ECR

docker build --provenance=false --platform linux/amd64 -t bun-lambda-demo:latest .

aws ecr create-repository --repository-name bun-lambda-demo
aws ecr get-login-password | docker login --username AWS --password-stdin <ECR_URI>

docker tag bun-lambda-demo:latest <ECR_URI>/bun-lambda-demo:latest
docker push <ECR_URI>/bun-lambda-demo:latest

--platform linux/amd64 produces the Lambda architecture even on Apple Silicon; adjust accordingly for arm64 functions.

4. Create the function

  1. In the Lambda console, create the function with the Container image option and select the pushed ECR image;
  2. For public testing, enable a Function URL with Auth Type NONE;
  3. curl the function URL and expect Hello from Bun on Lambda!.

Auth Type NONE is a public endpoint

NONE is for demos only. Production functions should use AWS_IAM or sit behind your own auth; public endpoints also need rate limiting, cost, and abuse evaluation.

Boundaries

  • This page only covers the official container + Web Adapter path, not a provided.al2023 custom runtime.
  • Lambda remains an event model: local disk beyond snapshots, background tasks, and long-lived connections are not guaranteed; WebSockets don't fit this path.
  • Timeout, memory, and concurrency follow the function configuration; AI streaming is bounded by both Lambda limits and Bun.serve's idleTimeout β€” see Serverless and edge.
  • Measure cold starts on the target memory size; image size directly affects them.

Acceptance

  1. The Function URL returns the expected response with no adapter startup errors in logs;
  2. Cold start and p95 latency meet targets at the configured memory;
  3. Images are pinned by version/digest and the CI build is reproducible;
  4. No production function exposes a public NONE-auth URL.

Official references: Bun on AWS Lambda, AWS Lambda Web Adapter.