简体   繁体   English

无服务器框架:在 serverless.yml 中为 HTTP API 网关路由配置预先存在的 lambda 身份验证器

[英]serverless framework: configuring a pre-existing lambda authenticator for HTTP API Gateway routes in serverless.yml

I would like to add a preexisting lambda authenticator to the routes of a preexisting http api gateway using the serverless framework.我想使用无服务器框架将预先存在的 lambda 身份验证器添加到预先存在的 http api 网关的路由中。 I have followed the docs, whereby I have specified the authorizer details under provider.httpApi (lines 15 to 18), and I have referenced the authorizer on the route(s) below (line 27 & 28).我已按照文档进行操作,据此我在 provider.httpApi 下指定了授权方详细信息(第 15 至 18 行),并且我在下面的路线(第 27 和 28 行)中引用了授权方。 Though I get the error message:虽然我收到错误消息:

Cannot setup authorizers for externally configured HTTP API无法为外部配置设置授权方 HTTP API

What am I doing wrong here?我在这里做错了什么? It must be for a HTTP API gateway and not a REST API gateway as thats what the current infra is configured as.它必须用于 HTTP API 网关,而不是 REST API 网关,因为这就是当前基础设施的配置。 Thanks谢谢

在此处输入图像描述

It looks like you're using an externally configured HTTP API (I'm guessing from the id being set).看起来您正在使用外部配置的 HTTP API(我从设置的id猜测)。 In such a situation, you cannot configure authorizers in this manner, you can only do so when you're provisioning HTTP API as a part of your serverless service.在这种情况下,您不能以这种方式配置授权方,您只能在将 HTTP API 作为无服务器服务的一部分进行配置时这样做。 What you can do there, is to setup a shared authorizer in a more manual way as described in docs here: https://www.serverless.com/framework/docs/providers/aws/events/http-api#shared-authorizer您可以在那里做的是以更手动的方式设置共享授权方,如此处文档中所述: https://www.serverless.com/framework/docs/providers/aws/events/http-api#shared-authorizer

I came across this post when researching how to use API gateway authorizers and serverless framework.我在研究如何使用 API 网关授权器和无服务器框架时遇到了这篇文章。 I was terraforming the API gateway therefore needed to terraform the authorizer as well.我正在改造 API 网关,因此还需要 terraform 授权方。 When created, I stashed the authorizer ID in a parameter store entry.创建时,我将授权方 ID 存储在参数存储条目中。 This is a 6 character alphanumeric value such as tw9qgj .这是一个 6 个字符的字母数字值,例如tw9qgj I then referenced the parameter as follows:然后我引用了参数如下:

custom:
  authorizerId: ${ssm:api_gateway_authoriser}

Then added the following block to each API eg然后将以下块添加到每个 API 例如

      - httpApi:
          path: /protected
          method: get
          authorizer:
            id: ${self:custom.authorizerId}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM