Using AWS Lambda with Cognito and API Gateway

我们两清 提交于 2020-01-07 04:29:09

问题


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
});


来源:https://stackoverflow.com/questions/46108431/using-aws-lambda-with-cognito-and-api-gateway

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!