I have an API Gateway with an endpoint that is fulfilled by AWS Lambda proxy integration. I have also configured a custom authorizer for this endpoint. I am seeing an issue where the first request that I make to this endpoint is successful, but additional calls will fail; I get a 403 - Forbidden error. If I wait a while, I can make another request that succeeds but then I start seeing the same problem.
Here's my code for the authorizer:
const jwt = require('jsonwebtoken');
exports.authorizer = async function (event, context) {
const bearerToken = event.authorizationToken.slice(7);
const { payload } = jwt.decode(bearerToken);
return {
principalId: payload.sub,
policyDocument: {
Version: '2012-10-17',
Statement: [{
Action: 'execute-api:Invoke',
Effect: 'Allow',
Resource: event.methodArn,
}],
},
};
};
In the API Gateway logs for this endpoint I can see that the authorizer is returning Allow
but I can still see that the authorization fails:
(50ac5f87-e152-4933-a797-63d84a528f61) The client is not authorized to perform this operation.
Does anyone know how or why this could happen?