Skip to content

fix(aws-lambda): fix awsRequest to return request with runtime metadata#4288

Open
fossamagna wants to merge 1 commit into
nitrojs:mainfrom
fossamagna:fix-4287
Open

fix(aws-lambda): fix awsRequest to return request with runtime metadata#4288
fossamagna wants to merge 1 commit into
nitrojs:mainfrom
fossamagna:fix-4287

Conversation

@fossamagna
Copy link
Copy Markdown

Closes #4287

Summary

Fixes two bugs in awsRequest() in src/presets/aws-lambda/runtime/_utils.ts that caused request.runtime.awsLambda to always be undefined in request handlers.

Bug 1: Runtime metadata was discarded
The function set req.runtime.aws on a ServerRequest object, but then returned a brand-new Request object, losing all the runtime metadata that had just been set.

Bug 2: Wrong property name (awsawsLambda)
The runtime context was stored under req.runtime.aws, but srvx's ServerRequest type exposes it as runtime.awsLambda. The @ts-expect-error suppression was masking this type mismatch.

Changes

  • Return the original req object instead of creating a new Request
  • Rename req.runtime.awsreq.runtime.awsLambda (aligns with srvx types, removes @ts-expect-error)
  • Type context parameter as Context instead of unknown
  • Add unit tests for awsRequest()

Motivation

Users relying on request.runtime.awsLambda to access the Lambda event and context (e.g. for use with @aws-lambda-powertools/logger) would always receive undefined.

fetch(request) {
  const runtime = (request as ServerRequest).runtime;
  if (runtime?.name === "aws-lambda" && runtime.awsLambda) {
    logger.addContext(runtime.awsLambda.context);
    logger.logEventIfEnabled(runtime.awsLambda.event);
  }
}

@fossamagna fossamagna requested a review from pi0 as a code owner May 26, 2026 14:22
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

Someone is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 104ccbde-a275-4bc6-82de-d48e3c621818

📥 Commits

Reviewing files that changed from the base of the PR and between 5d21dd2 and 6d912f8.

📒 Files selected for processing (2)
  • src/presets/aws-lambda/runtime/_utils.ts
  • test/unit/aws-lambda.utils.test.ts

📝 Walkthrough

Walkthrough

The PR fixes two critical bugs in the AWS Lambda preset's awsRequest() function: a missing type annotation for the context parameter and incorrect property naming/return behavior that prevented accessing Lambda runtime metadata from request handlers.

Changes

AWS Lambda request runtime metadata fix

Layer / File(s) Summary
Signature typing and implementation fix
src/presets/aws-lambda/runtime/_utils.ts
awsRequest now accepts a properly typed Context parameter, sets runtime.awsLambda (not runtime.aws) with event and context, and returns the same ServerRequest instance instead of creating a new Request object that discards runtime metadata.
Unit test for awsRequest runtime metadata
test/unit/aws-lambda.utils.test.ts
New Vitest suite verifying that awsRequest returns a Request with runtime.name set to "aws-lambda" and runtime.awsLambda containing the original event and context references.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title follows conventional commits format with the 'fix' type and aws-lambda scope, and accurately summarizes the main change.
Description check ✅ Passed The pull request description is clearly related to the changeset, detailing the two bugs being fixed, the changes made, and the motivation.
Linked Issues check ✅ Passed The PR fully addresses all coding requirements from issue #4287: returns the original request with runtime metadata, renames aws to awsLambda, types context as Context, and includes unit tests.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the identified bugs and testing the fix; no out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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 preset: awsRequest() returns a new Request object without runtime metadata, and uses wrong property name (aws instead of awsLambda)

1 participant