首页 文章

将AWS Lambda与Cognito和API Gateway配合使用

提问于
浏览
0

如何让用户使用Lambda函数?用户在Cognito中进行身份验证,并使用API网关调用lambda . API网关方法具有AWS_IAM授权程序并选中“使用Lambda代理集成”复选框

1 回答

  • 1

    如果您已检查AWS_IAM API Gateway,则为您的函数提供最终用户的标识 . 您可以按如下方式访问身份标识 .

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

相关问题