Conversation
A Lambda-authorized Event API populates `ctx.identity` with
`{"handlerContext": {...}}` — an empty object when the authorizer returned no
context — where a GraphQL API uses `{"resolverContext": {...}}`. AWS returns
`Lambda Authorization` for both.
The Lambda entry of `IDENTITY_SCHEMAS` listed `resolverContext` alone, and a key
outside a schema rules that schema out rather than being ignored, so
`handlerContext` ruled out every mode and `util.authType()` fell through to its
default, `API Key Authorization`. Add `handlerContext` to the schema's keys.
This puts the fork back in step with the Python twin used by the VTL runtime
(`services/appsync/auth_type.py::IDENTITY_SCHEMAS`), which already lists both
keys and whose docstring requires the two to agree.
The new cases are local assertions rather than AWS-compared snapshots:
`EvaluateCode` validates its mock context against the GraphQL identity keys and
rejects one carrying `handlerContext` before the resolver runs, so the shape is
unreachable under `TEST_TARGET=AWS_CLOUD`. Their expected values come from
responses recorded from a real Lambda-authorized Event API; the comment on the
block says so. The 15 AWS-compared snapshots in the file were re-checked against
live AWS and are unchanged.
Releases this as v0.1.8.
Relates to AWS-1869.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
bentsku
deleted the
aws-1869-appsync-utils-utilauthtype-must-recognise-the-event-api
branch
September 21, 2026 19:57
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
util.authType()answersAPI Key Authorizationfor a request authorized by a Lambda authorizer on an Event API, where AWS answersLambda Authorization.An Event API populates
ctx.identitywith{"handlerContext": {...}}— an empty object when the authorizer returned no context — where a GraphQL API uses{"resolverContext": {...}}. Both are the authorizer's output under a different name, and AWS reports the same mode for both.The Lambda entry of
IDENTITY_SCHEMASlistedresolverContextalone. A key outside a schema rules that schema out rather than being ignored, sohandlerContextruled out every mode and the lookup fell through to its default.What this does
Adds
handlerContextto the Lambda schema's keys.requiredstays empty, so an identity carrying no keys at all remains a Lambda identity.Lambda AuthorizationresolverContext,handlerContextThe other three schemas are untouched: none of them can now match an identity they did not match before, since the only newly accepted key is one they all reject.
Tests
The two new cases are local assertions rather than
checkResolverValidsnapshots, and the comment on the block says why:EvaluateCodevalidates its mock context against the GraphQL identity keys and rejects one carryinghandlerContextbefore the resolver ever runs —Probed directly:
{handlerContext: {...}},{handlerContext: {}},{resolverContext, handlerContext}and an invented key all fail that way, while{resolverContext: {...}}evaluates and answersLambda Authorization. So this shape is unreachable underTEST_TARGET=AWS_CLOUDand cannot be recorded here. The expected values were read off the responses of a real Lambda-authorized Event API on AWS instead.For the same reason there is no case for the
{resolverContext, handlerContext}mixture that the widened schema now accepts: no API emits it andEvaluateCodewill not answer for it, so a test would pin invented behaviour.Verification
API Key Authorizationwhen theindex.jschange is stashed, and pass with it.authType.test.jswere re-run against live AWS (TEST_TARGET=AWS_CLOUD, no-u): all pass and the snapshot file is unchanged.Released as v0.1.8.
🤖 Generated with Claude Code