- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在我的 Web 客户端中,我直接通过以下方式调用我的 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 用户数据吗?谢谢!
最佳答案
不确定您是否解决了这个问题,但是在您的 API 网关中,在集成请求下,您必须设置您的正文映射模板,如果您使用 application/json 的“默认”模板,这会将数据传递到您的应用程序。
您将看到它创建的“上下文”对象。然后在您的 lambda 应用程序中:
Node 代码:
exports.handler = (event, context, callback) => {
let what = event.context;
let who = what['cognito-authentication-provider']; // or match what the template setup
callback(null, "cognito provider: " + who);
};
希望这有帮助!
关于node.js - AWS Lambda - 如何使用 context.identity.cognitoIdentityId 获取相关的 Cognito 用户池用户数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49058553/
我目前有一个 API 网关设置来绑定(bind)使用 Java 编写的 Lambda 函数。我正在使用 javascript SDK 调用 API 网关端点,它们正确地中继到 Lambda 函数。但是
我正在尝试从我的 lambda 函数中获取 Cognito 用户名。我已启用我的 api 网关以使用“使用 Lambda 代理集成”。它现在返回身份对象,但 cognitoIdentityId 返回
在我的 Web 客户端中,我直接通过以下方式调用我的 AWS Lambda 函数: // Build the logins object for the credentials var loginKe
早些时候,当我们仅使用 Cognito 用户池启动项目时,我创建了许多解析器并通过 Cognito 用户池数据进行验证,例如: #if( $ctx.identity.claims["custom:ro
早些时候,当我们仅使用 Cognito 用户池启动项目时,我创建了许多解析器并通过 Cognito 用户池数据进行验证,例如: #if( $ctx.identity.claims["custom:ro
我是一名优秀的程序员,十分优秀!