dsw88
dsw88

Reputation: 4592

AWS API Gateway - HTTP Passthrough Path Parameters

I'm trying out the HTTP passthrough functionality in API gateway, passing through a resource method to another API. I want to pass through the path parameters from the API gateway URL to the backend API that also needs those path parameters.

I have the following simple Swagger document trying to test this out:

{
  "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"
    }
  }
}

When I try deploying this to API Gateway via CloudFormation, API Gateway gives me this error:

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]

I've looked at various sources online, and this way of configuring the "requestParameters" section seems to be the recommended way to pass through path parameters to the backend API.

What am I missing here that would cause this to not work?

Upvotes: 2

Views: 4824

Answers (1)

Kannaiyan
Kannaiyan

Reputation: 13025

It is missing parameter definitions.

Check it out with the below,

{
  "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"
    }
  }
}

Upvotes: 4

Related Questions