using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Amazon.Lambda.Core;
using Amazon.Lambda.APIGatewayEvents;
using System.Text.Json;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]
namespace SimpleLambdaContainerForRIE
{
public class Functions
{
///
/// Default constructor that Lambda will invoke.
///
public Functions()
{
}
///
/// A Lambda function to respond to HTTP Get methods from API Gateway
///
///
/// The API Gateway response.
public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context)
{
context.Logger.LogInformation("Get Request\n");
Console.WriteLine($"Id = {request.PathParameters["Id"]}");
Console.WriteLine($"request: {JsonSerializer.Serialize(request)}");
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
//Body = $"You were looking for something with an Id of : {request.PathParameters["id"]}",
Body = $"{JsonSerializer.Serialize(request)}",
Headers = new Dictionary { { "Content-Type", "application/json" } }
};
return response;
}
///
/// A Lambda function to respond to HTTP Get methods from API Gateway
///
///
/// The API Gateway response.
public APIGatewayProxyResponse Post(APIGatewayProxyRequest request, ILambdaContext context)
{
context.Logger.LogInformation("Post Request\n");
Person p = JsonSerializer.Deserialize(request.Body);
Console.WriteLine($"The person is {p}");
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.Created,
//Body = $"You sent a new person - {p} ",
Body = $"{JsonSerializer.Serialize(request)}",
Headers = new Dictionary { { "Content-Type", "application/json" } }
};
return response;
}
}
}