/// <summary> /// Asynchronous Lambda Entry Point /// </summary> /// <param name="jsonInput">json input from AWS</param> /// <param name="context">contextual information from AWS</param> public async Task ExecuteAsync(JToken jsonInput, ILambdaContext context) { await ExecuteWithScope(context, jsonInput, async (cancellationToken) => { var handlerType = LambdaHandler.GetType(); var method = handlerType.GetMethod(nameof(IAsyncLambdaHandler <object> .HandleAsync)); var inputType = handlerType.GetInterface($"{nameof(IAsyncLambdaHandler<object>)}`1") .GenericTypeArguments.Single(); await(Task) method.Invoke(LambdaHandler, new object[] { jsonInput.ToObject(inputType), context, cancellationToken }); return(new LambdaResponse <int>(System.Net.HttpStatusCode.OK, null, 0, false, false)); }); }
/// <summary> /// Synchronous Lambda Entry Point /// </summary> /// <param name="jsonInput">json input from AWS</param> /// <param name="context">contextual information from AWS</param> /// <returns>HTTP style response message with payload</returns> public async Task <object> ExecuteAsync(JToken jsonInput, ILambdaContext context) { var result = await ExecuteWithScope(context, jsonInput, async (cancellationToken) => { var handlerType = LambdaHandler.GetType(); var method = handlerType.GetMethod(nameof(ISyncLambdaHandler <object, object> .HandleAsync)); var interfaceType = handlerType.GetInterface($"{nameof(ISyncLambdaHandler<object, object>)}`2"); var inputType = interfaceType.GenericTypeArguments.First(); var outputType = interfaceType.GenericTypeArguments.Last(); var task = (Task)method.Invoke(LambdaHandler, new object[] { jsonInput.ToObject(inputType), context, cancellationToken }); await task; return((ILambdaResponse)task .GetType() .GetProperty(nameof(Task <ILambdaResponse> .Result)) .GetValue(task)); }); return(PrepareResult(result)); }