Dockerfile.
Before continuing, make sure you have:
- A Bun application ready for deployment
- An AWS account
- AWS CLI installed and configured
- Docker installed and added to your
PATH
1
Create a new Dockerfile
Make sure you’re in the directory containing your project, then create a new Create a new
Dockerfile in the root of your project. This file contains the instructions to initialize the container, copy your local project files into it, install dependencies, and start the application.Dockerfile
Make sure that the start command corresponds to your application’s entry point. This can also be
CMD ["bun", "run", "start"] if you have a start script in your package.json.This image installs dependencies and runs your app with Bun inside a container. If your app doesn’t have dependencies, you can omit the RUN bun install --production --frozen-lockfile line..dockerignore file in the root of your project. This file contains the files and directories that should be excluded from the container image, such as node_modules. This makes your builds faster and smaller:.dockerignore
2
Build the Docker image
Make sure you’re in the directory containing your
Dockerfile, then build the Docker image. In this case, we’ll call the image bun-lambda-demo and tag it as latest.terminal
3
Create an ECR repository
To push the image to AWS Lambda, we first need to create an ECR repository to push the image to.By running the following command, we:
- Create an ECR repository named
bun-lambda-demoin theus-east-1region - Get the repository URI, and export the repository URI as an environment variable. This is optional, but make the next steps easier.
terminal
If you’re using IAM Identity Center (SSO) or have configured AWS CLI with profiles, you’ll need to add the
--profile flag to your AWS CLI commands.For example, if your profile is named my-sso-app, use --profile my-sso-app. Check your AWS CLI configuration with aws configure list-profiles to see available profiles.terminal
4
Authenticate with the ECR repository
Log in to the ECR repository:
terminal
If using a profile, use the
--profile flag:terminal
5
Tag and push the docker image to the ECR repository
Make sure you’re in the directory containing your Then, push the image to the ECR repository.
Dockerfile, then tag the docker image with the ECR repository URI.terminal
terminal
6
Create an AWS Lambda function
Go to AWS Console > Lambda > Create Function > Select Container image
Give the function a name, like
Make sure you’ve selected the right region, this URL defaults to
us-east-1.
my-bun-function.7
Select the container image
Then, go to the Container image URI section, click on Browse images. Select the image we just pushed to the ECR repository.
Then, select the 

latest image, and click on Select image.
8
Configure the function
To get a public URL for the function, we need to go to Additional configurations > Networking > Function URL.Set this to Enable, with Auth Type NONE.

9
Create the function
Click on Create function at the bottom of the page, this will create the function.

10
Get the function URL
Once the function has been created you’ll be redirected to the function’s page, where you can see the function URL in the “Function URL” section.

11
Test the function
🥳 Your app is now live! To test the function, you can either go to the Test tab, or call the function URL directly.
terminal