【发布时间】:2017-07-22 00:59:42
【问题描述】:
我尝试使用 Swagger/OpenAPI 定义我的 AWS Api Gateway 基础设施。到目前为止一切正常,但是我的端点需要 API 密钥时遇到问题。
我的 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 Required 的标志仍然是 false。
有什么建议吗?谢谢。
【问题讨论】:
标签: amazon-web-services swagger aws-api-gateway amazon-cloudformation