AWS Custom Authorizer无法正常工作并返回请求超时

问题描述 投票:0回答:1

我正在使用AWS Custom Authorizer。我从https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html中获取了自定义授权代码的示例在部署API之后,我发送带有'allow'或'deny'标头的请求,我得到了正确的响应。我第二次请求时,请求超时。

我的Lambda处理程序代码如下:

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);
  }
};

我的lambdahandler是一个请求处理程序,当授权者授予允许请求时,请求被处理。

在两种情况下从lambda函数生成的日志如下:


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.

现在我发送了一个带有'deny'标题的请求并查看了请求:

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网关日志是:

(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

我无法弄清楚这个授权程序错误是什么。

任何帮助将非常感激。

node.js aws-lambda authorization
1个回答
0
投票

我在以下链接找到了答案:

Why does AWS Lambda function always time out?

context.callbackWaitsForEmptyEventLoop = false;

适合我。

© www.soinside.com 2019 - 2024. All rights reserved.