2017-09-16 84 views
1

我嘗試了API網關中的HTTP傳遞功能,將資源方法傳遞給另一個API。我想通過API網關URL的路徑參數傳遞給也需要這些路徑參數的後端API。AWS API網關 - HTTP傳遞路徑參數

我有以下簡單揚鞭文件試圖測試了這一點:

{ 
    "swagger": "2.0", 
    "info": { 
    "version": "2017-09-15T03:33:48Z", 
    "title": "api-gateway-http-test" 
    }, 
    "schemes": [ 
    "https" 
    ], 
    "paths": { 
    "/subresource/{name}": { 
     "get": { 
     "produces": [ 
      "application/json" 
     ], 
     "responses": { 
      "200": { 
      "description": "200 response", 
      "schema": { 
       "$ref": "#/definitions/Empty" 
      } 
      } 
     }, 
     "x-amazon-apigateway-integration": { 
      "uri": "http://my.web.service.url/subresource/{name}", 
      "passthroughBehavior": "when_no_match", 
      "httpMethod": "GET", 
      "type": "http_proxy", 
      "requestParameters": { 
      "integration.request.path.name": "method.request.path.name" 
      } 
     } 
     } 
    } 
    }, 
    "definitions": { 
    "Empty": { 
     "type": "object", 
     "title": "Empty Schema" 
    } 
    } 
} 

當我嘗試通過CloudFormation部署這對API網關API網關使我這個錯誤:

Unable to put integration on 'GET' for resource at path '/subresource/{name}': 
Invalid mapping expression specified: 
Validation Result: 
warnings : [], errors : [Invalid mapping expression parameter specified: method.request.path.name] 

我已經在線查看各種源,並且這種配置「requestParameters」部分的方式似乎是將路徑參數傳遞到後端API的推薦方式。

我在這裏錯過了什麼,會導致這不起作用?

+0

沒有答案解決您的問題? – Kannaiyan

+0

是的,工作謝謝!我對Swagger很陌生,所以我仍然不清楚API Gateway需要文檔的哪些部分。 – dsw88

回答

2

缺少參數定義。

與下面檢查出來,

{ 
    "swagger": "2.0", 
    "info": { 
    "version": "2017-09-15T03:33:48Z", 
    "title": "api-gateway-http-test" 
    }, 
    "schemes": [ 
    "https" 
    ], 
    "paths": { 
    "/subresource/{name}": { 
     "get": { 
     "produces": [ 
      "application/json" 
     ], 
     "parameters": [ 
      { 
      "name": "name", 
      "in": "path", 
      "required": true, 
      "type": "string" 
      } 
     ], 
     "responses": { 
      "200": { 
      "description": "200 response", 
      "schema": { 
       "$ref": "#/definitions/Empty" 
      } 
      } 
     }, 
     "x-amazon-apigateway-integration": { 
      "uri": "http://google.com/subresource/{name}", 
      "passthroughBehavior": "when_no_match", 
      "httpMethod": "GET", 
      "type": "http_proxy", 
      "requestParameters": { 
      "integration.request.path.name": "method.request.path.name" 
      } 
     } 
     } 
    } 
    }, 
    "definitions": { 
    "Empty": { 
     "type": "object", 
     "title": "Empty Schema" 
    } 
    } 
}