Node.js API未根据lambda授权者的响应调用lambda并返回null消息
我正在尝试根据Lambda授权人的响应对api进行身份验证。因此,我创建了以下堆栈:Node.js API未根据lambda授权者的响应调用lambda并返回null消息,node.js,postman,aws-api-gateway,aws-serverless,Node.js,Postman,Aws Api Gateway,Aws Serverless,我正在尝试根据Lambda授权人的响应对api进行身份验证。因此,我创建了以下堆栈: Lambda函数调用“Test Lambda”,返回一些值 创建API网关并连接到“测试Lambda” 现在创建了一个authorizerlambda,用于验证请求头并返回策略。附加相同的API网关 现在,在部署了API之后,我通过PostMan使用以下参数进行了测试 Key: Authorization Value:allow 但在回应中,我得到了以下结果 { "message": null }
Key: Authorization
Value:allow
但在回应中,我得到了以下结果
{
"message": null
}
这是Lambda授权人代码。正如我在cloud watch日志中所验证的,这是基于请求执行的
module.exports.handler = async function(event, context) {
const token = event.authorizationToken.toLowerCase();
const methodArn = event.methodArn;
console.log("Lambda Invoked")
switch(token){
case 'allow':
return genertaeAuthResponse('user','Allow', methodArn);
default:
return genertaeAuthResponse('user','Deny', methodArn);
}
}
function genertaeAuthResponse(principalId, effect, methodArn) {
const policyDocument= generatePolicyDocument(effect, methodArn);
return {
principalId,
policyDocument
}
}
function generatePolicyDocument(effect, methodArn){
console.log("Lambda Invoked in the generatePolicyDocument", effect,methodArn)
if(!effect || !methodArn) return null
const policyDocument = {
Version: '2012-10-17',
Statemnet: [{
Action:'execute-api:Invoke',
Effect: effect,
Resource: methodArn
}]
};
console.log("policyDocument in the generatePolicyDocument", policyDocument)
return policyDocument
}
我在日志中看到以下响应
Version: '2012-10-17',
Statemnet: [
{
Action: 'execute-api:Invoke',
Effect: 'Allow',
Resource: 'arn:aws:execute-api:ap-southeast-1:myresource'
}
]
}
但我不明白为什么PostMan返回'null',通常返回'fail'值?看起来api网关没有根据授权者的响应调用lambda
如果有人能帮上忙,我会很感激的
谢谢有人能帮忙吗?