2

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?

2
  • Did the answer solved your issue? Commented Sep 19, 2017 at 0:25
  • Yep that worked thanks! I'm pretty new to Swagger, so I'm still a little unclear on what parts of the document are required by API Gateway. Commented Sep 24, 2017 at 4:58

1 Answer 1

4

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"
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.