I am writing this because I could not find how to get the AWS Api Gateway stage variables of a dotnet 6 minimal rest api anywhere on the internet, so please see the below code snipett
app.MapGet("/test", ([FromQueryAttribute] string name, HttpRequest request) =>
{
Log.Information("Name {name}", name);
try
{
var req = (APIGatewayProxyRequest)request.HttpContext.Items.Where(i => i.Key == "LambdaRequestObject").Select(s => s.Value).FirstOrDefault();
if (req.StageVariables != null)
{
foreach (var stgVar in req.StageVariables)
{
Log.Information("stage v value: {key}, {value}", stgVar.Key, stgVar.Value);
}
}
else
{
Log.Information("stage v is null");
}
}
catch (Exception)
{
Log.Error("Error in request");
}
// after get the stage variable
//var r = RestService.For<IIpAddressApi>(stagevariableUrl);
return name;
}).WithName("Test");