【发布时间】:2019-02-16 23:06:59
【问题描述】:
从我的网络客户端,我直接通过以下方式调用我的 AWS Lambda 函数:
// 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
});
});
在我的 Lambda 函数中,我验证了 context.identity.cognitoIdentityId 和 context.identity.cognitoIdentityPoolId 的值,如文档 here 中所述。以下是一个非常简化的 Lambda 函数,可以准确显示我所询问的属性:
exports.handler = (event, context, callback) => {
console.log(context.identity.cognitoIdentityId); // Has value
console.log(context.identity.cognitoIdentityPoolId); // Has value
callback(null, "success");
};
我认为有了这些信息,我可以获得 Cognito 用户数据,包括利用这些信息的属性,但我还没有找到方法。 This 最近的 SO 线程是我见过的最接近的,但即使他们想出了一个“变通”类型的解决方案。
有人知道使用 Lambda 函数 context.identity 数据获取 Cognito 用户数据的方法吗?谢谢!
【问题讨论】:
标签: node.js amazon-web-services aws-lambda