1 Answer
- Newest
- Most votes
- Most comments
0
Short answer: This behavior is expected. Amazon Cognito does not guarantee single invocation of the Pre-SignUp Lambda trigger, especially when used with Amplify.
Why this happens A single logical sign-up from an Amplify client can result in multiple backend attempts, causing Pre-SignUp to be invoked more than once. Common causes include:
- Internal retries due to transient errors, timeouts, or downstream failures
- Amplify client re-attempts when promises, redirects, or errors are not fully handled
- Federated or multi-step auth flows, which may invoke Cognito multiple times before completion
- Temporary usernames created during failed attempts that are later cleaned up automatically
- Pre-SignUp does not provide exactly-once execution semantics and should not be treated as a final or authoritative lifecycle event.
Recommended approach
- Design Pre-SignUp to be idempotent
- Avoid irreversible side effects (DB writes, external calls, emails)
- Use stable identifiers (email, sub), not the generated username
- Move business logic to Post-Confirmation whenever possible
- Verify Amplify configuration to avoid unintended client retries
Example (idempotent guard) if (event.request.userAttributes.email_verified) { return event; // already processed }
Conclusion This is an architectural characteristic of Cognito + Amplify, not a bug. Handling Pre-SignUp defensively and idempotently is the recommended best practice.
answered a month ago
Relevant content
- asked 3 years ago
