【发布时间】:2018-02-16 21:43:26
【问题描述】:
如何在 Lambda 函数中获取用户?用户在 Cognito 中经过身份验证,并使用 API Gateway 调用 lambda。 API Gateway 方法具有 AWS_IAM 授权者并选中“使用 Lambda 代理集成”复选框
【问题讨论】:
标签: amazon-web-services aws-lambda aws-cognito
如何在 Lambda 函数中获取用户?用户在 Cognito 中经过身份验证,并使用 API Gateway 调用 lambda。 API Gateway 方法具有 AWS_IAM 授权者并选中“使用 Lambda 代理集成”复选框
【问题讨论】:
标签: amazon-web-services aws-lambda aws-cognito
如果您已检查 AWS_IAM API Gateway,您的函数可用的最终用户身份。您可以按如下方式访问身份 ID。
exports.handler = function(event, context) {
var identity = event.requestContext.identity.cognitoIdentityId;
console.log("clientID = " + identity);
context.succeed("Your client ID is " + identity);
}
然后使用AWS SDK for Cognito 调用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
});
【讨论】: