2017-09-16 88 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" 
    } 
    } 
}