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

Đang mở
#8,718 3 bình luận 0 reaction 1 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Goldloli đang làm issue này rồi.

Từ ngày 31/10/2026.

  • #8719 của @ibrhmyi — đã đóng, không merge
  • #8720 của @Goldloli — đang mở

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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

Ngôn ngữ chính
Python
Star
3.3k
Fork
511
Merge trung bình
3 ngày 8 giờ
Pull request đã merge (30 ngày)
92

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws-powertools/powertools-lambda-python

Tất cả issue của aws-powertools/powertools-lambda-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.