1+ // C# file-based Lambda functions can be deployed to Lambda using the .NET Tool Amazon.Lambda.Tools.
2+ //
3+ // Command to install Amazon.Lambda.Tools
4+ // dotnet tool install -g Amazon.Lambda.Tools
5+ //
6+ // Command to deploy function
7+ // dotnet lambda deploy-function <lambda-function-name> BlueprintBaseName.1.cs
8+ //
9+ // Command to package function
10+ // dotnet lambda package BlueprintBaseName.1.zip BlueprintBaseName.1.cs
11+
12+
13+ #: package Amazon . Lambda. Core@2.8 .0
14+ #: package Amazon . Lambda. RuntimeSupport@1.14 .1
15+ #: package Amazon . Lambda. Serialization. SystemTextJson@2.4 .4
16+
17+ // Explicitly setting TargetFramework here is done to avoid
18+ // having to specify it when packaging the function with Amazon.Lambda.Tools
19+ #: property TargetFramework = net10 . 0
20+
21+ // By default File-based C# apps publish as Native AOT. When packaging Lambda function
22+ // unless the host machine is Amazon Linux a container build will be required.
23+ // Amazon.Lambda.Tools will automatically initate a container build if docker is installed.
24+ // Native AOT also requires the code and dependencies be Native AOT compatible.
25+ //
26+ // To disable Native AOT uncomment the following line to add the .NET build directive
27+ // that disables Native AOT.
28+ //#:property PublishAot=false
29+
30+ using Amazon . Lambda . Core ;
31+ using Amazon . Lambda . RuntimeSupport ;
32+ using Amazon . Lambda . Serialization . SystemTextJson ;
33+ using System . Text . Json . Serialization ;
34+
35+ // The function handler that will be called for each Lambda event
36+ var handler = ( string input , ILambdaContext context ) =>
37+ {
38+ return input . ToUpper ( ) ;
39+ } ;
40+
41+ // Build the Lambda runtime client passing in the handler to call for each
42+ // event and the JSON serializer to use for translating Lambda JSON documents
43+ // to .NET types.
44+ await LambdaBootstrapBuilder . Create ( handler , new SourceGeneratorLambdaJsonSerializer < LambdaSerializerContext > ( ) )
45+ . Build ( )
46+ . RunAsync ( ) ;
47+
48+
49+ // Since Native AOT is used by default with C# file-based Lambda functions the source generator
50+ // based Lambda serializer is used. Ensure the input type and return type used by the function
51+ // handler are registered on the JsonSerializerContext using the JsonSerializable attribute.
52+ [ JsonSerializable ( typeof ( string ) ) ]
53+ public partial class LambdaSerializerContext : JsonSerializerContext
54+ {
55+ }
0 commit comments