user82504
user82504

Reputation: 111

AWS Custom Authorizer is not working and returns request timed out

I am using AWS Custom Authorizer. I have taken the example of custom authorization code from https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html After deployment of API, I send the request with header 'allow' or 'deny' and I get the correct response. Second time when I request, then request timed out.

My Lambda handler code is as:

let authenticateHandler = require('./authenticate_handler').handler;

exports.handler = function (event, context, callback) {

console.log('event.path ====> : ', event.path);
  if(event.path) {
      console.log('API Gateway call!!!!!');
    lambdaHandler(event, context, callback);
  } else {
    console.log('Authentication call!!!!!');
    authenticateHandler(event, context, callback);
  }
};

Where my lambdahandler is a request handler on which request is routed when authoriser grants allow to request.

The logs that are generated from lambda function in both the cases are as:


2019-04-17T10:58:58.760Z    d1a35bcc-9336-4fe4-a5a2-55b0d86b4064    Token : allow
2019-04-17T10:58:58.761Z    d1a35bcc-9336-4fe4-a5a2-55b0d86b4064    ======>>> { principalId: 'user',
policyDocument: { Version: '2012-10-17', Statement: [ [ { Action: 'execute-api:Invoke',
Effect: 'Allow',
Resource: 'arn:aws:execute-api:us-east-1:xxxxxxxxxxxxx:xxxxxxxxxx/dev/GET/test/authorizer' } ] ] },
context: { stringKey: 'stringval', numberKey: 123, booleanKey: true } } 

---Here request ends and authorizer sends the request to API Gateway.
Route logs are:
2019-04-17T10:58:58.779Z    0ea765f9-2e93-4811-b391-f150a8e2248e    API Gateway call!!!!!
2019-04-17T10:58:58.779Z    0ea765f9-2e93-4811-b391-f150a8e2248e    Event object is: { numberKey: '123',
booleanKey: 'true',
stringKey: 'stringval',
principalId: 'user',
integrationLatency: 441 }
2019-04-17T10:58:58.799Z    0ea765f9-2e93-4811-b391-f150a8e2248e    I am in /test/authorizer allow

And at this time request ends.

Now I have sent a request with 'deny' header and have a look at the request:

2019-04-17T11:16:55.998Z    20a0ab60-ac0d-4323-81de-9869537ad7e5    Token : deny
2019-04-17T11:16:55.998Z    20a0ab60-ac0d-4323-81de-9869537ad7e5    ======>>> { principalId: 'user',
policyDocument: { Version: '2012-10-17', Statement: [ [ { Action: 'execute-api:Invoke',
Effect: 'Deny',
Resource: 'arn:aws:execute-api:us-east-1:xxxxxxxxxxx:xxxxxx/dev/GET/test/authorizer' } ] ] },
context: { stringKey: 'stringval', numberKey: 123, booleanKey: true } } 

API Gateway's logs in case of deny are:

(4f4d3765-6102-11e9-a7ed-39a90f976cc3) Incoming identity: **ny
(4f4d3765-6102-11e9-a7ed-39a90f976cc3) Endpoint request body after transformations:
{
    "type": "TOKEN",
    "methodArn": "arn:aws:execute-api:us-east-1:xxxxxxxxxxx:xxxxxxxxx/dev/GET/test/authorizer",
    "authorizationToken": "deny"
}
(4f4d3765-6102-11e9-a7ed-39a90f976cc3) Sending request to https://lambda.us-east-1.amazonaws.com/2015-03-31/functions/arn:aws:lambda:us-east-1:xxxxxxxxxxxx:function:AuthrorizerTest/invocations
(4f4d3765-6102-11e9-a7ed-39a90f976cc3) Execution failed due to a timeout error
(4f4d3765-6102-11e9-a7ed-39a90f976cc3) Execution failed due to configuration error: Authorizer error

I am unable to figure out what this authorizer error is.

Any help would be much appreciated.

Upvotes: 0

Views: 1005

Answers (1)

user82504
user82504

Reputation: 111

I found the answer at the following link:

Why does AWS Lambda function always time out?

context.callbackWaitsForEmptyEventLoop = false;

works for me.

Upvotes: 1

Related Questions