Skip to content

Conversation

admirkadriu
Copy link

Fixes serverless/serverless#12336

Summary

Adds support for Lambda versions V2_0 and V3_0 for PreTokenGeneration triggers in Cognito User Pools, enabling enhanced token customization beyond the current V1_0 limitation.

Changes

  • Updated validLambdaVersions to include V2_0 and V3_0 for PreTokenGeneration
  • Added trigger-specific validation (CustomSenders: V1_0 only, PreTokenGeneration: V1_0/V2_0/V3_0)
  • Enhanced template generation to use PreTokenGenerationConfig when Lambda versions are specified
  • Updated custom resources to handle PreTokenGenerationConfig for existing pools
  • Added documentation with usage examples

Usage

functions:
  preTokenV2:
    handler: handler.preToken
    events:
      - cognitoUserPool:
          pool: MyPool
          trigger: PreTokenGeneration
          lambdaVersion: V2_0  # ID + Access token customization

  preTokenV3:
    handler: handler.preToken
    events:
      - cognitoUserPool:
          pool: MyPool
          trigger: PreTokenGeneration
          lambdaVersion: V3_0  # Includes M2M client-credentials

AWS Compliance

  • Uses PreTokenGenerationConfig for versioned triggers (AWS best practice)
  • Maintains backward compatibility for existing V1_0 behavior
  • Requires Cognito User Pool on Essentials or Plus feature plan for V2_0/V3_0

@mkucharek
Copy link

hi @mnapoli, can you take a look at it when you have a moment? We're using osls and basically ended up needing v2.0 PreTokenGeneration lambda version support. We can keep using the fork for the time being, but we'd love to contribute even just this tiny bit.

Thanks a lot in advance, you guys are doing awesome job!

@mnapoli
Copy link
Contributor

mnapoli commented Oct 5, 2025

Could you add tests to cover the new features please?

@admirkadriu
Copy link
Author

Could you add tests to cover the new features please?

@mnapoli done

@mnapoli
Copy link
Contributor

mnapoli commented Oct 6, 2025

Thanks!

@mnapoli mnapoli merged commit 2452335 into oss-serverless:main Oct 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

V2 Pre-Token Generation Lamba / Cognito Support
4 participants