【问题标题】:Using AWS Lambda with Cognito and API Gateway将 AWS Lambda 与 Cognito 和 API Gateway 结合使用
【发布时间】:2018-02-16 21:43:26
【问题描述】:

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

【问题讨论】:

    标签: amazon-web-services aws-lambda aws-cognito


    【解决方案1】:

    如果您已检查 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
    });
    

    【讨论】:

    • 没有 context.identity 属性。我使用npmjs.com/package/aws-api-gateway-client 调用 API 上下文对象具有属性:callbackWaitsForEmptyEventLoop、logGroupName、logStreamName、functionName、memoryLimitInMB、functionVersion、invokeid、awsRequestId、invokedFunctionArn
    • 但事件对象中有 event.requestContext.identity.cognitoIdentityId。谢谢
    • 我检查了移动 SDK 调用。但是谢谢会相应地更新答案。
    • 你知道如何获取用户属性吗?我在 describeIdentity 中获得了 Logins 数组。用户在用户池中,他们有属性
    • 您是否尝试调用 describeIdentity-property 方法?在 NodeSDK for Cognito 中
    猜你喜欢
    • 2021-05-17
    • 2019-04-28
    • 2016-08-11
    • 2017-12-30
    • 2018-12-16
    • 2021-04-24
    • 2020-06-12
    • 2018-12-25
    • 2017-05-29
    相关资源
    最近更新 更多