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

2 minute read
0

I used an AWS CloudFormation template—or OpenAPI 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
        .
        .
...

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

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

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

....

....

}

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

Note: For more information, see Describing parameters on the OpenAPI website.

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. If your proxy path parameter includes a correctly defined a URL path parameter mapping, then no error appears.


Related information

x-amazon-apigateway-integration.requestParameters object

Set up a proxy integration with a proxy resource

Setting up data transformations for REST APIs

AWS OFFICIAL
AWS OFFICIALUpdated 2 years ago