예제 #1
0
 public LambdaOutput HelloHandler(LambdaInput input, ILambdaContext context)
 {
     context.Logger.Log($"Hello {input.Name}, you are now {input.Age}");
     return(new LambdaOutput {
         Name = input.Name, Old = input.Age > 50
     });
 }
예제 #2
0
        //Sample input to test the lambda function in isolation
        //{"QueryStringParameters": {"name":"Abel","age":"33"}}

        public APIGatewayProxyResponse HelloHandler(APIGatewayProxyRequest apigProxyEvent, ILambdaContext context)
        {
            // Some validation here as it will blow up
            // if query string params are not supplied !

            var input = new LambdaInput {
                Name = apigProxyEvent.QueryStringParameters["name"],
                Age  = Convert.ToInt32(apigProxyEvent.QueryStringParameters["age"])
            };

            context.Logger.LogLine($"Hello {input.Name}, you are now {input.Age}");

            var output = new LambdaOutput {
                Name = input.Name, Old = input.Age > 50
            };

            // Logic that used to be on the API integration response template
            var apiOutput = new { Message = $"Dear {output.Name}, you are {(output.Old ? "": "not ")}old." };

            return(new APIGatewayProxyResponse
            {
                Body = JsonSerializer.Serialize(apiOutput),
                StatusCode = 200,
                Headers = new Dictionary <string, string> {
                    { "Content-Type", "application/json" }
                }
            });
        }