public static async Task <bool> Invoke(ILogger log, Context context) { var args = new SimpleFunctionArgs { Name = "ProjectBaseName" }; log.Information("Invoking lambda with args: {@args}", args); var result = await LambdaInvoker.Invoke <SimpleFunctionArgs, SimpleFunctionResult>(log, context, args, Name(context.Config)); log.Information("Lambda result: {@result}", result); return(true); }
public async Task Test1() { ILambdaContext context = new TestLambdaContext(); IAmazonCloudWatch cloudwatch = Substitute.For <IAmazonCloudWatch>(); var function = new Function(cloudwatch); SimpleFunctionArgs args = new SimpleFunctionArgs { Name = "ProjectBaseName" }; SimpleFunctionResult result = await function.Handler(args, context); Assert.Equal("Hello, ProjectBaseName", result.Message); }
public async Task <SimpleFunctionResult> Handler(SimpleFunctionArgs args, ILambdaContext context) { using (LogContext.PushProperty("awsRequestId", context.AwsRequestId)) { try { log.Information("Processing request: Args: {@args}", args); var result = new SimpleFunctionResult { Message = "Hello, " + args.Name }; log.Information("Processed request. Result: {@result}", result); await CloudwatchMetrics.PutCountMetricAsync(log, cloudwatch, context.FunctionName, "Success", 1); return(result); } catch (Exception ex) { log.Error(ex, "Whoops"); await CloudwatchMetrics.PutCountMetricAsync(log, cloudwatch, context.FunctionName, "Errors", 1); throw; } } }