Hi everyone,
A quick post on where to find the user id (sub) in a lambda requested that has been authenticated with a congito authorizer.
You’ll be able to find everything you need in the event object under requestContext > authorizer > claims:
exports.viewContextHandler = async (event, context, callback) => {
console.log(JSON.stringify(event.requestContext));
}
"requestContext": {
"resourceId": "XXXXX",
"authorizer": {
"claims": {
"at_hash": "XXXXX",
"sub": "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX",
"aud": "XXXXX12341234512345XXXXX",
"email_verified": "true",
"token_use": "id",
"auth_time": "1547371205",
"iss": "https://cognito-XXXXX.com/XXXXX",
"cognito:username": "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX",
"exp": "Sun Jan 13 10:20:05 UTC 2019",
"iat": "Sun Jan 13 09:20:05 UTC 2019",
"email": "XXXXX@XXXXX.XXXXX"
}
},
}