I’m trying to add a custom Lambda authorizer to my WebSocket API, but I’m stuck on what response needs to be returned.
My custom Lambda authorizer for the HTTP API looks like this. Based on the event, I simply return a result object, as shown in the example below.
function customHttpLambdaAuthorizer(event) {
const isValid = validate(event);
const result = {
isAuthorized: isValid === true,
context: {
message: "User authenticated"
}
};
return result;
}
When I tried to add a custom authorizer for a WebSocket and attempted to return a similar result, it didn’t work. I found this example in the AWS documentation, but they use a policy, which I don’t fully understand. I also have a feeling that the example is outdated because it uses callbacks, etc.
function customWebSocketLambdaAuthorizer(event) {
const isValid = validate(event);
const result = /* ? */;
return result;
}
Could someone clearly explain what a custom WebSocket Lambda authorizer should return, and why?
Thanks!