Search code examples
amazon-web-servicesaws-lambda

queryStringParameters Not working to fetch GET response


I'm using AWS Lambda, and using the function URL directly - no API gateway.

9/10 times when I run my query with my GET request, it fails. But if I keep sending it repeatedly by refreshing, occasionally it accepts it.

When it fails, it believes my GET request is empty:

{
    "timestamp": "2024-07-03T02:01:32.577Z",
    "level": "ERROR",
    "requestId": "3b3aecb0-5b32-49fe-883f-264459bcd19f",
    "message": "empty GET again"
}

Here is a portion of my relevant code, up to the point where it logs the error:

export const handler = async (event:APIGatewayProxyEventV2):Promise<APIGatewayProxyStructuredResultV2> => {

    const req = event['queryStringParameters']
    var question
    question =  req['q']
    if(!question){
        console.error('empty GET again')
        return {statusCode:400}
    }
...

What can be causing this? I'm actually noticing this behavior gets more frequent when the GET request is longer (no more than 100 chars). When its really short (like 30 chars), it accepts it MOST of the time.

I don't understand how this is so unreliable.


Solution

  • I fixed the problem. As it turns out, I had to increase the lambda max execution time to something higher than the default, 3 seconds.

    If you have GET or POST parameters in your Lambda function and it exceeds the execution time threshold - AWS thinks its more useful to handle the logging as if these parameters don't exist, triggering the first error that depends on them.