private async Task <string> InvokeAsync(LambdaBootstrap bootstrap, string dataIn, TestRuntimeApiClient testRuntimeApiClient) { testRuntimeApiClient.FunctionInput = dataIn != null?Encoding.UTF8.GetBytes(dataIn) : new byte[0]; using (var cancellationTokenSource = new CancellationTokenSource()) { var exceptionWaiterTask = Task.Run(async() => { _output.WriteLine($"Waiting for an output."); while (testRuntimeApiClient.LastOutputStream == null) { } _output.WriteLine($"Output available."); cancellationTokenSource.Cancel(); using (var reader = new StreamReader(testRuntimeApiClient.LastOutputStream)) { return(await reader.ReadToEndAsync()); } }); await bootstrap.RunAsync(cancellationTokenSource.Token); return(await exceptionWaiterTask); } }
private static async Task Main(string[] args) { // Inicializa la configuración de la app. Configuration = ConfigurationBuilder(Environment.GetEnvironmentVariable("ENVIRONMENT")).Build(); // envVariables = Configuration.GetSection("environmentDM").Get<EnvVariables>(); GetVariablesEntorno(); // Configura la colección de servicios para la app. var services = ConfigureServices(Configuration); // Genera un proveedor para iniciar el servicio AWSService. var serviceProvider = services.BuildServiceProvider(); // Inicia el Proceso. initial = serviceProvider.GetService <IIniciaProceso>(); Func <S3Event, ILambdaContext, string> func = FunctionHandler; // Para debuguear como app de consola: // - Descomentar la región DEBUG. // - Comentar la región AWS_LAMBDA. // #region DEBUG // var context = new TestLambdaContext(); // var s3_event = JsonConvert.DeserializeObject<S3Event>(await File.ReadAllTextAsync("event.json")); // var upperCase = Program.FunctionHandler(s3_event, context); //#endregion //FIXME Descomentar para que funcione como lambda. using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new Amazon.Lambda.Serialization.Json.JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
//--- Class Methods --- public static async Task Main(string[] args) { // NOTE: this method is the entry point for Lambda functions with a custom runtime using var handlerWrapper = HandlerWrapper.GetHandlerWrapper(new Function().FunctionHandlerAsync); using var bootstrap = new LambdaBootstrap(handlerWrapper); await bootstrap.RunAsync(); }
private static async Task Main(string[] args) { Func <string, ILambdaContext, string> func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) { using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { try { await bootstrap.RunAsync(); } catch (Exception ex) { Console.WriteLine("An exception occured with message below:"); Console.WriteLine("----------------------------------------"); Console.WriteLine(ex.Message); Console.WriteLine("Stack Trace:"); Console.WriteLine("------------"); Console.WriteLine(ex.StackTrace); if (ex.InnerException != null) { Console.WriteLine("Inner Exception:"); Console.WriteLine("---------------"); Console.WriteLine(ex.InnerException.Message); } } } } }
public static void Main(string[] args) { // AWS Lambda will call the "bootstrap" shell script, which // will pass the string "lambda" as an argument if (args.Length > 0 && args[0] == "lambda") { var lambdaEntryPoint = new LambdaEntryPoint(); // This explicit cast is needed with slightly older C# versions var lambdaFunctionHandler = (Func <APIGatewayProxyRequest, Amazon.Lambda.Core.ILambdaContext, Task <APIGatewayProxyResponse> >)lambdaEntryPoint.FunctionHandlerAsync; var handlerWrapper = HandlerWrapper.GetHandlerWrapper <APIGatewayProxyRequest, APIGatewayProxyResponse>(lambdaFunctionHandler, new JsonSerializer()); using (handlerWrapper) { using (var lambdaBootstrap = new LambdaBootstrap(handlerWrapper)) { lambdaBootstrap.RunAsync().GetAwaiter().GetResult(); } } } // Otherwise, it gets called like most ASP.NET Core web apps else { CreateWebHostBuilder(args).Build().Run(); } }
internal static async Task RunAsync(HttpClient httpClient, CancellationToken cancellationToken) { var handler = new CustomHandler(); using var bootstrap = new LambdaBootstrap(httpClient, handler.InvokeAsync); await bootstrap.RunAsync(cancellationToken); }
public static async Task Main() { Func <string, ILambdaContext, Task> func = FunctionHandler; using var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new DefaultLambdaJsonSerializer()); using var bootstrap = new LambdaBootstrap(handlerWrapper); await bootstrap.RunAsync(); }
/// <summary> /// The main entry point for the custom runtime. /// </summary> /// <param name="args"></param> private static async Task Main(string[] args) { Func <string, ILambdaContext, string> func = FunctionHandler; using var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer()); using var bootstrap = new LambdaBootstrap(handlerWrapper); await bootstrap.RunAsync(); }
public async Task InitializerReturnsFalse() { using (var bootstrap = new LambdaBootstrap(_testFunction.BaseHandlerAsync, _testInitializer.InitializeFalseAsync)) { await bootstrap.RunAsync(); } Assert.True(_testInitializer.InitializerWasCalled); Assert.False(_testFunction.HandlerWasCalled); }
public static async Task RunAsync(HttpClient?httpClient = null, CancellationToken cancellationToken = default) { var serializer = new JsonSerializer(); using var handlerWrapper = HandlerWrapper.GetHandlerWrapper <MathsRequest, MathsResponse>(Evaluate, serializer); using var bootstrap = new LambdaBootstrap(httpClient ?? new HttpClient(), handlerWrapper); await bootstrap.RunAsync(cancellationToken); }
/// <summary> /// The main entry point for the custom runtime. /// </summary> /// <param name="args"></param> internal static async Task Main(string[] args) { var function = new Function(); Func <string, ILambdaContext, Task <string> > func = function.FunctionHandler; using var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer()); using var bootstrap = new LambdaBootstrap(handlerWrapper); await bootstrap.RunAsync(); }
/// <summary> /// Start Amazon.Lambda.RuntimeSupport to listen for Lambda events to be processed. /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="application"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public override Task StartAsync <TContext>(IHttpApplication <TContext> application, CancellationToken cancellationToken) { base.StartAsync(application, cancellationToken); var handlerWrapper = CreateHandlerWrapper(_serviceProvider); var bootStrap = new LambdaBootstrap(handlerWrapper); return(bootStrap.RunAsync()); }
/// <summary> /// The main entry point for the custom runtime. /// </summary> /// <param name="args"></param> private static async Task Main(string[] args) { Func <Newtonsoft.Json.Linq.JObject, ILambdaContext, string> func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
/// <summary> /// The main entry point for the custom runtime. /// </summary> /// <param name="args"></param> private static async Task Main(string[] args) { Func <CloudWatchLogsEvent, Task> func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
private static async Task Main(string[] args) { Func <APIGatewayProxyRequest, ILambdaContext, APIGatewayProxyResponse> func = Handler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, JsonSerializer)) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
public async Task RunAsync() { Func <TInput, ILambdaContext, Task <TOutput> > func = _handler.HandleAsync; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
private static async Task Main(string[] args) { Action <FunctionInput, ILambdaContext> func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
/// <summary> /// The main entry point for the custom runtime. /// </summary> /// <param name="args"></param> private static async Task Main(string[] args) { Func <ApplicationLoadBalancerRequest, ILambdaContext, ApplicationLoadBalancerResponse> func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new Amazon.Lambda.Serialization.Json.JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
/// <summary> /// Follows the standard pattern for a ASP.NET-based Lambda fed from an API Gateway. /// See: https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.APIGatewayEvents /// </summary> public static void TriggerFromApiGateway() { var lambdaEntry = new ApiGatewayLambdaFunction(); var functionHandler = (Func <APIGatewayProxyRequest, ILambdaContext, Task <APIGatewayProxyResponse> >)(lambdaEntry.FunctionHandlerAsync); using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(functionHandler, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { bootstrap.RunAsync().Wait(); } }
private static async Task RunLambdaWebHost() { var lambda = new LambdaFunction(); Func <APIGatewayProxyRequest, ILambdaContext, Task <APIGatewayProxyResponse> > handler = lambda.FunctionHandlerAsync; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(handler, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
public async Task InitializerReturnsTrueAndHandlerLoopRuns() { using (var bootstrap = new LambdaBootstrap(_testFunction.BaseHandlerAsync, _testInitializer.InitializeTrueAsync)) { bootstrap.Client = _testRuntimeApiClient; await bootstrap.RunAsync(_testFunction.CancellationSource.Token); } Assert.True(_testInitializer.InitializerWasCalled); Assert.True(_testFunction.HandlerWasCalled); }
/// <summary> /// Follows the standard pattern for a Lambda fed from a SQS. /// See: https://github.com/aws/aws-lambda-dotnet/tree/master/Libraries/src/Amazon.Lambda.SQSEvents /// </summary> public static void TriggerFromSqs() { var lambdaEntry = new SqsLambdaFunction(); Action <SQSEvent, ILambdaContext> func = lambdaEntry.FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { bootstrap.RunAsync().Wait(); } }
internal static async Task RunAsync <T>(HttpClient?httpClient, CancellationToken cancellationToken) where T : MyHandler, new() { var handler = new T(); var serializer = new JsonSerializer(); using var handlerWrapper = HandlerWrapper.GetHandlerWrapper <MyRequest, MyResponse>(handler.SumAsync, serializer); using var bootstrap = new LambdaBootstrap(httpClient, handlerWrapper, handler.InitializeAsync); await bootstrap.RunAsync(cancellationToken); }
public async Task NoInitializer() { _testFunction.CancellationSource.Cancel(); using (var bootstrap = new LambdaBootstrap(_testFunction.BaseHandlerAsync, null)) { bootstrap.Client = _testRuntimeApiClient; await bootstrap.RunAsync(_testFunction.CancellationSource.Token); } Assert.False(_testInitializer.InitializerWasCalled); Assert.False(_testFunction.HandlerWasCalled); }
private static async Task Main(string[] args) { Func <ILambdaContext, List <Member> > func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new JsonSerializer())) { using (var lambdaBootstrap = new LambdaBootstrap(handlerWrapper)) { await lambdaBootstrap.RunAsync(); } } }
/// <summary> /// Start Lambda. /// </summary> public async Task StartAsync() { // Wrap the FunctionHandler method in a form that LambdaBootstrap can work with. using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper((Func <string, ILambdaContext, string>)BaseHandler, new JsonSerializer())) { // Instantiate a LambdaBootstrap and run it. // It will wait for invocations from AWS Lambda and call // the handler function for each one. using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } } }
public static async Task RunAsync( HttpClient?httpClient = null, CancellationToken cancellationToken = default) { var serializer = new JsonSerializer(); #pragma warning disable CA2000 using var handlerWrapper = HandlerWrapper.GetHandlerWrapper <int[], int[]>(ReverseAsync, serializer); using var bootstrap = new LambdaBootstrap(httpClient ?? new HttpClient(), handlerWrapper); #pragma warning restore CA2000 await bootstrap.RunAsync(cancellationToken); }
public static async Task Main(string[] args) { //var function = HandlerWrapper.GetHandlerWrapper((Func<string, ILambdaContext, string>)UpperThingy, new JsonSerializer()); var function = HandlerWrapper.GetHandlerWrapper(FunctionHandler(), new JsonSerializer()); using (var handlerWrapper = function) { using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } } }
/// <summary> /// The main entry point for the custom runtime. /// </summary> /// <param name="args"></param> private static async Task Main(string[] args) { System.Console.WriteLine("In main"); _main++; Func <string, ILambdaContext, string> func = FunctionHandler; using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper(func, new DefaultLambdaJsonSerializer())) using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } }
public async Task RunLambda() { using (var handlerWrapper = HandlerWrapper.GetHandlerWrapper((Func <Argument, ILambdaContext, Task>)Run, new JsonSerializer())) { // Instantiate a LambdaBootstrap and run it. // It will wait for invocations from AWS Lambda and call // the handler function for each one. using (var bootstrap = new LambdaBootstrap(handlerWrapper)) { await bootstrap.RunAsync(); } } }