I created an API Gateway API with a proxy resource by using AWS CloudFormation or OpenAPI (Swagger). When I try to add URL path parameters to the API, I get the error "Invalid mapping expression specified." How do I resolve this error?

Last updated: 2019-06-10

I used an AWS CloudFormation template or OpenAPI (Swagger) definition to create an Amazon API Gateway API with a proxy resource. When I try to add URL path parameters to the API, I get the error "Invalid mapping expression specified." How do I fix this?

Short Description

This error can occur if you don't define a URL path parameter mapping for the proxy path parameter {proxy+} (also called a "greedy path variable").

In an AWS CloudFormation template, define the RequestParameters property of the AWS::ApiGateway::Method section. In an OpenAPI definition, define the parameters section under the x-amazon-apigateway-any-method object.

Resolution

AWS CloudFormation template

1.    Update your template, defining the RequestParameters property as follows:

"RequestParameters": {"method.request.path.proxy":true}

For more information about updates to API Gateway resources, see Amazon API Gateway Resource Type Reference.

2.    Update the AWS CloudFormation stack using your template. This action updates your API.

OpenAPI definition

1.    Update your API definition, defining the parameters under the x-amazon-apigateway-any-method section as follows:

      "x-amazon-apigateway-any-method": {
                "parameters": [
          {
            "name": "proxy",
            "in": "path",
            "required": true,
            "type": "string"
          }
        ]

....

....

}

For more information, see Describing Parameters on the OpenAPI website.

2.    Update your API by importing your updated API definition file into API Gateway.

(Optional) Verify the changes

After you update your AWS CloudFormation template or OpenAPI definition and then update your API, you can verify that the issue is fixed by checking the API Gateway console.

1.    In the API Gateway console, choose the name of your API.

2.    Add URL path parameters as needed for your use case. You should no longer get the error.