requestParameters returning "Invalid mapping expression specified: true"

Viewed 28214

I'm configuring a lambda function's API gateway integration with the Serverless Framework version 0.4.2.

My problem is with defining an endpoint's request parameters. The AWS docs for API gateway entry says:

requestParameters

Represents request parameters that can be accepted by Amazon API Gateway. Request parameters are represented as a key/value map, with a source as the key and a Boolean flag as the value. The Boolean flag is used to specify whether the parameter is required. A source must match the pattern method.request.{location}.{name}, where location is either querystring, path, or header. name is a valid, unique parameter name. Sources specified here are available to the integration for mapping to integration request parameters or templates.

As I understand it, the config in the s-function.json is given directly to the AWS CLI, so I've specified the request parameters in the format: "method.request.querystring.startYear": true. However, I'm receiving an Invalid mapping expression specified: true error. I've also tried specifying the config as "method.request.querystring.startYear": "true" with the same result.

s-function.json:

{
    "name": "myname",
    // etc...
    "endpoints": [
        {
            "path": "mypath",
            "method": "GET",
            "type": "AWS",
            "authorizationType": "none",
            "apiKeyRequired": false,
            "requestParameters": {
                "method.request.querystring.startYear": true,
                "method.request.querystring.startMonth": true,
                "method.request.querystring.startDay": true,
                "method.request.querystring.currentYear": true,
                "method.request.querystring.currentMonth": true,
                "method.request.querystring.currentDay": true,
                "method.request.querystring.totalDays": true,
                "method.request.querystring.volume": true,
                "method.request.querystring.userId": true
            },
            // etc...
        }
    ],
    "events": []
}

Any ideas? Thanks in advance!

4 Answers

First, you need to execute a put-method command for creating the Method- Request with query parameters:

aws apigateway put-method --rest-api-id "yourAPI-ID" --resource-id "yourResource-ID" --http-method GET --authorization-type "NONE" --no-api-key-required --request-parameters "method.request.querystring.paramname1=true","method.request.querystring.paramname2=true"

After this you can execute the put-integration command then only this will work. Otherwise it will give invalid mapping error

"requestParameters": {
    "integration.request.querystring.paramname1" : "method.request.querystring.paramname1",
    "integration.request.querystring.paramname2" : "method.request.querystring.paramname2",
Related