Skip to content

fix(parser): keep Lambda authorizer context in APIGatewayProxyEventModel - #8813

Merged
leandrodamascena merged 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-apigw-authorizer-context
Nov 15, 2026
Merged

leandrodamascena merged 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-apigw-authorizer-context

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Issue number:
closes #8801

Summary

Changes

  • APIGatewayEventAuthorizer now declares principalId and integrationLatency and allows extra keys, so the custom keys a Lambda authorizer returns in its context map are kept. They can be read as attributes or from model_extra.
  • A new test parses an event with the authorizer block from tests/events/apiGatewayProxyEventPrincipalId.json.

The APIGatewayProxyEvent data class already exposes these through principal_id, integration_latency and get_context(), and the TypeScript schema keeps them since aws-powertools/powertools-lambda-typescript#5749.

User experience

Today, requestContext.authorizer on a REST API event behind a Lambda authorizer parses to claims=None scopes=None, and the principal ID and context are lost. With this change the snippet in the issue prints principalId='user-123' integrationLatency=42 tenantId='t-9'. Events from Cognito authorizers parse the same as before, since this only adds fields.

Since the model allows extra keys now, model_dump() on the event also includes the authorizer's context keys.

Verification

  • The new test fails on develop ('APIGatewayEventAuthorizer' object has no attribute 'principalId') and passes with this change.
  • tests/unit/parser, tests/functional/parser and tests/functional/event_handler: 1531 passed, 1 skipped (Python 3.12).
  • ruff check, ruff format --check and mypy are clean.
  • An authorizer with only claims and scopes, like a Cognito one, still parses with no extra keys.
  • I didn't run this against a live API Gateway with a Lambda authorizer. The shape comes from the Lambda authorizer output docs and the repo's apiGatewayProxyEventPrincipalId.json event.

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

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.17%. Comparing base (d07a9c2) to head (b05ace6).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8813   +/-   ##
========================================
  Coverage    97.17%   97.17%           
========================================
  Files          323      323           
  Lines        16606    16609    +3     
  Branches      1504     1504           
========================================
+ Hits         16137    16140    +3     
  Misses         328      328           
  Partials       141      141           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena leandrodamascena added bug Something isn't working parser Parser (Pydantic) utility labels Nov 15, 2026
@leandrodamascena leandrodamascena added this to the 3.41.0 milestone Nov 15, 2026

@leandrodamascena leandrodamascena left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Manishram-ai! Small and right: extra="allow" is exactly what this model needed, since the authorizer's context keys are the user's own. The data class had been exposing them for a while, good to have the model catch up. Goes out in 3.41.0, no need to rebase, you'll be in the release notes.

@leandrodamascena
leandrodamascena merged commit c887a23 into aws-powertools:develop Nov 15, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser Parser (Pydantic) utility size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: APIGatewayProxyEventModel drops the Lambda authorizer context

2 participants