Skip to main content
AWS Lambda is a serverless compute service that runs code without requiring you to provision or manage servers. Bun can run on AWS Lambda via a Docker container image using the AWS Lambda Web Adapter.
Before continuing, make sure you have:
1

Create a Dockerfile

The AWS Lambda Web Adapter bridges Lambda’s event-based invocation model with a standard HTTP server. Create a Dockerfile in your project root:
Dockerfile
Adjust the CMD to match your application’s entry point. If you have a start script in package.json, you can use CMD ["bun", "run", "start"] instead.
Also create a .dockerignore to keep the image small:
.dockerignore
2

Write a Bun HTTP server

Your server must listen on the port defined by the PORT environment variable (Lambda sets this to 8080):
index.ts
3

Build the Docker image

Build the image targeting the linux/amd64 platform, which Lambda requires. The --provenance=false flag avoids a known ECR compatibility issue.
4

Create an ECR repository

Create an Amazon Elastic Container Registry (ECR) repository to host the image, and export its URI:
If you use IAM Identity Center (SSO), append --profile <your-profile> to every AWS CLI command.
5

Authenticate and push the image

Log in to ECR and push the image:
6

Create an AWS Lambda function

In the AWS Console, navigate to Lambda → Create function → Container image.
  • Give the function a name (e.g., my-bun-function).
  • Under Container image URI, click Browse images and select the image you just pushed, choosing the latest tag.
7

Configure a public URL

To expose the function over HTTPS without an API Gateway:
  1. Open Additional configurations → Networking → Function URL.
  2. Set Auth type to NONE and click Enable.
  3. Click Create function.
The function URL appears on the function’s overview page.
8

Test the function

Call the function URL directly:

Environment variables

Set environment variables in the Lambda console under Configuration → Environment variables, or via the AWS CLI:
Access them in your code with process.env or Bun.env:

IAM permissions

Lambda functions execute with the permissions of their associated IAM execution role. To grant your function access to other AWS services (e.g., S3, DynamoDB), attach the relevant managed policies or inline policies to the execution role in IAM → Roles.