AWS-Lambda Authorizer返回错误500

时间:2019-09-26 20:23:04

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

我已经设置了一个AWS API Gateway Web套接字API。

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

我的$connect路线:

enter image description here

请注意:

  • 它目前还没有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:

Error 500 from wscat

登录CloudWatch

enter image description here

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

1 个答案:

答案 0 :(得分:0)

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

我记得this answer在设置过程中遇到困难时为我提供了帮助。