Skip to content

Commit 6aa6757

Browse files
committed
More changes to support AOT
1 parent 4439450 commit 6aa6757

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

sample/SampleLambda-dotnet8/HelloWorldHandler.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Amazon.Lambda.Core;
22
using HeadlessChromium.Puppeteer.Lambda.Dotnet;
33
using Microsoft.Extensions.Logging;
4+
using System.Text.Json.Serialization;
45

56
namespace SampleLambda
67
{
@@ -22,4 +23,17 @@ public async Task<byte[]> Handle(ILambdaContext context)
2223
return await File.ReadAllBytesAsync("./google.png");
2324
}
2425
}
26+
27+
/// <summary>
28+
/// This class is used to register the input event and return type for the FunctionHandler method with the System.Text.Json source generator.
29+
/// There must be a JsonSerializable attribute for each type used as the input and return type or a runtime error will occur
30+
/// from the JSON serializer unable to find the serialization information for unknown types.
31+
/// </summary>
32+
[JsonSerializable(typeof(string))]
33+
public partial class LambdaFunctionJsonSerializerContext : JsonSerializerContext
34+
{
35+
// By using this partial class derived from JsonSerializerContext, we can generate reflection free JSON Serializer code at compile time
36+
// which can deserialize our class and properties. However, we must attribute this class to tell it what types to generate serialization code for.
37+
// See https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-source-generation
38+
}
2539
}

sample/SampleLambda-dotnet8/aws-lambda-tools-defaults.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"function-timeout": 60,
77
"function-handler": "SampleLambda::SampleLambda.HelloWorldHandler::Handle",
88
"package-type": "image",
9-
"docker-host-build-output-dir": "./bin/Release/lambda-publish"
10-
}
9+
"docker-host-build-output-dir": "./bin/Release/lambda-publish",
10+
"msbuild-parameters": "--self-contained true"
11+
}

0 commit comments

Comments
 (0)