Amazon web services 如何使用Swagger在API网关上全局设置API密钥安全性
我正在尝试将openapi/swagger文件导入api网关,但无法按预期获得安全设置。我希望所有路径都需要一个api密钥 导入后在控制台中设置it api密钥是必需的,但是这个解决方案是不可取的,同样有效的是在每个路径中单独设置安全字段,但是我正在寻找一个全局解决方案 当我尝试导入文件时,会收到以下警告:Amazon web services 如何使用Swagger在API网关上全局设置API密钥安全性,amazon-web-services,swagger,aws-api-gateway,openapi,Amazon Web Services,Swagger,Aws Api Gateway,Openapi,我正在尝试将openapi/swagger文件导入api网关,但无法按预期获得安全设置。我希望所有路径都需要一个api密钥 导入后在控制台中设置it api密钥是必需的,但是这个解决方案是不可取的,同样有效的是在每个路径中单独设置安全字段,但是我正在寻找一个全局解决方案 当我尝试导入文件时,会收到以下警告: Your API was not imported due to errors in the Swagger file. Method 'GET' on resource '/'
Your API was not imported due to errors in the Swagger file.
Method 'GET' on resource '/' specified security,
but no custom authorizers were created and the extension
x-amazon-apigateway-auth was not set.
This method will be not be secured.
从外观上看,我要么需要一个lambda作为api密钥的自定义授权人(我不熟悉授权人,但如果在控制台中设置api密钥时不需要授权人,这似乎没有意义);或者我需要对这个神秘的x-amazon-apigateway-auth
做点什么,我找不到它的文档(amazon记录的所有其他openapi扩展)
下面是一个小型示例:
openapi: 3.0.1
info:
title: test
version: 0
servers:
- url: "/"
security:
- ApiKey: []
paths:
"/":
get:
# if I copy the security part into here things work
responses:
'204':
description: no content
x-amazon-apigateway-integration:
httpMethod: GET
type: http
uri: https://httpstat.us/204
components:
securitySchemes:
ApiKey:
type: apiKey
name: x-api-key
in: header
x-amazon-apigateway-api-key-source: HEADER
由于api密钥安全性设置在根级别,这向我建议所有路径都应该使用api密钥(除非被单个路径覆盖),实际发生的是上述警告,导入时不需要api密钥。在我编写此答案时,根据它们的,AWS API网关不支持在根级别设置安全性 API网关不使用OpenAPI规范中定义的根级别安全性。因此,需要在操作级别定义安全性,以便适当应用
嗨@Jonathan,你找到解决方案了吗?我已经有一段时间没有尝试过了,所以现在情况可能已经改变了,但当时我不得不接受在每个路径中分别设置安全字段。