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:
Note that:
- It currently does not have
Integration Response
andRoute 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
:
Log in CloudWatch
:
Is there problem with Statement: [ [Object] ]
? Why I always receive error 500?