aws-lambda-dotnet | Libraries , samples and tools to help .NET Core developers | Cloud Functions library
kandi X-RAY | aws-lambda-dotnet Summary
kandi X-RAY | aws-lambda-dotnet Summary
Repository for the AWS NuGet packages and Blueprints to support writing AWS Lambda functions using .NET Core. For a history of releases view the release change log.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of aws-lambda-dotnet
aws-lambda-dotnet Key Features
aws-lambda-dotnet Examples and Code Snippets
Community Discussions
Trending Discussions on aws-lambda-dotnet
QUESTION
I have a nested JSON string that is passed to a lambda (part of a State Machine). I need to assign variables to each item in the dictionary which are then used further down the line in the Lambda process (not shown here). I have been able to write a couple of classes and a void to try and deserialize the json but I don't know how to integrate DeserialiseJSONString
into the lambda handler FunctionHandler
. My familiarity with Python does not seem to help with understanding how to utilize classes/functions here. Any input would be greatly appreciated. I am looking for the most simplistic approach possible (if that is possible). Here's my C# code:
ANSWER
Answered 2021-Jan-10 at 12:36I'll summarise the question then explain the steps to how I solved this. It's not hard, but there's some tricks newbies might miss.
Question:Given some json string, how can I easily deserialize the json string into a class (with children/nested classes, etc)
Answer:If we have the json schema (which you did provide), we need to do the following:
- Create some classes (which the data will be persisted too)
- Get the json text
- Deserialize
- Test/Assert.
Exactly like @chetanRanpariya said, let's use a website that generates these for us. Sure, having a small json might be trivial, but when you get a large json schema, then this saves you HEAPS of time.
Head over to https://json2csharp.com/ and paste your json schema in there, then ask that site to generate the output.
Even in the output they include a sample line of code to actually deserialize this!
The root
class is a crap name, so I usually rename it to what the json schema (data) is about. For this example, I'll leave it .. but I would have renamed this to message
or something.
Okay, so we have our classes generated as C# code .. now let's have a play.
2 Test codeTo test out simple C# code, I next use another website called DotNet Fiddler.
In this current "fiddle" you can see that I:
- setup the json message
- deserialize this message into a
root
class.
and the Newtonsoft nuget library is smart enough to figure everything out.
Let's have a look at what I did, so you don't miss out on the tricks, to get this working:
In order of the things I did
- Changed it to NET5.0
- Added
Newtonsoft.Json
nuget library (latest version) - Copy/Pasted the classes over from Json2CSharp. Notice how I've put them just under the Main method, here?
- Added that one line of code from Json2CSharp ->
Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse);
- Noticed that the code doesn't understand
JsonConvert
, so I added that namespace at the top of the file ->using Newtonsoft.Json;
- Now, created my fake json text and then passed that value into that deserialize method (notice the name of variable in the method name is
(json)
- Created a few more lines of code to print out the values of the class which the json was deserialized to.
and voila! we have some json deserialized and working.
Newbie trick: Notice the weird json string? how it is: var json = @"
... that @
makes the string a MULTI-LINE string (also called a verbatim string literal or something). When you do this, it's easier to read large swaths of string data over multi lines .. but we have to double-quote any "
(quotes). Normally, we escape a quote inside a string (e.g. \"
) but multi-lines don't like any escaping. It's a literal string .. hence the name.
QUESTION
I have an aws api gateway endpoint that I am trying to test using Mock Lambda Test Tool
command. The aws api gateway endpoint expects a input type which has NoOFHours, AutoRecharge properties. I am passing the body as "body": "{"NoOFHours":51&"\AutoRecharge":false}" but the aws framework throws a "Error deserializing the input JSON to type APIGatewayProxyRequest" error.
How should a complex type be passed to a aws api gateway for testing?
...ANSWER
Answered 2020-May-31 at 03:25I was able to get this working by changing the "body"
to "{'NoOFHours':51,'AutoRecharge':false}"
.
QUESTION
I've recently switched jobs from a AWS shop to an Azure shop, both using dotnet. AWS publishes Amazon.Lambda.AspNetCoreServer, which is a magic Nuget package that allows you to write a plain ol' ASP.NET core Web API and deploy it as into a lambda with only a few lines on config. I really loved this pattern because it allows developers to just write a normal web api without having the host runtime leak into their coding.
Does anything like this exist in Azure? Even something that is community supported? Or is there some any way to achieve something like this in Azure Functions?
...ANSWER
Answered 2020-May-21 at 23:54Unfortunately there is no simple way to do that since Azure function format is a bit different.
QUESTION
ANSWER
Answered 2020-Apr-22 at 06:26Could you try and experiment for me and in your csproj file add the property CopyLocalLockFileAssemblies
with a value of true
and see if that changes your behavior?
Here is a full csproj file example.
QUESTION
ANSWER
Answered 2020-Feb-11 at 22:24Ok, there are several implicit questions lurking behind the original question. I would try to address your concerns to the best of my ability without taking to much of your time:
- In your second example the AWS AspNetCoreServer takes the
IActionResult
(which is actually aOkObjectResult
) and returns back something the lambda runtime can interpret as a response (same thing happens with APIGatewayProxyResponse). Responses to API Gateway are JSON documents with the structure below.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install aws-lambda-dotnet
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page