MCPcopy Create free account
hub / github.com/aws-samples/aws-lambda-extensions / Main

Method Main

csharp-example-extension/Program.cs:12–43  ·  view source on GitHub ↗
(string[] args)

Source from the content-addressed store, hash-verified

10 class Program
11 {
12 static async Task Main(string[] args)
13 {
14 var extensionName = (1 == args.Length)
15 ? args[0]
16 : Assembly.GetEntryAssembly()?.GetName()?.Name;
17
18 if (string.IsNullOrWhiteSpace(extensionName)) {
19 throw new InvalidOperationException("Failed to determine extension name!");
20 }
21
22 using var client = new ExtensionClient(extensionName);
23
24 // ProcessEvents will loop internally until SHUTDOWN event is received
25 await client.ProcessEvents(
26 // this expression will be called immediately after successful extension registration with Lambda Extension API
27 onInit: async id => {
28 Console.WriteLine($"[{extensionName}] Registered extension with id = {id}");
29 await Task.CompletedTask; // useless await, so that compiler doesn't report warnings
30 },
31 // this will be called every time Lambda is invoked
32 onInvoke: async payload =>
33 {
34 Console.WriteLine($"[{extensionName}] Handling invoke from extension: {payload}");
35 await Task.CompletedTask; // useless await, so that compiler doesn't report warnings
36 },
37 // this will be called just once - after receiving SHUTDOWN event and before exitting the loop
38 onShutdown: payload => // this is an example of lambda expression implementation without async keyword
39 {
40 Console.WriteLine($"[{extensionName}] Shutting down extension: {payload}");
41 return Task.CompletedTask;
42 });
43 }
44 }
45}

Callers

nothing calls this directly

Calls 1

ProcessEventsMethod · 0.80

Tested by

no test coverage detected