1
我嘗試使用Swagger/OpenAPI定義我的AWS Api網關基礎結構。一切工作到目前爲止,但我有問題,需要我的端點的API密鑰。設置AWS API Gateway需要的API Key(Swagger import)
我揚鞭文件看起來像這樣(縮短):
---
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模板中。但是,當我在AWS Web Console中打開端點時,API密鑰要求的標記仍爲false。
有什麼建議嗎?謝謝。
答案的來源是這樣的句子:「客戶端現在可以調用API方法,同時提供具有所選API密鑰的x-api-key標頭作爲標頭值。」在aws文檔中可以看到:https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html –