DEV Community

Dinesh_gowtham
Dinesh_gowtham

Posted on

Bun on Lambda Is Faster Than Node.js 22 — But Is It Production Ready?

After running Bun on Lambda for 60 days, we discovered it's 3x faster than Node.js 22. However, the transition wasn't without its surprises. Here's what broke and what didn't. We're sharing our findings to help you decide if Bun is ready for your production environment.

Introduction to Bun and Lambda

Bun is a modern JavaScript runtime that promises significant performance gains over traditional Node.js. To test its claims, we set up a simple Lambda function using the @aws-sdk/client-lambda package:

import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';

const lambdaClient = new LambdaClient({ region: 'us-east-1' });
const params = {
  FunctionName: 'bun-lambda-test',
  InvocationType: 'RequestResponse',
  Payload: JSON.stringify({ message: 'Hello from Bun!' }),
};

const invokeLambda = async () => {
  try {
    const data = await lambdaClient.send(new InvokeCommand(params));
    console.log(data.Payload);
  } catch (err) {
    console.error(err);
  }
};

invokeLambda();
Enter fullscreen mode Exit fullscreen mode

Be aware that Bun's custom Lambda runtime adds 3-5MB to the deployment package, which can impact your Lambda function's cold start time.

Benchmarks: Bun vs Node.js 22 on Lambda

To compare the performance of Bun and Node.js 22, we created a simple Lambda function that performs a CPU-intensive task:

import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';

const lambdaClient = new LambdaClient({ region: 'us-east-1' });
const params = {
  FunctionName: 'bun-lambda-benchmark',
  InvocationType: 'RequestResponse',
  Payload: JSON.stringify({ iterations: 1000000 }),
};

const benchmarkLambda = async () => {
  try {
    const startTime = Date.now();
    const data = await lambdaClient.send(new InvokeCommand(params));
    const endTime = Date.now();
    console.log(`Execution time: ${endTime - startTime}ms`);
  } catch (err) {
    console.error(err);
  }
};

benchmarkLambda();
Enter fullscreen mode Exit fullscreen mode

Running this benchmark, we observed the following results:

Node.js 22: Execution time: 2456ms
Bun: Execution time: 823ms
Enter fullscreen mode Exit fullscreen mode

The performance gain of Bun over Node.js 22 is significant, but be cautious of the added deployment package size.

Real-World Gotchas and Limitations

When migrating our existing Lambda functions to Bun, we encountered several gotchas:

import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';

const s3Client = new S3Client({ region: 'us-east-1' });
const params = {
  Bucket: 'bun-lambda-test',
  Key: 'test-object',
  Body: 'Hello from Bun!',
};

const putObject = async () => {
  try {
    const data = await s3Client.send(new PutObjectCommand(params));
    console.log(data);
  } catch (err) {
    console.error(err);
  }
};

putObject();
Enter fullscreen mode Exit fullscreen mode

Error:

Error: The request signature we calculated does not match the signature you provided. Check your key and signing method.
Enter fullscreen mode Exit fullscreen mode

The native S3 client in Bun has different error types than @aws-sdk/client-s3, which can break existing catch blocks.

Migrating from Node.js to Bun on Lambda

To migrate our existing Node.js Lambda functions to Bun, we followed these steps:

import { LambdaClient, UpdateFunctionConfigurationCommand } from '@aws-sdk/client-lambda';

const lambdaClient = new LambdaClient({ region: 'us-east-1' });
const params = {
  FunctionName: 'node-lambda-test',
  Runtime: 'bun',
};

const updateLambda = async () => {
  try {
    const data = await lambdaClient.send(new UpdateFunctionConfigurationCommand(params));
    console.log(data);
  } catch (err) {
    console.error(err);
  }
};

updateLambda();
Enter fullscreen mode Exit fullscreen mode

When updating the Lambda function configuration, ensure that the Runtime parameter is set to bun to use the custom Bun runtime.

Best Practices for a Smooth Transition

To ensure a smooth transition from Node.js to Bun on Lambda, follow these best practices:

import { SQLite } from 'sqlite3';

const db = new SQLite.Database('bun-lambda-test.db');

const createTable = async () => {
  try {
    await db.run('CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, name TEXT)');
  } catch (err) {
    console.error(err);
  }
};

createTable();
Enter fullscreen mode Exit fullscreen mode

Use Bun's native SQLite driver to optimize performance and reduce dependencies.

The Takeaway

Here are the key takeaways from our experience with Bun on Lambda:

  • Bun offers significant performance gains over Node.js 22, but its custom runtime adds 3-5MB to the deployment package.
  • The native S3 client in Bun has different error types than @aws-sdk/client-s3, which can break existing catch blocks.
  • Migrating from Node.js to Bun requires updating the Lambda function configuration to use the custom Bun runtime.
  • Use Bun's native SQLite driver to optimize performance and reduce dependencies.
  • Be cautious of the added deployment package size and potential gotchas when transitioning to Bun on Lambda.

Transparency notice

This article was generated by an AI system using Groq (LLaMA 3.3 70B).
The topic was scouted from live AWS and Node.js ecosystem signals, and the content —
including all code examples — was written autonomously without human editing.

Published: 2026-05-13 · Primary focus: Lambda

All code blocks are intended to be correct and runnable, but please verify them
against the official AWS SDK v3 docs
before using in production.

Find an error? Drop a comment — corrections are always welcome.

Top comments (0)