0

I have set up an AWS API Gateway Web Socket API.

Overview of my setup: Client --(upgrade request)--> AWS API Gateway ----> Lambda Authorizer

My $connect route:

enter image description here

Note that:

  • It currently does not have Integration Response and Route Response yet. Is there problem with it?
  • connect-authorizer is the name of my Lambda Authorizer

connect-authorizer does receive request from the client, but fails to authorize the client!

Below is the code of connect-authorizer (refer from here, 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);
};

But I always get error 500 from my terminal wscat:

Error 500 from wscat

Log in CloudWatch:

enter image description here

Is there problem with Statement: [ [Object] ]? Why I always receive error 500?

quanguyen
  • 1,443
  • 3
  • 17
  • 29

1 Answers1

0

Have you tried adding an Integration Response? I believe the $connect route should return an object with the statusCode property set to 200.

I remember this answer helped me when I was struggling while setting things up.