How do I resolve an "Invalid mapping expression specified" error from API Gateway?

Last updated: 2021-03-22

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 an "Invalid mapping expression specified" error message. How do I resolve the error?

Short description

API Gateway returns an Invalid mapping expression specified error when the proxy path parameter {proxy+} doesn't have a defined a URL path parameter mapping.

To resolve the error, do the following:

Resolution

For CloudFormation templates

1.    Update the CloudFormation template so that the RequestParameters value is set to true.

Example CloudFormation template RequestParameters

...
.
.
  ProxyMethod:
    Type: 'AWS::ApiGateway::Method'
    Properties:
      .
      .
      RequestParameters:
       
        method.request.path.proxy: true
       
      Integration:
        RequestParameters:
          integration.request.path.proxy: 'method.request.path.proxy'
       
        IntegrationHttpMethod: ANY
        .
        .
...

For more information on how to update API Gateway resources, see Amazon API Gateway resource type reference.

2.    Update your API by using the CloudFormation template to update the AWS CloudFormation stack.

For OpenAPI definitions

1.    Update your API definition so that the parameters under the x-amazon-apigateway-any-method section have the following values:

      "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.

Test the setup

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

2.    Add URL path parameters as needed for your use case.
Note: The Invalid mapping expression specified error should not appear.