lambci / docker-lambda

Docker images and test runners that replicate the live AWS Lambda environment
MIT License
5.83k stars 431 forks source link

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value #142

Closed patelneel1994 closed 5 years ago

patelneel1994 commented 5 years ago

Usr:publish user$ docker run --rm -v "$PWD":/var/task lambci/lambda:dotnetcore2.1 MyFunction::MyFunction.Function::FunctionHandler '{"input": "event"}'

image

I am getting below error when I try to invoke the lambda function. I am fairly new to Docker. I just wanted to make sure I am not doing anything crazy. Looking at the error below, it seems like it is having issue with parsing json event. I have also tried to feed "{"input": "event"}", but still having issue with parsing json. I may be just doing something wrong.

START RequestId: 1b29ef36-eadc-4ae5-89f4-fc9a030f117d Version: $LATEST END RequestId: 1b29ef36-eadc-4ae5-89f4-fc9a030f117d REPORT RequestId 1b29ef36-eadc-4ae5-89f4-fc9a030f117d Duration: 143 ms Billed Duration: 200 ms Memory Size 1536 MB Max Memory Used: 36 MB AWSLambda.Internal.Bootstrap.LambdaUserCodeException: An exception occurred while invoking customer handler. ---> Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: {. Path '', line 1, position 1. 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 Amazon.Lambda.Serialization.Json.JsonSerializer.Deserialize[T](Stream requestStream) at lambda_method(Closure , Stream , Stream , LambdaContextInternal ) at AWSLambda.Internal.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, Stream outStream, LambdaContextInternal contextInternal) in /opt/workspace/LambdaSandboxCoreCLR-2-1/src/Bootstrap/UserCodeLoader.cs:line 150 --- End of inner exception stack trace --- at AWSLambda.Internal.Bootstrap.UserCodeLoader.Invoke(Stream lambdaData, Stream outStream, LambdaContextInternal contextInternal) in /opt/workspace/LambdaSandboxCoreCLR-2-1/src/Bootstrap/UserCodeLoader.cs:line 154 at MockLambdaRuntime.Program.Main(String[] args) in /source/Program.cs:line 61

patelneel1994 commented 5 years ago

Never mind I got it by passing the parameter like below docker run --rm -v "$PWD":/var/task lambci/lambda:dotnetcore2.1 MyFunction::MyFunction.Function::FunctionHandler \"input\"

I basically had to add backward slashes before each double quote.