Skip to content

Commit a52359a

Browse files
committed
Add FileBasedFunction template
1 parent 3777829 commit a52359a

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"author": "AWS",
3+
"classifications": [
4+
"AWS",
5+
"Lambda",
6+
"Function"
7+
],
8+
"name": "Lambda File-Based",
9+
"identity": "AWS.Lambda.File-Based.CSharp",
10+
"groupIdentity": "AWS.Lambda.File-Based",
11+
"shortName": "lambda.FileBased",
12+
"tags": {
13+
"language": "C#"
14+
},
15+
"sourceName": "BlueprintBaseName.1",
16+
"preferNameDirectory": false,
17+
"symbols": {},
18+
"primaryOutputs": [
19+
{
20+
"path": "./BlueprintBaseName.1.cs"
21+
}
22+
]
23+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)