【问题标题】:AWS - Lambda Authorizer returns error 500AWS - Lambda 授权方返回错误 500
【发布时间】:2019-12-06 16:47:56
【问题描述】:

我已经设置了一个 AWS API Gateway Web Socket API。

我的设置概述:客户端 --(升级请求)--> AWS API Gateway ----> Lambda 授权者

我的$connect路线:

请注意:

  • 目前还没有Integration ResponseRoute Response。有问题吗?
  • connect-authorizer 是我的 Lambda 授权者的名称

connect-authorizer确实收到了客户端的请求,但是没有给客户端授权!

下面是connect-authorizer的代码(参考hereRequest-based函数):

exports.handler = function(event, context, callback) {
    console.log("Received event", JSON.stringify(event, null, 2));

    callback(null, generateAllow("me", event.methodArn)); // just authorize!

    //callback("Unauthorized"); // if replaced by this line, my Terminal does receive error 401 !
};

const generatePolicy = function(principalId, effect, resource) {
    console.log("generating policy", principalId, effect, resource)

    const authResponse = {};
    authResponse.principalId = principalId;
    authResponse.context = {
        "stringKey": "stringval",
        "numberKey": 123,
        "booleanKey": true
    };

    if (effect && resource) {
        const statementOne = {};
        statementOne.Action = "execute-api:Invoke";
        statementOne.Effect = effect;
        statementOne.Resource = resource;

        const policyDocument = {};
        policyDocument.Version = "2012-10-17";
        policyDocument.Statement = [statementOne];

        authResponse.policyDocument = policyDocument;
    }

    console.log("final authResponse", authResponse)

    return authResponse;
};

const generateAllow = function(principalId, resource) {
    return generatePolicy(principalId, "Allow", resource);
};

const generateDeny = function(principalId, resource) {
    return generatePolicy(principalId, "Deny", resource);
};

但我总是从终端 wscat 收到错误 500:

登录CloudWatch:

Statement: [ [Object] ] 有问题吗?为什么我总是收到错误 500?

【问题讨论】:

    标签: amazon-web-services websocket aws-lambda aws-api-gateway http-error


    【解决方案1】:

    您是否尝试过添加集成响应?我相信$connect 路由应该返回一个将statusCode 属性设置为200 的对象。

    我记得在我设置困难时,this answer 帮助了我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-12
      • 2017-11-12
      • 1970-01-01
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      • 2021-12-02
      相关资源
      最近更新 更多