using System.Net;
using Amazon.Lambda.Core;
using Amazon.Lambda.APIGatewayEvents;
using AWS.Lambda.Powertools.Logging;
using AWS.Lambda.Powertools.Metrics;
using AWS.Lambda.Powertools.Tracing;
// 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 BlueprintBaseName._1;
///
/// Learn more about Powertools for AWS Lambda (.NET) at https://awslabs.github.io/aws-lambda-powertools-dotnet/
/// Powertools for AWS Lambda (.NET) Logging: https://awslabs.github.io/aws-lambda-powertools-dotnet/core/logging/
/// Powertools for AWS Lambda (.NET) Tracing: https://awslabs.github.io/aws-lambda-powertools-dotnet/core/tracing/
/// Powertools for AWS Lambda (.NET) Metrics: https://awslabs.github.io/aws-lambda-powertools-dotnet/core/metrics/
///
public class Functions
{
///
/// A Lambda function to respond to HTTP Get methods from API Gateway
///
///
/// The API Gateway response.
[Logging(LogEvent = true, CorrelationIdPath = CorrelationIdPaths.ApiGatewayRest)]
[Metrics(CaptureColdStart = true)]
[Tracing(CaptureMode = TracingCaptureMode.ResponseAndError)]
public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context)
{
Logger.LogInformation("Get Request");
var greeting = GetGreeting();
var response = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.OK,
Body = greeting,
Headers = new Dictionary { { "Content-Type", "text/plain" } }
};
return response;
}
[Tracing(SegmentName = "GetGreeting Method")]
private static string GetGreeting()
{
Metrics.AddMetric("GetGreeting_Invocations", 1, MetricUnit.Count);
return "Hello Powertools for AWS Lambda (.NET)";
}
}