-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathFunction.cs
More file actions
37 lines (32 loc) · 1.12 KB
/
Function.cs
File metadata and controls
37 lines (32 loc) · 1.12 KB
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
using Amazon.Lambda.Core;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace Function
{
public class Handler
{
public Dictionary<string, object> FunctionHandler(JsonElement input, ILambdaContext context)
{
context.Logger.LogLine("Hello world!");
var sleepMsStr = Environment.GetEnvironmentVariable("SLEEP_MS");
if (!string.IsNullOrEmpty(sleepMsStr) && int.TryParse(sleepMsStr, out int sleepMs) && sleepMs > 0)
{
context.Logger.LogLine($"Sleeping for {sleepMs}ms");
Thread.Sleep(sleepMs);
}
var body = new Dictionary<string, object>
{
{ "message", "Success" },
{ "requestId", context.AwsRequestId }
};
return new Dictionary<string, object>
{
{ "statusCode", 200 },
{ "body", JsonSerializer.Serialize(body) }
};
}
}
}