I am trying to write an AWS Lambda function in C #. I have an AWS Toolkit for Visual Studio 2015. I created a project with the AWS Lambda Project (.Net Core) and then selected the Empty Function option. Which gave me the following code:
UPDATE and RESPONSE 02/24/17 . The comment designated as βAnswerβ was useful knowledge, but was not the actual answer for me. It was a comment by @PavelSafronov in this answer that did the trick. I either missed nothing (and got an error), or I assumed that he wants me to send information in JSON format, so I would enter { "input": "Some string" } and still get the error. Now that I just went to "Some string", it worked. However , as far as I know, this seems like a mistake. A string is nullable by default, and the code written by Amazon even assumes that it can be virtual input?.ToUpper() , where ?. checks for null .
Note: I added the lines LambdaLogger.Log and Constructor to see where I get:
using Amazon.Lambda.Core; using Amazon.Lambda.Serialization.Json;
The output screen and Solution Explorer said:
Errors in C:\Test Projects\AWSLambda1\AWSLambda1\AWSLambda1.xproj Unable to resolve 'Amazon.Lambda.Core (>= 1.0.0)' for '.NETCoreApp,Version=v1.0'.
However, this will result in a crash and publication in AWS. I can even call it, which returns the following: And my main question :
{ "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 )" ] }
The log file indicated that the Constructors log message appeared, but is NOT the actual KevingsTestFunction log KevingsTestFunction .
On the side of the note, I can get the Unable to resolve 'Amazon.Lambda.Core (>= 1.0.0)' for '.NETCoreApp,Version=v1.0' error Unable to resolve 'Amazon.Lambda.Core (>= 1.0.0)' for '.NETCoreApp,Version=v1.0' to leave by adding the following to my project.json file:
"runtimes": { "win10-x64": {}, "win81-x64": {}, "win8-x64": {}, "win7-x64": {} }
Which makes sense on a Windows machine, not on Amazon. Do I need a few different runtime(s) ?
This change did not change the JsonReaderException .
I tried adding "Linux": {} , but didn't change anything.
I even tried updating the Microsoft.NETCore.App NuGet package from 1.0.0 to 1.1.0 , and it did nothing and even returned to 1.0.1 .
I would point out that the default example that they give you will work, but I'm wrong. It looks like there are problems with the Amazon.Lambda.Serialization.Json.JsonSerializer attribute. Can I just use NewtonSoft ?