I created a .Net Core 6 app - HealthCheckerApp, which calls an HTTP GET request to one of my APIs hosted on Api gateway + Lambda to ensure it is accessible. Then, I pushed this code into AWS Lambda and scheduled it to run every minute using the AWS EventBridge Scheduler. It runs the code and gives the successful output, but I can see the Runtime in logs.ExitError after the successful console write. I am not sure why it is causing it. I tried changing Lambda RAM from 128 to 8008 MB, but I got the same error.
Log:
Health check successful!
INIT_REPORT Init Duration: 244.15 ms Phase: invoke Status: error Error Type: Runtime.ExitError
or sometimes:
START RequestId: 2365fc8f-4401-447d-8b3d-3ef00c5be943 Version: $LATEST
RequestId: 2365fc8f-4401-447d-8b3d-3ef00c5be943 Error: Runtime exited without providing a reason
Runtime.ExitError
END RequestId: 2365fc8f-4401-447d-8b3d-3ef00c5be943
REPORT RequestId: 2365fc8f-4401-447d-8b3d-3ef00c5be943 Duration: 245.46 ms Billed Duration: 246 ms Memory Size: 512 MB Max Memory Used: 17 MB
Program.cs:
using System;
using System.Threading.Tasks;
public class Program
{
public static async Task Main(string[] args)
{
try
{
var healthChecker = new HealthChecker();
var isHealthy = await healthChecker.CheckHealthAsync();
if (isHealthy)
{
Console.WriteLine("Health check successful!");
}
else
{
Console.WriteLine("Health check failed!");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error program file: {ex.Message}");
}
}
}
HealthChecker.cs
using System;
using System.Net.Http;
using System.Threading.Tasks;
public class HealthChecker
{
private readonly HttpClient _httpClient;
public HealthChecker()
{
try
{
_httpClient = new HttpClient();
}
catch (Exception ex)
{
Console.WriteLine($"Error http client {ex.Message}");
throw;
}
}
public async Task<bool> CheckHealthAsync()
{
try
{
var response = await _httpClient.GetAsync("https://<api gateway custom domain + endpoint>");
response.EnsureSuccessStatusCode();
System.Console.WriteLine(await response.Content.ReadAsStringAsync());
return true;
}
catch (Exception ex)
{
Console.WriteLine($"Error checking health: {ex.Message}");
return false;
}
}
}
The command I used to publish this code and then zipped it to upload: dotnet publish -c Release --self-contained false -r linux-x64 -o publish