Skip to content

fix(parser): accept real Cognito trigger events - #8762

Open
Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-cognito-trigger-events
Open

Manishram-ai wants to merge 1 commit into
aws-powertools:developfrom
Manishram-ai:fix/parser-cognito-trigger-events

Conversation

@Manishram-ai

Copy link
Copy Markdown
Contributor

Issue number:
closes #8761

Summary

Changes

  • CognitoChallengeResultModel.challengeName accepts CUSTOM_CHALLENGE, the first challenge type in the define auth challenge docs.
  • The pre sign-up, post confirmation, custom email sender and custom SMS sender models accept every triggerSource documented for their trigger. The lists come from the trigger sources reference and the custom email and custom SMS sender pages. The trigger sources reference spells the SMS sources CustomSmsSender_*, but the custom SMS sender page and the API table use CustomSMSSender_*, which matches the existing literal, so I kept that spelling.
  • answerCorrect in the verify auth challenge response and callerContext.clientId are optional, because Cognito sends null for both. The function sets answerCorrect, and admin API calls such as AdminConfirmSignUp have no client ID.
  • New tests cover each newly accepted trigger source, CUSTOM_CHALLENGE in the define and create auth challenge sessions, and the two null values. Each one starts from the existing fixture and changes one field.

This is the same fix as aws-powertools/powertools-lambda-typescript#5777. Python's session has no minimum length and its custom sender models don't require response, so those two parts of the TypeScript change weren't needed here.

User experience

Today a custom auth flow can't be parsed past its first custom challenge, verify auth challenge events fail on answerCorrect, and pre sign-up, post confirmation and custom sender events from admin, federated, forgot password and resend code flows fail with a ValidationError. With this change they parse, and handlers can branch on triggerSource and challengeName the way the Cognito docs describe.

Verification

  • The 20 new test cases fail on develop and pass with this change.
  • tests/unit/parser, tests/functional/parser and tests/unit/data_classes: 449 passed (Python 3.12).
  • ruff format --check and ruff check are clean on the changed files, and mypy shows no errors in cognito.py.
  • I didn't run these against a live user pool. The trigger sources and CUSTOM_CHALLENGE come from the Cognito docs, and the two null values come from the events captured from a live user pool in Bug: Cognito trigger schemas reject real events from common flows powertools-lambda-typescript#5770.

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.

The Cognito trigger models rejected events that Cognito sends in common
flows: CUSTOM_CHALLENGE in the auth challenge session, the other
documented trigger sources for pre sign-up, post confirmation and the
custom email and SMS senders, and a null answerCorrect or clientId.
This is the same fix as powertools-lambda-typescript#5777.
@Manishram-ai
Manishram-ai requested a review from a team as a code owner November 3, 2026 06:38
@boring-cyborg boring-cyborg Bot added the tests label Nov 3, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 3, 2026
@sonarqubecloud

sonarqubecloud Bot commented Nov 3, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Cognito parser models reject real trigger events

1 participant