Skip to content

fix(data_classes): add AppSyncIdentityLambda for AWS_LAMBDA AppSync authorization - #8719

Closed
ibrhmyi wants to merge 5 commits into
aws-powertools:developfrom
ibrhmyi:contributor/issue-8718-5642484bdb
Closed

ibrhmyi wants to merge 5 commits into
aws-powertools:developfrom
ibrhmyi:contributor/issue-8718-5642484bdb

Conversation

@ibrhmyi

@ibrhmyi ibrhmyi commented Oct 31, 2026 •

Copy link
Copy Markdown

Closes #8718

With AppSync AWS_LAMBDA authorization, the resolver event identity is whatever the Lambda authorizer returned in resolverContext (e.g. {"resolverContext": {"userId": "u-1", "tier": "gold"}}). Previously get_identity_object only checked for sub (Cognito) and fell back to AppSyncIdentityIAM for everything else, so a Lambda-authorizer identity was wrapped in AppSyncIdentityIAM and every property on it (account_id, user_arn, ...) raised KeyError; resolverContext was only reachable as a raw dict.

Change

  • Added AppSyncIdentityLambda(DictWrapper) with a resolver_context property returning the dict the authorizer produced
  • get_identity_object now dispatches on "resolverContext" in identity before the IAM fallback; the sub (Cognito/OIDC) dispatch and the IAM fallback are unchanged
  • Updated the identity property return type and docstring (the AWS_LAMBDA line previously said "returns None - NEED TO TEST")
  • One line in docs/utilities/data_classes.md documenting which identity class each AppSync authorization type returns

Tests

  • New fixture tests/events/appSyncResolverEventLambdaAuth.json (existing fixtures untouched, per repo guidance)
  • Four new test cases through AppSyncResolverEvent(event).identity / get_identity_object: class exposes resolver_context, resolverContext identity dispatches to AppSyncIdentityLambda (not AppSyncIdentityIAM), IAM fallback regression without resolverContext, and nested-dict passthrough of resolver_context
  • Event shape validated against the AWS AppSync Lambda authorizer identity payload shape documented in the issue (resolverContext only, no sub or IAM fields) — no AWS resources needed
  • RED on unmodified code: 3 of 4 new tests failed (ImportError/AppSyncIdentityIAM misclassification); GREEN after fix: 10/10 in the file, 200/200 in tests/unit/data_classes/required_dependencies/; ruff check and ruff format --check clean on the changed files

Related: #8705 deliberately leaves AWS_LAMBDA marked unverified ("no fixture for it") while fixing the OIDC docstring — this PR completes the AWS_LAMBDA piece it deferred. The docstring edits are on adjacent lines, so a trivial rebase may be needed if #8705 merges first.

AI assistance was used for this contribution (implementation and review).

AI assistance was used for implementation and review; all reported verification is recorded above.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ibrhmyi
ibrhmyi requested a review from a team as a code owner October 31, 2026 18:36
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 31, 2026
@boring-cyborg boring-cyborg Bot added documentation Improvements or additions to documentation tests labels Oct 31, 2026
@boring-cyborg

boring-cyborg Bot commented Oct 31, 2026

Copy link
Copy Markdown

Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@sonarqubecloud

Copy link
Copy Markdown

@leandrodamascena

Copy link
Copy Markdown
Contributor

Thanks @ibrhmyi, the code is fine, but @Goldloli asked for this issue a minute before you opened the PR, and we go with whoever claimed it first so people don't duplicate work. I'm closing this one. There are other good first issue items open, and the rule is simple: comment on the issue first, wait for the assignment, then open the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: AppSync identity from a Lambda authorizer (AWS_LAMBDA) is wrapped in AppSyncIdentityIAM

2 participants