最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

AWS Lambda

IT培训 admin 3浏览 0评论

AWS Lambda

从我的Web客户端,我直接通过以下方式调用我的AWS Lambda函数:

// Build the logins object for the credentials
var loginKey = "cognito-idp." + config.awsRegion + ".amazonaws/" + 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网关中,在Integration Request下,你必须设置你的身体映射模板,如果你使用application / json的“默认”模板,这会将数据传递给你的应用程序。

您将看到它创建的“上下文”对象。然后在你的lambda应用程序中:

节点代码:

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

希望这可以帮助!

AWS Lambda

从我的Web客户端,我直接通过以下方式调用我的AWS Lambda函数:

// Build the logins object for the credentials
var loginKey = "cognito-idp." + config.awsRegion + ".amazonaws/" + 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网关中,在Integration Request下,你必须设置你的身体映射模板,如果你使用application / json的“默认”模板,这会将数据传递给你的应用程序。

您将看到它创建的“上下文”对象。然后在你的lambda应用程序中:

节点代码:

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

希望这可以帮助!

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论