Skip to content

feat(parser): Added Cognito trigger schemas #6737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

VatsalGoel3
Copy link
Contributor

@VatsalGoel3 VatsalGoel3 commented May 29, 2025

Issue number: #6203

Summary

Changes

This PR adds full support for all Amazon Cognito User Pool Lambda Triggers as part of the Parser (Pydantic) utility. These include schemas for:

  1. PreSignUp
  2. PostConfirmation
  3. PreAuthentication
  4. PostAuthentication
  5. PreTokenGeneration
  6. MigrateUser
  7. CustomMessage
  8. CustomEmailSender
  9. CustomSMSSender
  10. DefineAuthChallenge
  11. CreateAuthChallenge
  12. VerifyAuthChallenge

Each schema includes:

  • Strict Pydantic models with field aliases
  • Unit tests based on sample event payloads
  • Event fixture JSON files
  • Centralized export in __init__.py

User experience

Before:

  • Developers had to manually validate and parse Cognito Lambda events.
  • No native schema validation via @parser for Cognito triggers.

After:

  • Full schema validation for all supported Cognito Lambda events.
  • Type-safe access to event fields via @parser(model=CognitoXxxEventModel).

Checklist

Is this a breaking change?

RFC issue number: N/A

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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


⚠️ Current blocker

Some schemas are currently failing validation in tests due to discrepancies in the sample fixture files:

  • email_verified, phone_number_verified appear as bool in test events but the schema expects str
  • Some optional nested fields are missing or provided as empty objects in test files
  • Aliases like awsSdk vs awsSdkVersion cause mismatches

Would you prefer:

  1. Loosening the validators and accepting bool | str, with appropriate aliases?
  2. Or should we update the JSON test fixtures to match stricter validation?

@VatsalGoel3 VatsalGoel3 requested a review from a team as a code owner May 29, 2025 06:48
@VatsalGoel3 VatsalGoel3 requested a review from anafalcao May 29, 2025 06:48
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels May 29, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 29, 2025
@github-actions github-actions bot added feature New feature or functionality and removed documentation Improvements or additions to documentation labels May 29, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jun 2, 2025
@leandrodamascena leandrodamascena linked an issue Jun 2, 2025 that may be closed by this pull request
2 tasks
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Hey @VatsalGoel3 can you pls run make format and push a commit again? Ruff is complaining about some files.

@boring-cyborg boring-cyborg bot added the github-actions Pull requests that update Github_actions code label Jul 9, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 9, 2025
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.25%. Comparing base (0560746) to head (281a55a).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6737      +/-   ##
===========================================
+ Coverage    96.20%   96.25%   +0.04%     
===========================================
  Files          273      274       +1     
  Lines        12713    12856     +143     
  Branches       950      950              
===========================================
+ Hits         12231    12374     +143     
  Misses         377      377              
  Partials       105      105              

☔ View full report in Codecov by Sentry.
📢 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.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jul 9, 2025
Copy link

sonarqubecloud bot commented Jul 9, 2025

@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jul 9, 2025
@leandrodamascena leandrodamascena requested review from dreamorosi and removed request for dreamorosi July 9, 2025 17:43
Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

Hey @VatsalGoel3 thanks a lot for working in this PR! I had to make some changes to align with the TypeScript implementation: https://github.com/aws-powertools/powertools-lambda-typescript/blob/main/packages/parser/src/schemas/cognito.ts

@dreamorosi can you pls review this?

@leandrodamascena leandrodamascena requested review from dreamorosi and removed request for anafalcao July 9, 2025 17:48
@leandrodamascena leandrodamascena merged commit 0868993 into aws-powertools:develop Jul 9, 2025
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality github-actions Pull requests that update Github_actions code 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.

Feature request: Add Cognito trigger models in parser utility
3 participants