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개 답변
0
수락된 답변

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
전문가
iwasa
답변함 2년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠