0

I have created an aws lambda function using c# in visual studio 2017 and I'm having problems with the parameters. I am trying to get the 'querystringparameter' but every time I put a parameter in my FunctionHandler I get this error.

{
  "errorType": "JsonReaderException",
  "errorMessage": "Unexpected character encountered while parsing value: {. Path '', line 1, position 1.",
  "stackTrace": [
    "at Newtonsoft.Json.JsonTextReader.ReadStringValue(ReadType readType)",
    "at Newtonsoft.Json.JsonTextReader.ReadAsString()",
    "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)",
    "at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)",
    "at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)",
    "at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)",
    "at lambda_method(Closure , Stream , Stream , ContextInfo )"
  ]
}

This is my sample FunctionHandler code :

public string FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            var sample = GetParameters(request.QueryStringParameters, "sample");
            return sample;
        }

What's wrong with this ? Answers would be very much appreciated. Thank you !

UPDATE

Error Message

7
  • What is the input do you pass to the lambda? Commented Oct 6, 2017 at 5:34
  • I pass a query parameter via API Gateway. Commented Oct 6, 2017 at 5:36
  • can you please provide how you are passing the parameters, I mean the format of JSON values Commented Oct 6, 2017 at 5:37
  • I pass the parameter via API Gateway when I'm testing it. I've also tried just passing in a string via testing of function in visual studio 2017 but I still get that same error. Commented Oct 6, 2017 at 5:39
  • 1
    the parameter you are passing is not a valid JSON format. Commented Oct 6, 2017 at 5:42

1 Answer 1

1

The exception means you are not passing your parameter as a valid JSON format. please make sure to pass your parameter in a string quoted format.

public string myFunctionHandler(string param, ILambdaContext context){
....
}

Passing parameter (in a string quoted format) should be looking like:

"{ \"param\": \"value\" }"

If you have an object:

public string myFunctionHandler(JObject param, ILambdaContext context) {
...
}

In this case, you can pass it like this:

{ "param": "value" }
Sign up to request clarification or add additional context in comments.

2 Comments

How about if I want to pass it as a query parameter but not via AWS API Gateway ? Like, api.com/v1?param=sample ...
@anonymous Such query parameter mapping can be configured as mentioned docs.aws.amazon.com/apigateway/latest/developerguide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.