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

オープン
#8,718 コメント 3 件 リアクション 0 件 担当者 1 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Goldloli がすでに取り組んでいます。

2026年10月31日 から。

  • #8719 @ibrhmyi による — マージされずにクローズ
  • #8720 @Goldloli による — オープン

評価

この issue はまだ評価されていません。

説明

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

主要言語
Python
スター
3.3k
フォーク
511
平均マージ
3日 8時間
マージ済み PR(30日)
92

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws-powertools/powertools-lambda-python のほかの issue

aws-powertools/powertools-lambda-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。