Я использую 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 - это обработчик запроса, на который направляется запрос, когда разрешает авторизаторrequest.
Журналы, которые сгенерированы лямбда-функцией в обоих случаях, выглядят так:
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 Gateway в случае отказа:
(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
Я не могу выяснить, что это за ошибка авторизатора.
Любая помощь будетвысоко ценится.