By using AWS re:Post, you agree to the Terms of Use
/RequestParameters for Api Event in Serverless::Function in JSON - how does it work?/

RequestParameters for Api Event in Serverless::Function in JSON - how does it work?

0

I'm trying to add some query string parameters for a Lambda function, using a SAM template written in JSON. All the examples are in YAML? Can anyone point out where I'm going wrong.

Here's the snippet of the definition:

    "AreaGet": {
      "Type": "AWS::Serverless::Function",
      "Properties": {
        "Handler": "SpeciesRecordLambda::SpeciesRecordLambda.Functions::AreaGet",
        "Runtime": "dotnet6",
        "CodeUri": "",
        "MemorySize": 256,
        "Timeout": 30,
        "Role": null,
        "Policies": [
          "AWSLambdaBasicExecutionRole"
        ],
        "Events": {
          "AreaGet": {
            "Type": "Api",
            "Properties": {
              "Path": "/",
              "Method": "GET",
              "RequestParameters": [
                "method.request.querystring.latlonl": {
                  "Required": "true"
                },
                "method.request.querystring.latlonr": {
                  "Required": "true"
                }
              ]
            }
          }
        }
      }
    },

and here's the error message I get:

Failed to create CloudFormation change set: Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [AreaGet] is invalid. Event with id [AreaGet] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'.

Sorry I know this is a bit of a beginners question, but I'm a bit lost as to what to do, as I can't find any information about this using JSON. Maybe you can't do it using JSON?

Thanks, Andy.

1 Answers
0
Accepted Answer

Hi, @Andy Douglas.
Does it work if you enclose the elements of the array in {} as follows?

"Events": {
    "AreaGet": {
        "Type": "Api",
        "Properties": {
            "Path": "/",
            "Method": "GET",
            "RequestParameters": [
                {
                    "method.request.querystring.latlonl": {
                        "Required": "true"
                    }
                },
                {
                    "method.request.querystring.latlonr": {
                        "Required": "true"
                    }
                }
            ]
        }
    }
}
EXPERT
answered 15 days ago
  • Ah that's it! Thank you. Rather annoyingly, that works!

    I say annoyingly, because I'm sure I tried that (?) but also because visual studio hates it - it's all in red, and vs2022 is pretty good at these things usually. I guess the problem was me not really knowing JSON or YAML properly and how to translate between them - I thought I did, but maybe not. Examples using JSON in the docs would be very welcome though.

    Thanks again - I can move forward now. Andy.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions