Example #1
0
 public static async Task RunAsync <T>(Func <T, ILambdaContext, Task> func, CancellationToken cancellationToken)
 {
     using var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new DefaultLambdaJsonSerializer());
     using var bootstrap      = new LambdaBootstrap(handlerWrapper);
     await bootstrap.RunAsync(cancellationToken).ConfigureAwait(false);
 }
Example #2
0
        private static async Task Main(string[] args)
        {
            var             handler        = LambdaEnvironment.Handler;
            LambdaBootstrap bootstrap      = null;
            HandlerWrapper  handlerWrapper = null;

            try
            {
                switch (handler)
                {
                case nameof(LoggingStressTest):
                    bootstrap = new LambdaBootstrap(LoggingStressTest);
                    break;

                case nameof(LoggingTest):
                    bootstrap = new LambdaBootstrap(LoggingTest);
                    break;

                case nameof(ToUpperAsync):
                    bootstrap = new LambdaBootstrap(ToUpperAsync);
                    break;

                case nameof(PingAsync):
                    bootstrap = new LambdaBootstrap(PingAsync);
                    break;

                case nameof(HttpsWorksAsync):
                    bootstrap = new LambdaBootstrap(HttpsWorksAsync);
                    break;

                case nameof(CertificateCallbackWorksAsync):
                    bootstrap = new LambdaBootstrap(CertificateCallbackWorksAsync);
                    break;

                case nameof(NetworkingProtocolsAsync):
                    bootstrap = new LambdaBootstrap(NetworkingProtocolsAsync);
                    break;

                case nameof(HandlerEnvVarAsync):
                    bootstrap = new LambdaBootstrap(HandlerEnvVarAsync);
                    break;

                case nameof(AggregateExceptionUnwrappedAsync):
                    bootstrap = new LambdaBootstrap(AggregateExceptionUnwrappedAsync);
                    break;

                case nameof(AggregateExceptionUnwrapped):
                    handlerWrapper = HandlerWrapper.GetHandlerWrapper((Action)AggregateExceptionUnwrapped);
                    bootstrap      = new LambdaBootstrap(handlerWrapper);
                    break;

                case nameof(AggregateExceptionNotUnwrappedAsync):
                    bootstrap = new LambdaBootstrap(AggregateExceptionNotUnwrappedAsync);
                    break;

                case nameof(AggregateExceptionNotUnwrapped):
                    handlerWrapper = HandlerWrapper.GetHandlerWrapper((Action)AggregateExceptionNotUnwrapped);
                    bootstrap      = new LambdaBootstrap(handlerWrapper);
                    break;

                case nameof(TooLargeResponseBodyAsync):
                    bootstrap = new LambdaBootstrap(TooLargeResponseBodyAsync);
                    break;

                case nameof(LambdaEnvironmentAsync):
                    bootstrap = new LambdaBootstrap(LambdaEnvironmentAsync);
                    break;

                case nameof(LambdaContextBasicAsync):
                    bootstrap = new LambdaBootstrap(LambdaContextBasicAsync);
                    break;

                case nameof(GetPidDllImportAsync):
                    bootstrap = new LambdaBootstrap(GetPidDllImportAsync);
                    break;

                case nameof(GetTimezoneNameAsync):
                    bootstrap = new LambdaBootstrap(GetTimezoneNameAsync);
                    break;

                default:
                    throw new Exception($"Handler {handler} is not supported.");
                }
                await bootstrap.RunAsync();
            }
            finally
            {
                handlerWrapper?.Dispose();
                bootstrap?.Dispose();
            }
        }