AWS - Lambda Authorizer возвращает ошибку 500 - PullRequest
0 голосов
/ 26 сентября 2019

Я настроил AWS API Gateway Web Socket API.

Обзор моих настроек: Клиент - (запрос на обновление) -> AWS API Gateway ----> Lambda Authorizer

Мой $connect маршрут:

enter image description here

Обратите внимание:

  • В настоящее время он не имеет Integration Response иRoute Response пока.Есть ли проблема с этим?
  • connect-authorizer - это имя моего Lambda Authorizer

connect-authorizer действительно получает запрос от клиента, но не может авторизовать клиента!

Ниже приведен код connect-authorizer (см. здесь , Request-based function):

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

Но я всегда получаю ошибку 500 с моего терминала wscat:

Error 500 from wscat

Вход CloudWatch:

enter image description here

Isесть проблема с Statement: [ [Object] ]?Почему я всегда получаю ошибку 500?

...