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

Aperta
#8,718 3 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@Goldloli ci sta già lavorando.

Dal 31/10/2026.

  • #8719 di @ibrhmyi — chiusa senza merge
  • #8720 di @Goldloli — aperta

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

bug event_sources good first issue help wanted
Expected Behaviour

With AppSync AWS_LAMBDA authorization, the resolver event identity is what the authorizer returned in resolverContext, for example {"resolverContext": {"userId": "u-1", "tier": "gold"}}. AppSyncResolverEvent.identity should return a dedicated class exposing resolver_context, so the only field that exists in this mode is reachable through a typed property.

Current Behaviour

get_identity_object in aws_lambda_powertools/utilities/data_classes/appsync_resolver_event.py has two outcomes: an identity with sub becomes AppSyncIdentityCognito, anything else becomes AppSyncIdentityIAM. A Lambda-authorizer identity has neither sub nor IAM fields, so it lands on AppSyncIdentityIAM and every property on it (account_id, user_arn, source_ip, cognito_identity_*) raises KeyError. resolverContext is only reachable as a raw dict.

Code snippet
from aws_lambda_powertools.utilities.data_classes.appsync_resolver_event import get_identity_object

identity = get_identity_object({"resolverContext": {"userId": "u-1", "tier": "gold"}})
print(type(identity).__name__)  # AppSyncIdentityIAM
identity.account_id  # KeyError: 'accountId'
Possible Solution
  • Add AppSyncIdentityLambda(DictWrapper) with a resolver_context property returning the dict the authorizer produced (see the AppSync docs on Lambda authorization: the identity object carries resolverContext).
  • In get_identity_object, dispatch on "resolverContext" in identity before the IAM fallback, and update the return type of identity and the docstring line that #8705 left marked as unverified.
  • Add a fixture with a Lambda-authorizer identity under tests/events/, tests through AppSyncResolverEvent(event).identity, and a line in docs/utilities/data_classes.md.
  • Keep the existing dispatch for sub (Cognito and OIDC) and the IAM fallback unchanged.

This is a good first issue. Everything needed is in the file above plus the tests next to it; no AWS resources are required to reproduce.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

No response

Lingua principale
Python
Stelle
3.3k
Fork
511
Merge medio
3g 12h
PR unite (30g)
93

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di aws-powertools/powertools-lambda-python

Tutte le issue di aws-powertools/powertools-lambda-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.