How to get user in Lambda function? User is authenticated in Cognito and invokes lambda with API Gateway. API Gateway method has AWS_IAM authorizer and checked "Use Lambda Proxy integration" checkbox
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
If you have checked AWS_IAM API Gateway, identity of the end user available to your function. You can access the Identity ID as follows.
exports.handler = function(event, context) {
var identity = event.requestContext.identity.cognitoIdentityId;
console.log("clientID = " + identity);
context.succeed("Your client ID is " + identity);
}
Then using the AWS SDK for Cognito invoking describeIdentity-property
method, you should be able to retrieve additional information available for the identity.
var params = {
IdentityId: 'STRING_VALUE' /* required */
};
cognitoidentity.describeIdentity(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});