in Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/LambdaBootstrap.cs [167:236]
public async Task RunAsync(CancellationToken cancellationToken = default(CancellationToken))
{
#if NET8_0_OR_GREATER
AdjustMemorySettings();
#endif
if (_configuration.IsCallPreJit)
{
this._logger.LogInformation("PreJit: CultureInfo");
UserCodeInit.LoadStringCultureInfo();
this._logger.LogInformation("PreJit: Amazon.Lambda.Core");
UserCodeInit.PreJitAssembly(typeof(Amazon.Lambda.Core.ILambdaContext).Assembly);
}
// For local debugging purposes this environment variable can be set to run a Lambda executable assembly and process one event
// and then shut down cleanly. Useful for profiling or running local tests with the .NET Lambda Test Tool. This environment
// variable should never be set when function is deployed to Lambda.
var runOnce = string.Equals(Environment.GetEnvironmentVariable(Constants.ENVIRONMENT_VARIABLE_AWS_LAMBDA_DOTNET_DEBUG_RUN_ONCE), "true", StringComparison.OrdinalIgnoreCase);
if (_initializer != null && !(await InitializeAsync()))
{
return;
}
#if NET8_0_OR_GREATER
// Check if Initialization type is SnapStart, and invoke the snapshot restore logic.
if (_configuration.IsInitTypeSnapstart)
{
InternalLogger.GetDefaultLogger().LogInformation($"In LambdaBootstrap, Initializing with SnapStart.");
object registry = null;
try
{
registry = SnapstartHelperCopySnapshotCallbacksIsolated.CopySnapshotCallbacks();
}
catch (TypeLoadException ex)
{
Client.ConsoleLogger.FormattedWriteLine(
Amazon.Lambda.RuntimeSupport.Helpers.LogLevelLoggerWriter.LogLevel.Error.ToString(),
$"Failed to retrieve snapshot hooks from Amazon.Lambda.Core.SnapshotRestore, " +
$"this can be fixed by updating the version of Amazon.Lambda.Core: {ex}",
null);
}
// no exceptions in calling SnapStart hooks or /restore/next RAPID endpoint
if (!(await SnapstartHelperInitializeWithSnapstartIsolatedAsync.InitializeWithSnapstartAsync(Client,
registry)))
{
return;
};
}
#endif
while (!cancellationToken.IsCancellationRequested)
{
try
{
await InvokeOnceAsync(cancellationToken);
if(runOnce)
{
_logger.LogInformation("Exiting Lambda processing loop because the run once environment variable was set.");
return;
}
}
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
{
// Loop cancelled
}
}
}