From my web client I call my AWS Lambda functions directly via:
// Build the logins object for the credentials
var loginKey = "cognito-idp." + config.awsRegion + ".amazonaws.com/" + config.identity.UserPoolId;
var logins = {};
logins[loginKey] = jwtToken;
// Instantiate the credentials.
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: config.identity.IdentityPoolId,
Logins: logins
});
// Must refresh the credentials prior to calling the function.
AWS.config.credentials.refresh(function(err) {
... // Error handling excluded
var lambda = new AWS.Lambda({region: config.awsRegion, apiVersion: '2015-03-31'});
var params = {
FunctionName: functionName,
InvocationType : 'RequestResponse',
LogType : 'None',
Payload: JSON.stringify(data)
};
lambda.invoke(params, function(err, data){
... // Data handling
});
});
In my Lambda functions I verify there are values for context.identity.cognitoIdentityId and context.identity.cognitoIdentityPoolId as described in the documentation here. The following is a very simplified Lambda function to show exactly the properties I am asking about:
exports.handler = (event, context, callback) => {
console.log(context.identity.cognitoIdentityId); // Has value
console.log(context.identity.cognitoIdentityPoolId); // Has value
callback(null, "success");
};
I figured with this information I could get the Cognito User data, including attributes utilizing this information but I am yet to find a way. This recent SO thread was the closest I have seen, but even they came up with a "work around" type solution.
Does anyone know a way to get the Cognito User data utilizing the Lambda function context.identity data? Thanks!