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 Antwort
0
Akzeptierte Antwort

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"
                    }
                }
            ]
        }
    }
}
profile picture
EXPERTE
iwasa
beantwortet vor 2 Jahren
  • 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.

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen