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

未關閉
#8,718 3 則留言 0 個 reaction 已指派 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 小時
30 天內合併 PR
92

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aws-powertools/powertools-lambda-python 的其他 Issue

查看 aws-powertools/powertools-lambda-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。