Skip to content

fix: Node.js 24 compatibility — replace callback handlers with async return#111

Merged
rferreira merged 3 commits into
mainfrom
fix/node24-callback-deprecated
May 12, 2026
Merged

fix: Node.js 24 compatibility — replace callback handlers with async return#111
rferreira merged 3 commits into
mainfrom
fix/node24-callback-deprecated

Conversation

@rferreira

@rferreira rferreira commented May 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Both lib/s3-handler.js and lib/ag-handler.js were async functions that still called callback(null, response) — the pattern AWS Lambda Node.js 24 removed (Runtime.CallbackHandlerDeprecated)
  • Converted both to async (event, context) => { return response } — the only supported pattern in Node.js 24+
  • Updated all unit tests to const result = await handler(event, {}) and assert on the returned value
  • Fixed a pre-existing silent test bug in the "should fail to process a directory" fixture: the S3 object key had no trailing / so the directory check never triggered; assertions inside the old callback were silently swallowed by mocha, masking the broken test

Regression guards (so this doesn't happen again)

  1. Unit-test arity assertion. Each handler test asserts handler.length <= 2, matching what AWS's runtime client checks. Cheap, runs on every Node version in the existing matrix.
  2. Runtime init smoke job. New CI job spins up each handler inside public.ecr.aws/lambda/nodejs:24 (Runtime Interface Emulator bundled) and POSTs an invocation. We only fail on Runtime.* errorType in the response (CallbackHandlerDeprecated, ImportModuleError, MalformedHandlerName, …) — handler-side errors from the empty event are expected. Verified locally against a synthetic callback-shaped handler: detected.

Test plan

  • npm test — passing locally (34 unit tests + 4 integration pending without local scanii-cli)
  • PR CI matrix on ubuntu/macos/windows × Node 22/24 covers integration tests via setup-cli-action
  • New Lambda Node 24 runtime init smoke job exercises real runtime init

Fixes #110

rferreira added 3 commits May 12, 2026 12:11
… compatibility

AWS Lambda Node.js 24 runtime removed support for callback-based function handlers
(Runtime.CallbackHandlerDeprecated). Both s3-handler and ag-handler were async
functions still using the deprecated callback(null, response) pattern. Converted
to return the response object directly. Updated all unit tests accordingly; also
fixed a pre-existing silent test bug where the "directory" fixture key had no
trailing slash and assertions inside callbacks were silently swallowed by mocha.

Fixes #110
Two complementary checks to prevent #110 from recurring:

1. Unit-test arity assertion. Each handler test asserts `handler.length <= 2`,
   which is what AWS Lambda's runtime client checks (`errorOnDeprecatedCallback`)
   before deciding whether to reject async-with-callback handlers. Cheap, runs
   on every Node version in the existing matrix.

2. Runtime init smoke job. New CI job spins up each handler inside the official
   `public.ecr.aws/lambda/nodejs:24` image (with the Runtime Interface Emulator
   bundled) and POSTs an invocation. The handler's own assertions on the empty
   event are expected to fail — we only fail CI if the response contains a
   `Runtime.*` errorType (CallbackHandlerDeprecated, ImportModuleError,
   MalformedHandlerName, etc.), which means init itself broke. Verified locally
   against a synthetic callback-shaped handler: detected.
scanii-lambda only ever runs on the Linux Lambda runtime — testing on
windows and macos was burning runner minutes for no signal.
@rferreira
rferreira merged commit d9005b0 into main May 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AWS Lambda for Nodejs24 no longer supports callback-based function handlers

1 participant