I have created a PreSignup
Lambda function to be used with Cognito Pre-SignUp trigger with the following code:
import { APIGatewayEventDefaultAuthorizerContext, APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
export async function PreSignup(event: any, context: APIGatewayEventDefaultAuthorizerContext,) {
console.log("...event:", event);
console.log("...context:", context);
let userName = event.userName;
let email = event.request.userAttributes.email;
console.log("...userName:", userName);
console.log("...email:", email);
// Confirming the event so Cogntio doesnt resend it again:
event.response.autoConfirmUser = true;
event.response.autoVerifyPhone = true;
event.response.autoVerifyEmail = true;
return event;
}
Instead of setting up the event
to any
with function PreSignup(event: any)
I would rather specify a type of the event.
I tried to specify it as APIGatewayProxyEvent
like so:
function PreSignup(event: APIGatewayProxyEvent, context: APIGatewayEventDefaultAuthorizerContext,) {...}
but it doesn't work as the event
sent by Cognito Pre Sign-Up trigger is not a APIGatewayProxyEvent
type. What kind of event is it?
Edited later:
Below is copy/pasted event that was pushed by Cognito PreSignUp Trigger:
{
version: '1',
region: 'us-east-1',
userPoolId: 'us-east-1_abcdef',
userName: '[email protected]',
callerContext: {
awsSdkVersion: 'aws-sdk-nodejs-2.799.0',
clientId: 'CLIENT_ID_NOT_APPLICABLE'
},
triggerSource: 'PreSignUp_AdminCreateUser',
request: {
userAttributes: { email: '[email protected]' },
validationData: null
},
response: {
autoConfirmUser: false,
autoVerifyEmail: false,
autoVerifyPhone: false
}
}
Below is an example of another AWS event this time pushed by AWS EventBridge
(similar to the one pushed by Cognito Trigger):
{
version: '0',
id: '0ee136cb-ea53-f9e0-a6a9-232dfb78b7d0',
'detail-type': 'UserCreated',
source: 'my.company.endpointname',
account: '123456789012',
time: '2021-01-29T03:05:54Z',
region: 'us-east-1',
resources: [],
detail: { foo: 'bar', createdAt: 1611889553709 }
}