How it works without Apex
Attach two lightweight Node.js 18+ Lambda triggers to your Amazon Cognito User Pool: PostConfirmation sends user_signed_up with eventId keyed by the user's immutable Cognito sub, and PostAuthentication sends user_identified so existing pre-Apex users reconcile automatically on their next login. Both handlers await fetch with a 1.5-second timeout and catch all errors so Cognito's hard 5-second trigger limit never fails a sign-in.
How Apex does it for you
Apex maps Cognito's sub to internal_user_id, deduplicates repeated PostConfirmation retries via eventId, reconciles dormant users passively as they sign back in, and isolates staging user pools via x-apex-environment.
How to set this up in 5 steps
Create a workspace server key and set Lambda env vars
Generate an apex_sk_ key under Settings, then API keys in Apex. Store it as APEX_API_KEY on both Lambda functions, and set APEX_ENVIRONMENT to beta or dev on non-production user pools.
Deploy the PostConfirmation Lambda for new sign-ups
Read sub, email, name, and picture from event.request.userAttributes and POST user_signed_up with eventId set to signup- plus sub, awaiting fetch with AbortSignal.timeout(1500) and a catch fallback.
Deploy the PostAuthentication Lambda for passive backfill
On every sign-in, POST user_identified with email and userId set to sub using the same 1.5-second timeout and silent catch so pre-Apex users reconcile automatically on their next login.
Keep await on fetch and return event cleanly
Always await the fetch before returning event because Lambda freezes execution the moment the handler resolves, which would drop an unawaited request.
Attach both triggers in your Cognito User Pool
Under User pool properties, Lambda triggers, attach Post confirmation and Post authentication, then confirm a test account and verify the profile appears under Customers.
Two triggers and why both matter
Amazon Cognito assigns every user an immutable UUID called sub. Even if a customer later updates their email address or signs in through a federated provider, sub never changes, making it the cleanest possible internal_user_id for Apex.
Instead of trying to capture identity inside fragile browser callbacks after Cognito Hosted UI redirects, wire two small Node.js 18+ Lambda triggers documented in Connect Cognito:
- PostConfirmation fires when a brand-new user confirms their account and records
user_signed_upwitheventId: "signup-" + sub. - PostAuthentication fires on every subsequent sign-in and sends
user_identifiedso every existing customer created before you installed Apex reconciles automatically the next time they log in.

PostConfirmation and PostAuthentication code
Both functions use Node.js 18+ built-in fetch and AbortSignal.timeout with zero third-party npm packages to bundle:
// cognito-post-confirmation.js
export const handler = async (event) => {
const { sub, email, name, picture } = event.request.userAttributes;
await fetch("https://app.apex.inc/api/v1/events", {
method: "POST",
signal: AbortSignal.timeout(1500),
headers: {
"content-type": "application/json",
"x-api-key": process.env.APEX_API_KEY,
"x-apex-environment": process.env.APEX_ENVIRONMENT ?? "production",
},
body: JSON.stringify({
events: [
{
type: "user_signed_up",
eventId: `signup-${sub}`,
email,
data: { userId: sub, name, avatar_url: picture },
},
],
}),
}).catch(() => {});
return event;
};For returning logins, attach a second trigger to Post authentication sending type: "user_identified" with email and data: { userId: sub } using the exact same timeout and error handler.

Protecting Cognito's 5-second limit
Cognito enforces a hard 5-second deadline on synchronous Lambda triggers, and any unhandled exception fails the user's sign-up or sign-in outright. Four habits make this integration bulletproof in production:
| Rule | What happens if you skip it |
|---|---|
| Cap fetch at 1,500 ms | A slow upstream socket can push Lambda past Cognito's 5-second wall and reject the login |
| Keep `await` on `fetch` | Returning event early lets Lambda freeze the container before the HTTP request leaves |
| Swallow errors with `.catch(() => {})` | A transient network failure turns into a broken login screen instead of a harmless skipped ping |
| Pass `APEX_ENVIRONMENT` on non-prod pools | QA sign-ups from staging user pools leak into production customer lists and ad conversions |
Note on regional consent: Cognito does not pass visitor country or tracking consent automatically. If you store either as custom attributes (such ascustom:countryorcustom:consent), pass them on the event payload. Otherwise, see Server Events consent rules for how missing-country sign-ups are handled. If you also need dormant users imported immediately, follow Backfill existing users.
What this costs on Apex
Live Apex pricing · Pay-as-you-go
Estimated Apex cost for SaaS product on Amazon Cognito with 3,000 monthly sign-ups and 22,000 sign-ins
$0 / month
Covered by monthly free allowances.
| Apex meter / schedule | Scenario volume | Free allowance / basis | Rate | Apex cost |
|---|---|---|---|---|
Events Cognito PostConfirmation and PostAuthentication server events (3,000 confirmed sign-ups plus 22,000 returning authentications per month) | 25,000 / mo | 1M / month | $5 per 100K events | $0 |
Every Cognito user reconciles cleanly against your existing marketing snippet visits and Stripe invoices. History: 13 months no card, 3 years with card, 7 years once you've paid an invoice. Live pricing.
Third-party and campaign costs (not paid to Apex)
| Expense | Typical range | Notes |
|---|---|---|
| AWS Lambda trigger invocations | Under $1/month | 25,000 short Node.js invocations fit inside the standard AWS Lambda free tier |
Your Cognito User Pool triggers invoke tiny Node.js handlers that stay near zero on AWS billing, and Apex meters only the delivered server events under standard Web Measurement.
