Customize tokens with a Cognito pre-token-generation Lambda trigger

domain: docs.aws.amazon.com/cognito · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. In the Cognito User Pool console under User pool properties > Lambda triggers, attach your Lambda function to the Pre token generation trigger.
  2. Your Lambda handler receives an event object; read event.request.userAttributes and event.request.groupConfiguration to access user data available at token time.
  3. Modify event.response.claimsOverrideDetails to add, suppress, or override claims; use claimsToAddOrOverride for additions and claimsToSuppress for removals.
  4. Return the modified event object from your handler; Cognito uses the response to shape the final token claims.
  5. Test end-to-end by authenticating a user and decoding the resulting ID or access token to confirm custom claims appear as expected.
  6. Monitor Lambda execution duration closely — Cognito enforces a hard 5-second timeout on all Lambda triggers and this limit is not configurable.

Known gotchas

Related routes

Migrate users into Cognito lazily with the user migration Lambda trigger
docs.aws.amazon.com/cognito · 6 steps · unrated
Trigger a CircleCI pipeline with custom parameters via v2 API
circleci.com/docs · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans