amazon-web-services - 无服务器 : Deploy Endpoint with Custom Authorizer - Name Not Found Error

标签 amazon-web-services lambda serverless-framework

我正在与 Serverless 合作使用自定义授权者部署函数的框架。该问题类似于 one described in this thread ,但没有详细的解决方案。

基本上,我有一个自定义授权者和函数按照文档中的规范设置,但是当我部署该函数(带有端点)时,我得到的错误是这个错误:

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 的“授权者”部分有关。它位于文件的 header 中,而不是端点中。我没有看到此设置的示例,并且不确定要放在这里的内容。任何想法或例子将不胜感激!

最佳答案

因此,我的 s-function.json 中的错误是由于自定义授权函数中的“authorizer”字段(而不是在实现身份验证代码的端点或函数中)造成的。

我需要将其添加到 s-function.json:

"authorizer": {
        "type": "TOKEN",
        "identitySource": "method.request.header.Authorization",
        "authorizerResultTtlInSeconds": "300"
      },

对于遇到同样问题的任何人,这里是用于自定义授权的完整 s-function.json。

    {
  "name": "exampleAuth",
  "runtime": "nodejs4.3",
  "description": "Custom Auth Function for exampleAPI",
  "customName": false,
  "customRole": false,
  "handler": "handler.handler",
  "timeout": 30,
  "memorySize": 256,
  "authorizer": {
    "type": "TOKEN",
    "identitySource": "method.request.header.Authorization",
    "authorizerResultTtlInSeconds": "300"
  },
  "custom": {
    "excludePatterns": []
  },
  "endpoints": [],
  "events": [],
  "environment": {
    "SERVERLESS_PROJECT": "${project}",
    "SERVERLESS_STAGE": "${stage}",
    "SERVERLESS_REGION": "${region}"
  },
  "vpc": {
    "securityGroupIds": [],
    "subnetIds": []
  }
}

我还没有弄清楚如何添加 token 验证表达式,并且我知道反射(reflect)区域和名称的控制台存在问题,但除此之外它工作得很好。

关于amazon-web-services - 无服务器 : Deploy Endpoint with Custom Authorizer - Name Not Found Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38363618/

相关文章:

amazon-web-services - 如何访问元组的值?

amazon-web-services - 托管在 aws s3 存储桶上的静态网站的自定义 url

c# - 将 C++ 特定功能映射到 C++/CLI

c# - 动态递归 lambda 表达式

memory-leaks - 使用 lambdas 作为事件处理程序会导致内存泄漏吗?

linux - su 和 sudo 未安装,但我需要 root 权限才能安装它们

python - Amazon lambda 不显示 python 日志

amazon-web-services - 为什么我的 ELB 有两个 IP 地址?如何找到它们?

node.js - 连接池和 lambda 终止

amazon-web-services - 如何在不停机的情况下使用无服务器框架更新 AWS lambda?