fix(aws-lambda): add jwt and lambda authorizer types for API Gateway v2 - #5142
Merged
yusukebe merged 1 commit intoJul 21, 2026
Merged
Conversation
`ApiGatewayRequestContextV2["authorizer"]` only declared the `iam` variant,
so reading the context of a Lambda (REQUEST) authorizer or a JWT authorizer
was a TypeScript error even though API Gateway populates those keys:
ctx.env.event.requestContext.authorizer.lambda.userId
// Property 'lambda' does not exist on type 'Authorizer'.
The payload format 2.0 event documented by AWS carries `authorizer.jwt`
with `claims` and `scopes`, and a Lambda authorizer's `context` object is
delivered under `authorizer.lambda`. Add both as optional properties,
mirroring `@types/aws-lambda`.
Types only — no runtime change, and `iam` is untouched, so this is
backwards compatible.
Closes honojs#3281
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5142 +/- ##
=======================================
Coverage 79.04% 79.04%
=======================================
Files 154 154
Lines 10779 10779
Branches 2256 2256
=======================================
Hits 8520 8520
Misses 2259 2259 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
yusukebe
approved these changes
Jul 21, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ApiGatewayRequestContextV2["authorizer"]declares only theiamvariant:API Gateway populates two other keys on that object, so reading either one is a
TypeScript error even though the value is present at runtime:
This affects anyone using an HTTP API (payload format 2.0) with a Lambda
(REQUEST) authorizer or a JWT authorizer.
ApiGatewayRequestContextV2isexported from
hono/aws-lambda, so the gap is user-facing. The reportedworkaround is to redeclare the type by hand before using the bindings.
Why these two keys
jwt— AWS's own payload format 2.0 example carriesrequestContext.authorizer.jwtwithclaimsandscopes:https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
lambda— a Lambda authorizer returns an optionalcontextobject(simple response or IAM policy response), which API Gateway delivers to the
integration under
requestContext.authorizer.lambda:https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html
The shapes mirror
@types/aws-lambda(
APIGatewayEventRequestContextJWTAuthorizerandAPIGatewayEventRequestContextLambdaAuthorizer), which the issue cites as thereference.
lambdais typedRecord<string, unknown> | nullrather thangeneric to keep the change contained;
nullis what API Gateway sends when theauthorizer returns no context.
scopesisstring[] | nullbecause a JWT withno scope claim yields
null.Changes
Both properties are optional and
iamis untouched, so this is purely additiveand backwards compatible. Types only — no runtime change.
Tests
Added a
V2 request context authorizerblock tosrc/adapter/aws-lambda/handler.test.tscovering both authorizer variantsend-to-end through
handle(), plus anexpectTypeOfcheck that each variant isoptional and that
scopesacceptsnull.Without the type change these fail
tsc -p tsconfig.spec.jsonwith exactly theerror from the issue:
bun run testpasses: 145 files, 4619 tests.eslintandprettier --checkare clean on the changed files.
Closes #3281
The author should do the following, if applicable
bun run format:fix && bun run lint:fixto format the code