You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc_source/csharp-handler.md
+36-52Lines changed: 36 additions & 52 deletions
Original file line number
Diff line number
Diff line change
@@ -50,47 +50,9 @@ All other types, as listed below, require you to specify a serializer\.
50
50
+ For asynchronous invocations the return\-type will be ignored by Lambda\. The return type may be set to void in such cases\.
51
51
+ If you are using \.NET asynchronous programming, the return type can be Task and Task<T> types and use `async` and `await` keywords\. For more information, see [Using async in C\# functions with AWS Lambda](#csharp-handler-async)\.
52
52
53
-
Unless your function input and output parameters are of type `System.IO.Stream`, you will need to serialize them\. AWS Lambda provides a default serializer that can be applied at the assembly or method level of your application, or you can define your own by implementing the `ILambdaSerializer` interface provided by the `Amazon.Lambda.Core` library\. For more information, see [Deploy C\# Lambda functions with \.zip file archives](csharp-package.md)\.
53
+
Unless your function input and output parameters are of type `System.IO.Stream`, you will need to serialize them\. AWS Lambda provides a default serializers that can be applied at the assembly or method level of your application, or you can define your own by implementing the `ILambdaSerializer` interface provided by the `Amazon.Lambda.Core` library\. For more information, see [Deploy C\# Lambda functions with \.zip file archives](csharp-package.md)\.
54
54
55
-
To add the default serializer attribute to a method, first add a dependency on `Amazon.Lambda.Serialization.Json` in your `.csproj` file\.
The example below illustrates the flexibility you can leverage by specifying the default Json\.NET serializer on one method and another of your choosing on a different method:
If you are using \.NET Core 3\.1, we recommend that you use the [ Amazon\.Lambda\.Serialization\.SystemTextJson](https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson) serializer\. This package provides a performance improvement over `Amazon.Lambda.Serialization.Json`\.
55
+
Instruction how to define serialize you can find in [Serializing Lambda functions](#csharp-handler-serializer)\.
For any Lambda functions that use input or output types other than a `Stream` object, you will need to add a serialization library to your application\. You can do this in the following ways:
131
-
+ Use the `Amazon.Lambda.Serialization.Json` NuGet package\. This library uses JSON\.NET to handle serialization\.
132
-
**Note**
133
-
If you are using \.NET Core 3\.1, we recommend that you use the [ Amazon\.Lambda\.Serialization\.SystemTextJson](https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.Serialization.SystemTextJson) serializer\. This package provides a performance improvement over `Amazon.Lambda.Serialization.Json`\.
93
+
+ Use the `Amazon.Lambda.Serialization.SystemTextJson` NuGet package\. This library uses native .net core JSON serializer to handle serialization\. This package provides a performance improvement over `Amazon.Lambda.Serialization.Json`, but please note that there are some limitation documented in the [Microsoft's documentation](https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-how-to?pivots=dotnet-core-3-1)\. It is only available for \.net core 3\.1 runtimes or higher\.
94
+
+ Use the `Amazon.Lambda.Serialization.Json` NuGet package\. This library uses `Newtonsoft.Json` NuGet package to handle serialization\.
134
95
+ Create your own serialization library by implementing the `ILambdaSerializer` interface, which is available as part of the `Amazon.Lambda.Core` library\. The interface defines two methods:
135
96
+`T Deserialize<T>(Stream requestStream);`
136
97
@@ -139,24 +100,47 @@ If you are using \.NET Core 3\.1, we recommend that you use the [ Amazon\.Lambda
139
100
140
101
You implement this method to serialize the result returned from the Lambda function handler into the response payload that is returned by the `Invoke` API\.
141
102
142
-
You use whichever serializer you wish by adding it as a dependency to your `MyProject.csproj` file\.
103
+
104
+
To use serializer you need to add a dependency to your `csproj` file\.
You then add it to your AssemblyInfo\.cs file\.For example, if you are using the default Json\.NET serializer, this is what you would add:
114
+
Next you need to define the serializer. For example you can define it in the AssemblyInfo\.cs file\.If you are using `Amazon.Lambda.Serialization.SystemTextJson`, the serializercan be defined that way:
You can define a custom serialization attribute at the method level, which will override the default serializer specified at the assembly level\. For more information, see [Handling standard data types](#csharp-handler-types)\.
126
+
You can also define a custom serialization attribute at the method level, which will override the default serializer specified at the assembly level\.
127
+
128
+
```
129
+
public class ProductService{
130
+
131
+
[LambdaSerializer(typeof(JsonSerializer))]
132
+
public Product DescribeProduct(DescribeProductRequest request)
0 commit comments