-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathProgram.cs
45 lines (40 loc) · 1.93 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
using System;
using System.Reflection;
using System.Threading.Tasks;
namespace csharp_example_extension
{
class Program
{
static async Task Main(string[] args)
{
var extensionName = (1 == args.Length)
? args[0]
: Assembly.GetEntryAssembly()?.GetName()?.Name;
if (string.IsNullOrWhiteSpace(extensionName)) {
throw new InvalidOperationException("Failed to determine extension name!");
}
using var client = new ExtensionClient(extensionName);
// ProcessEvents will loop internally until SHUTDOWN event is received
await client.ProcessEvents(
// this expression will be called immediately after successful extension registration with Lambda Extension API
onInit: async id => {
Console.WriteLine($"[{extensionName}] Registered extension with id = {id}");
await Task.CompletedTask; // useless await, so that compiler doesn't report warnings
},
// this will be called every time Lambda is invoked
onInvoke: async payload =>
{
Console.WriteLine($"[{extensionName}] Handling invoke from extension: {payload}");
await Task.CompletedTask; // useless await, so that compiler doesn't report warnings
},
// this will be called just once - after receiving SHUTDOWN event and before exitting the loop
onShutdown: payload => // this is an example of lambda expression implementation without async keyword
{
Console.WriteLine($"[{extensionName}] Shutting down extension: {payload}");
return Task.CompletedTask;
});
}
}
}