我正在使用Serverless框架来部署具有自定义授权方的功能。该问题与此线程中描述的问题相似,但没有详细的解决方案。
基本上,我有一个自定义授权者和函数设置为文档中的规范,但是当我部署函数(带端点)时,我得到的错误是这个错误:
Serverless: POST - exampleTest: Endpoint exampleTest~POST has an 'authorizerFunction' specified that does not exist in this project. Make sure the function's 'authorizer' property is filled in
这是端点的 s-function.json 部分:
"endpoints": [
{
"path": "exampleTest",
"method": "POST",
"type": "AWS",
"authorizationType": "custom",
"authorizerFunction": "exampleAuth",
"apiKeyRequired": false,
"requestParameters": {},
"requestTemplates": "$${apiRequestTemplate}",
"responses": {
"400": {
"statusCode": "400"
},
"default": {
"statusCode": "200",
"responseParameters": {},
"responseModels": {
"application/json;charset=UTF-8": "Empty"
},
"responseTemplates": {
"application/json;charset=UTF-8": ""
}
}
}
}
这是自定义授权方的整个 s-function.json:
{
"name": "exampleAuth",
"runtime": "nodejs4.3",
"description": "Custom Auth Function for API",
"customName": false,
"customRole": false,
"handler": "handler.handler",
"timeout": 30,
"memorySize": 256,
"authorizer": {},
"custom": {
"excludePatterns": []
},
"endpoints": [],
"events": [],
"environment": {
"SERVERLESS_PROJECT": "${project}",
"SERVERLESS_STAGE": "${stage}",
"SERVERLESS_REGION": "${region}"
},
"vpc": {
"securityGroupIds": [],
"subnetIds": []
}
}
不确定是否重要,但函数和自定义授权者在同一个项目但不同的文件夹中(即授权者不是函数的子文件夹)。
最后,如果我手动添加自定义授权者,一切正常。
感谢您的任何帮助或指导!
编辑: 经过额外研究,我认为该问题与 s-function.json 的“授权人”部分有关。这是在文件的标题中,而不是在端点中。我没有看到此设置的示例,我不确定在此处放置什么。任何想法或示例将不胜感激!