Deploy a Bun application on AWS Lambda - BunDocumentation Index Search...⌘KInstall Bun Search...Navigation Deployment Deploy a Bun application on AWS LambdaRuntimePackage ManagerBundlerTest RunnerGuidesReferenceBlogFeedback:first-child]:!hidden peer-[.is-custom]:[&>:first-child]:sm:!hidden peer-[.is-custom]:[&>:first-child]:md:!hidden peer-[.is-custom]:[&>:first-child]:lg:!hidden peer-[.is-custom]:[&>:first-child]:xl:!hidden">OverviewGuidesDeploymentDeploy on VercelDeploy on RailwayDeploy on RenderDeploy on AWS LambdaDeploy on DigitalOceanDeploy on Google Cloud RunRuntime & DebuggingTypeScript typesRe-map import pathsVS Code debuggerWeb debuggerHeap snapshotsBuild-time constantsDefine constantsGitHub ActionsCodesign on macOSUtilitiesUpgrade BunDetect BunGet Bun versionHash passwordGenerate UUIDBase64 encodingGzip compressionDEFLATE compressionEscape HTMLDeep equalitySleepFile URL to pathPath to file URLFind executable pathimport.meta.dirimport.meta.fileimport.meta.pathCheck entrypointGet entrypoint pathEcosystem & FrameworksAstro with BunDiscord.js with BunDocker with BunDrizzle with BunGel with BunElysia with BunExpress with BunHono with BunMongoose with BunNeon Drizzle with BunNeon Serverless Postgres with BunNext.js with BunNuxt with BunPM2 with BunPrisma ORM with BunPrisma Postgres with BunQwik with BunReact with BunRemix with BunTanStack Start with BunSentry with BunSolidStart with BunSSR React with BunStricJS with BunSvelteKit with Bunsystemd with BunVite with BunUpstash with BunHTTP & NetworkingHTTP Server with BunSimple HTTP Server with BunFetch with BunHot reload an HTTP serverStart a cluster of HTTP serversConfigure TLSProxy HTTP requests using fetch()Stream file responseUpload files via HTTP using FormDataFetch with unix domain socketsStream with iteratorsServer-Sent EventsStream with Node.jsWebSocketSimple serverPub-sub serverContextual dataEnable compressionProcesses & SystemSpawn child processRead stdoutRead stderrParse command-line argumentsRead from stdinSpawn a child process and communicate using IPCListen for CTRL+COS signalsProcess uptimeRun shell commandSet time zoneSet env variablesRead env variablesPackage ManagerAdd a dependencyAdd a dev dependencyAdd an optional dependencyAdd a peer dependencyAdd a Git dependencyAdd a tarball dependencyInstall with aliasWorkspaces with BunOverride the default npm registryConfigure a scoped registryAzure Artifacts with BunJFrog Artifactory with BunAdd a trusted dependencyGenerate a yarn-compatible lockfileMigrate from npm to bunConfigure git to diff Bun's lockfileInstall Bun in GitHub ActionsTest RunnerRun testsWatch modeMigrate from JestMock functionsSpy on methodsMock system timeSnapshot testingUpdate snapshotsCoverage reportsCoverage thresholdConcurrent test globSkip testsTodo testsTest timeoutBail earlyRe-run testsTesting LibraryDOM testsTest SvelteRuntime & DebuggingVS Code debuggerWeb debuggerHeap snapshotsBuild-time constantsDefine constantsGitHub ActionsCodesign on macOSModule SystemImport JSONImport TOMLImport YAMLImport JSON5Import HTMLimport.meta.dirimport.meta.fileimport.meta.pathCheck entrypointGet entrypoint pathFile SystemRead as stringRead to BufferRead to Uint8ArrayRead to ArrayBufferRead JSON fileGet MIME typeCheck file existsWatch directoryRead as streamWrite string to fileWrite BlobWrite ResponseAppend to fileIncremental writeWrite streamWrite to stdoutWrite file to stdoutCopy fileDelete fileDelete filesDelete directoriesUtilitiesHash passwordGenerate UUIDBase64 encodingGzip compressionDEFLATE compressionEscape HTMLDeep equalitySleepFile URL to pathPath to file URLFind executable pathHTML ProcessingExtract links using HTMLRewriterOpenGraph tagsBinary DataArrayBuffer to stringArrayBuffer to BufferArrayBuffer to BlobArrayBuffer to ArrayArrayBuffer to Uint8ArrayBuffer to stringBuffer to ArrayBufferBuffer to BlobBuffer to Uint8ArrayBuffer to ReadableStreamBlob to stringBlob to ArrayBufferBlob to Uint8ArrayBlob to DataViewBlob to ReadableStreamUint8Array to stringUint8Array to ArrayBufferUint8Array to BufferUint8Array to BlobUint8Array to DataViewUint8Array to ReadableStreamDataView to stringStreamsStream to stringStream to JSONStream to BlobStream to BufferStream to ArrayBufferStream to Uint8ArrayStream to arrayReadable to stringReadable to JSONReadable to BlobReadable to Uint8ArrayReadable to ArrayBufferDeploymentDeploy a Bun application on AWS Lambda Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_n4ctdbsnlht5lebsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed"> Copy pagespan]:line-clamp-1 overflow-hidden group flex items-center py-0.5 gap-1 text-sm text-gray-950/50 dark:text-white/50 group-hover:text-gray-950/70 dark:group-hover:text-white/70 rounded-none rounded-r-xl border px-3 border-gray-200 aspect-square dark:border-white/[0.07] bg-background-light dark:bg-background-dark hover:bg-gray-600/5 dark:hover:bg-gray-200/5" aria-label="More actions" type="button" id="radix-_R_1cctdbsnlht5lebsnpfdb_" aria-haspopup="menu" aria-expanded="false" data-state="closed"> AWS Lambda is a serverless compute service that lets you run code without provisioning or managing servers.
In this guide, we will deploy a Bun HTTP server to AWS Lambda using a 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 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.Create a new .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 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 If using a profile, use the --profile flag:terminal Make sure you’ve selected the right region, this URL defaults to us-east-1. Give the function a name, like my-bun-function.7 Then, select the latest image, and click on Select image. 8 9 10 11 Yes NoSuggest editsRaise issueDeploy a Bun application on RenderPreviousDeploy a Bun application on DigitalOceanNext⌘I xgithubdiscordyoutubePowered byThis documentation is built and hosted on Mintlify, a developer documentation platform
Fetch the complete documentation index at: /docs/llms.txt
Use this file to discover all available pages before exploring further.
Skip to main contentBun home pageCreate a new Dockerfile
Make sure you’re in the directory containing your project, then 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# Use the official AWS Lambda adapter image to handle the Lambda runtime FROM public.ecr.aws/awsguru/aws-lambda-adapter:0.9.0 AS aws-lambda-adapter # Use the official Bun image to run the application FROM oven/bun:debian AS bun_latest # Copy the Lambda adapter into the container COPY --from=aws-lambda-adapter /lambda-adapter /opt/extensions/lambda-adapter # Set the port to 8080. This is required for the AWS Lambda adapter. ENV PORT=8080 # Set the work directory to `/var/task`. This is the default work directory for Lambda. WORKDIR "/var/task" # Copy the package.json and bun.lock into the container COPY package.json bun.lock ./ # Install the dependencies RUN bun install --production --frozen-lockfile # Copy the rest of the application into the container COPY . /var/task # Run the application. CMD ["bun", "index.ts"]
node_modules Dockerfile* .dockerignore .git .gitignore README.md LICENSE .vscode .env # Any other files or directories you want to exclude2
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# cd /path/to/your/app docker build --provenance=false --platform linux/amd64 -t bun-lambda-demo:latest .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-demo in the us-east-1 region Get the repository URI, and export the repository URI as an environment variable. This is optional, but make the next steps easier. terminalexport ECR_URI=$(aws ecr create-repository --repository-name bun-lambda-demo --region us-east-1 --query 'repository.repositoryUri' --output text) echo $ECR_URI
[id].dkr.ecr.us-east-1.amazonaws.com/bun-lambda-demo
export ECR_URI=$(aws ecr create-repository --repository-name bun-lambda-demo --region us-east-1 --profile my-sso-app --query 'repository.repositoryUri' --output text) echo $ECR_URI4
Authenticate with the ECR repository
Log in to the ECR repository:terminalaws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_URI
Login Succeeded
aws ecr get-login-password --region us-east-1 --profile my-sso-app | docker login --username AWS --password-stdin $ECR_URI5
Tag and push the docker image to the ECR repository
Make sure you’re in the directory containing your Dockerfile, then tag the docker image with the ECR repository URI.terminaldocker tag bun-lambda-demo:latest ${ECR_URI}:latest
Then, push the image to the ECR repository.terminaldocker push ${ECR_URI}:latest
6Create an AWS Lambda function
Go to AWS Console > Lambda > Create Function > Select Container imageSelect 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.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.Create the function
Click on Create function at the bottom of the page, this will create the function.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.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.terminalcurl -X GET https://[your-function-id].lambda-url.us-east-1.on.aws/
Hello from Bun on Lambda!
Was this page helpful?
Deploy a Bun application on AWS Lambda - Bun,AI智能索引,全网链接索引,智能导航,网页索引
- Deploy a Bun application on AWS Lambda - Bun - 提供全网公开链接智能索引服务,快速访问目标内容,支持分类筛选和智能导航