Skip to content

UserPoolTriggerEventSource

Source: src/AWS/Cognito/UserPoolTriggerEventSource.ts

Event source connecting a Cognito UserPool Lambda trigger to the hosting Lambda function.

At deploy time the Lambda implementation (Lambda.UserPoolTriggerEventSource) injects the function ARN into the pool’s LambdaConfig (via the pool’s binding contract) and creates the lambda:InvokeFunction Permission for cognito-idp.amazonaws.com; at runtime it dispatches matching trigger events to the handler and returns the handler’s (mutated) event to Cognito.

Use the onUserPoolTrigger helper (or the per-slot shorthands onPreSignUp, onPostConfirmation, onPreTokenGeneration, onCustomMessage) rather than the service directly, and provide Lambda.UserPoolTriggerEventSource on the hosting function.

export default AuthFunction.make(
{ main: import.meta.url },
Effect.gen(function* () {
const pool = yield* Cognito.UserPool("Users", {});
// deploy: wires PreSignUp in the pool's LambdaConfig + invoke Permission
// runtime: dispatches PreSignUp_* events to this handler
yield* Cognito.onPreSignUp(pool, (event) =>
Effect.sync(() => Cognito.autoConfirmUser(event, { verifyEmail: true })),
);
return {};
}).pipe(Effect.provide(Lambda.UserPoolTriggerEventSource)),
);