结合使用AWS Lambda和Cognito和API网关 [英] Using AWS Lambda with Cognito and API Gateway

查看:97
本文介绍了结合使用AWS Lambda和Cognito和API网关的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Lambda函数中获取用户?用户已在Cognito中进行身份验证,并使用API​​ Gateway调用lambda。 API Gateway方法具有AWS_IAM授权者,并选中了使用Lambda代理集成复选框

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

推荐答案

如果您已选中AWS_IAM API Gateway,可以使用您的功能的最终用户。您可以按以下方式访问身份ID。

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

然后使用用于Cognito的AWS开发工具包调用 describeIdentity-property

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

这篇关于结合使用AWS Lambda和Cognito和API网关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆