static void LogRequestEnd(MockLambdaContext context) { Console.Error.WriteLine($"END RequestId: {context.RequestId}"); Console.Error.WriteLine($"REPORT RequestId {context.RequestId}\t" + $"Duration: {context.Duration} ms\t" + $"Billed Duration: {context.BilledDuration} ms\t" + $"Memory Size {context.MemorySize} MB\t" + $"Max Memory Used: {context.MemoryUsed / (1024 * 1024)} MB"); }
/// Program entry point static void Main(string[] args) { AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; var handler = GetFunctionHandler(args); var body = GetEventBody(args); var lambdaContext = new MockLambdaContext(handler, body); var userCodeLoader = new UserCodeLoader(handler, InternalLogger.NO_OP_LOGGER); userCodeLoader.Init(Console.Error.WriteLine); var lambdaContextInternal = new LambdaContextInternal(lambdaContext.RemainingTime, LogAction, new Lazy <CognitoClientContextInternal>(), lambdaContext.RequestId, new Lazy <string>(lambdaContext.Arn), new Lazy <string>(string.Empty), new Lazy <string>(string.Empty), Environment.GetEnvironmentVariables()); Exception lambdaException = null; LogRequestStart(lambdaContext); try { userCodeLoader.Invoke(lambdaContext.InputStream, lambdaContext.OutputStream, lambdaContextInternal); } catch (Exception ex) { lambdaException = ex; } LogRequestEnd(lambdaContext); if (lambdaException == null) { Console.WriteLine(lambdaContext.OutputText); } else { Console.Error.WriteLine(lambdaException); } }
static void LogRequestStart(MockLambdaContext context) { Console.Error.WriteLine($"START RequestId: {context.RequestId} Version: {context.FunctionVersion}"); }
/// Program entry point static void Main(string[] args) { AssemblyLoadContext.Default.Resolving += OnAssemblyResolving; try { var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs); var handler = GetFunctionHandler(positionalArgs); var body = GetEventBody(positionalArgs); if (shouldWaitForDebugger) { Console.Error.WriteLine("Waiting for the debugger to attach..."); if (!DebuggerExtensions.TryWaitForAttaching( _debuggerStatusQueryInterval, _debuggerStatusQueryTimeout)) { Console.Error.WriteLine("Timeout. Proceeding without debugger."); } } var lambdaContext = new MockLambdaContext(handler, body); var userCodeLoader = new UserCodeLoader(handler, InternalLogger.NO_OP_LOGGER); userCodeLoader.Init(Console.Error.WriteLine); var lambdaContextInternal = new LambdaContextInternal(lambdaContext.RemainingTime, LogAction, new Lazy <CognitoClientContextInternal>(), lambdaContext.RequestId, new Lazy <string>(lambdaContext.Arn), new Lazy <string>(string.Empty), new Lazy <string>(string.Empty), Environment.GetEnvironmentVariables()); Exception lambdaException = null; LogRequestStart(lambdaContext); try { userCodeLoader.Invoke(lambdaContext.InputStream, lambdaContext.OutputStream, lambdaContextInternal); } catch (Exception ex) { lambdaException = ex; } LogRequestEnd(lambdaContext); if (lambdaException == null) { Console.WriteLine(lambdaContext.OutputText); } else { Console.Error.WriteLine(lambdaException); } } // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging catch (Exception ex) { Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}"); } }