gpt4 book ai didi

amazon-web-services - 设置 AWS ApiGateway 端点所需的 API key (Swagger 导入)

转载 作者:行者123 更新时间:2023-12-04 18:59:07 26 4
gpt4 key购买 nike

我尝试使用 Swagger/OpenAPI 定义我的 AWS Api Gateway 基础设施。到目前为止一切正常,但是我在为我的端点启用 API key 时遇到问题。

我的 Swagger 文件如下所示(缩短):

---
swagger: 2.0
basePath: /dev
info:
title: My API
description: Proof of concept
schemes:
- https
securityDefinitions:
api_key:
type: apiKey
name: X-Api-Key
in: header

paths:
/example-path:
options:
consumes:
- application/json
produces:
- application/json
x-amazon-apigateway-integration:
type: mock
requestTemplates:
application/json: |
{
"statusCode" : 200
}
responses:
"default":
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'GET,HEAD,OPTIONS'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
responseTemplates:
application/json: |
{}
responses:
200:
description: Default response for CORS method
headers:
Access-Control-Allow-Headers:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Origin:
type: "string"

get:
security:
- api_key: []
x-amazon-apigateway-integration:

# Further definition of the endpoint, calling Lambda etc...

链接到 CloudFormation 模板内后,Swagger 文件已成功处理。但当我在 AWS Web 控制台中打开终端节点时,需要 API key 标记仍然错误

有什么建议吗?谢谢。

最佳答案

找到解决方案:API key 必须命名为 x-api-key(全部小写)。

似乎只有这样才能在导入过程中识别设置。

关于amazon-web-services - 设置 AWS ApiGateway 端点所需的 API key (Swagger 导入),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42553093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com