Trying Out the Node.js 24 Runtime on AWS Lambda
ちょっと話題の記事

Trying Out the Node.js 24 Runtime on AWS Lambda

Testing AWS Lambda's Node.js 24 runtime, supported in November 2025: CLI and CloudFormation deployment steps, plus a hands-on check of the Runtime.CallbackHandlerDeprecated error raised by deprecated callback-style handlers.
2025.11.28

This page has been translated by machine translation. View original

On November 25, 2025, AWS Lambda began supporting Node.js 24.

AWS Lambda adds support for Node.js 24 | AWS What's New

The Node.js 24 runtime includes important changes that affect development practices, such as the removal of the traditional callback-based function handler, leaving only the async/await pattern supported. This article introduces the results of verifying deployment using the AWS CLI and CloudFormation, and of checking the error behavior when using the callback style.

Verification Environment

  • OS: Linux (Amazon Linux 2023)
  • AWS CLI: aws-cli/2.32.6
  • Region: us-east-1
  • Deployment methods: AWS CLI, CloudFormation

1. Deploying an ES Modules Function with the AWS CLI

First, I specified the nodejs24.x runtime and created a function using the ES Modules format (import/export).

index.js

export const handler = async (event) => {
  console.log('Event:', JSON.stringify(event, null, 2));

  return {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Hello from Node.js 24!',
      timestamp: new Date().toISOString()
    })
  };
};

package.json
To enable ES Modules, I specified "type": "module".

{
  "type": "module"
}

I created a zip file with the following commands, then created and invoked the Lambda function.

# Create zip file
zip function.zip index.js package.json

# Create Lambda function
aws lambda create-function \
  --function-name node24-hello-world \
  --runtime nodejs24.x \
  --handler index.handler \
  --role arn:aws:iam::123456789012:role/service-role/lambda-execution-role \
  --zip-file fileb://function.zip \
  --region us-east-1

# Invoke
aws lambda invoke \
  --function-name node24-hello-world \
  --region us-east-1 \
  response.json

Execution result (response.json)

{
  "statusCode": 200,
  "body": "{\"message\":\"Hello from Node.js 24!\",\"timestamp\":\"2025-11-28T10:00:00.000Z\"}"
}

I confirmed that deployment to the nodejs24.x runtime via the CLI and ES Modules work correctly.

I was also able to confirm the operation of the Node.js 24.x runtime Lambda function in the web console.

nodejs24_Lambda screen

2. Deploying with CloudFormation

Next, I verified deployment using a CloudFormation template. Because package.json cannot be included when using the ZipFile property, I wrote the code in CommonJS format here.

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Description: Node.js 24 Lambda Function Test

Resources:
  LambdaExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service: lambda.amazonaws.com
            Action: sts:AssumeRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

  Node24Function:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: node24-cfn-test
      Runtime: nodejs24.x
      Handler: index.handler
      Role: !GetAtt LambdaExecutionRole.Arn
      Code:
        ZipFile: |
          exports.handler = async (event) => {
            console.log('Event:', JSON.stringify(event, null, 2));
            return {
              statusCode: 200,
              body: JSON.stringify({
                message: 'Hello from Node.js 24 via CloudFormation!',
                timestamp: new Date().toISOString()
              })
            };
          };

After deployment, I confirmed that the stack status became CREATE_COMPLETE.
I confirmed that Node.js 24.x can be used without problems in CloudFormation as well.

3. Verifying the Behavior of the Removed Callback Style

Regarding the biggest change in Node.js 24, "the removal of the callback style," I actually deployed code in the removed style and checked the logs to see what kind of error occurs.

Test code (callback-handler.js)

exports.handler = (event, context, callback) => {
  console.log('Event:', JSON.stringify(event, null, 2));

  // Style not supported in Node.js 24
  callback(null, {
    statusCode: 200,
    body: JSON.stringify({
      message: 'Hello from callback handler'
    })
  });
};

Execution result (Invocation Error)

When I ran aws lambda invoke, the following Runtime.CallbackHandlerDeprecated error was returned.

{
  "StatusCode": 200,
  "FunctionError": "Unhandled",
  "ExecutedVersion": "$LATEST"
}

CloudWatch Logs output

{
  "errorType": "Runtime.CallbackHandlerDeprecated",
  "errorMessage": "ERROR: AWS Lambda has removed support for callback-based function handlers starting with Node.js 24. You need to modify this function to use a supported handler signature to use Node.js 24 or later. For more information see https://docs.aws.amazon.com/lambda/latest/dg/nodejs-handler.html."
}

As clearly stated in the error message, I confirmed that using a callback-based handler in Node.js 24 and later results in a runtime error and the execution fails. This demonstrated that rewriting to async/await is mandatory when migrating existing code.

4. Verifying Error Handling

I also checked the behavior of error handling in the async/await pattern.

Test code (error-handler.js)

exports.handler = async (event) => {
  // Error handling with try-catch
  try {
    if (event.tryCatchError) {
      throw new Error('Error caught in try-catch');
    }
    return { statusCode: 200, body: 'Success' };
  } catch (error) {
    console.error('Caught error:', error);
    return {
      statusCode: 500,
      body: JSON.stringify({ error: error.message })
    };
  }
};

Execution result

This is the result when sending the payload {"tryCatchError":true}.

{
  "statusCode": 500,
  "body": "{\"error\":\"Error caught in try-catch\"}"
}

As intended, the error was caught in the catch block and a response with status code 500 was returned. I confirmed that, instead of the traditional callback(error), control is possible with the standard JavaScript try-catch syntax.

Summary

Through this verification, I was able to confirm the following behaviors of the AWS Lambda Node.js 24 runtime.

  • Deployment to nodejs24.x works correctly with both the AWS CLI and CloudFormation.
  • ES Modules (type: module) are supported.
  • Callback-style handlers result in a Runtime.CallbackHandlerDeprecated error and cannot be executed at all.
  • Error handling has been unified into the standard approach using async/await and try-catch.

Node.js 24 is scheduled to receive long-term support (LTS) until April 2028. Since you can enjoy the latest features and a long support period, I recommend adopting this version for new development.

Migrating to Node.js 24 entails a major change: the removal of the long-familiar callback style. Depending on your existing assets, code modification costs will arise, but I encourage you to take this opportunity to fully migrate to the async/await pattern and consider modernization such as improved readability and unification on standard error handling.


AWS re:Invent 2025まとめ情報

クラスメソッドは2025/12/1〜5にラスベガスで開催されたAWSカンファレンスイベント「re:Invent」を今年も特集しました。ぜひ一度ご覧ください。 re:Invent 2025ポータルサイトを見るAWS re:Inventはこちら

Share this article

AWSのお困り事はクラスメソッドへ