Example #1
0
        /// 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);
            }
        }
Example #2
0
        /// 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}");
            }
        }