new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Bun · all subjects

deployment/aws-lambda

9 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

AWS Lambda deployment prerequisites

To deploy a Bun application on AWS Lambda, you need: a Bun application ready for deployment, an AWS account, AWS CLI installed and configured, and Docker installed and added to your PATH.

Dockerfile for AWS Lambda with Bun

The Dockerfile uses the official AWS Lambda adapter image (public.ecr.aws/awsguru/aws-lambda-adapter:0.9.0) as a base, then uses the official Bun image (oven/bun:debian). The Lambda adapter is copied to /opt/extensions/lambda-adapter. The PORT environment variable must be set to 8080 for the AWS Lambda adapter. The working directory is /var/task, which is the default for Lambda. Dependencies are installed with `bun install --production --frozen-lockfile`. The application is started with `CMD ["bun", "index.ts"]` or `CMD ["bun", "run", "start"]` depending on the entry point.

.dockerignore for Bun Lambda

A .dockerignore file should exclude: node_modules, Dockerfile*, .dockerignore, .git, .gitignore, README.md, LICENSE, .vscode, .env, and any other files or directories you want to exclude from the container image.

Docker build command for AWS Lambda

Build the Docker image with `docker build --provenance=false --platform linux/amd64 -t bun-lambda-demo:latest .` to ensure it is built for the linux/amd64 platform required by AWS Lambda.

Create ECR repository for Lambda image

Create an ECR repository with the AWS CLI command: `aws ecr create-repository --repository-name bun-lambda-demo --region us-east-1 --query 'repository.repositoryUri' --output text`. This creates a repository in the us-east-1 region. If using AWS CLI profiles or SSO, add the `--profile` flag with your profile name. The command returns the repository URI.

Authenticate Docker with ECR

Log in to the ECR repository with `aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $ECR_URI`. If using a profile, add the `--profile` flag: `aws ecr get-login-password --region us-east-1 --profile my-sso-app | docker login --username AWS --password-stdin $ECR_URI`.

Push Docker image to ECR

Tag the Docker image with the ECR repository URI using `docker tag bun-lambda-demo:latest ${ECR_URI}:latest`, then push it with `docker push ${ECR_URI}:latest`.

AWS Lambda function configuration for Bun

Create the Lambda function via AWS Console > Lambda > Create Function, select Container image as the source. Give the function a name and select the container image from the ECR repository. To expose the function via a public URL, go to Additional configurations > Networking > Function URL and set it to Enable with Auth Type NONE.

Test AWS Lambda Bun function

After the function is created, the function URL can be found in the Function URL section on the function's page. Test the function by calling it directly with curl: `curl -X GET https://[your-function-id].lambda-url.us-east-1.on.aws/`.

Give your agent this brain