Skip to content

dotnet 6 minimal api with api gateway - How do I get the APIGatewayProxyRequest ? #1292

Answered by normj
michaelakin asked this question in Q&A
Discussion options

You must be logged in to vote

If you are goal is to access the APIGatewayProxyRequest object you can access it from the HttpContext.Items collection. Here is an example.

app.MapGet("/test", ([FromQuery] string name, HttpContext context, [FromServices] ILogger<Program> logger) =>
{
    
    if(context.Items.TryGetValue(Amazon.Lambda.AspNetCoreServer.AbstractAspNetCoreFunction.LAMBDA_REQUEST_OBJECT, out var req))
    {
        var lambdaRequest = req as APIGatewayProxyRequest;
        logger.LogInformation($"Found lambda request: {lambdaRequest != null}");
    }
    else
    {
        logger.LogInformation("No lambda request found, probably running it locally outside of Lambda");
    }

    return name;
}).WithName("Tes…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@michaelakin
Comment options

@michaelakin
Comment options

@michaelakin
Comment options

@normj
Comment options

Answer selected by michaelakin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants