Query String Parameters with Lambda function URL

0

I have a Lambda function with URL and I am trying to POST some parameters to it with curl:

curl -d "item=one"  htpps://<lambda-url>

The queryStringParameters field of event is empty. Here's the function:

import json

def lambda_handler(event, context):
    if "queryStringParameters" in event:
        return
        {
        'statusCode': 200,
        'body': json.dumps(event["queryStringParameters"])
    }
    return {
        'statusCode': 200,
        'headers': {
            'Content-Type': 'text/html'
        },
        'body': 'Empty'
    }

The output of curl is null. I inspected the event object and the parameters do not appear anywhere in it.

What am I doing wrong and how can I pass query string parameters, such as a form from a website, to a URL Lambda using POST?

Romanko
asked 11 days ago26 views
2 Answers
0

-d is used to sent a payload, not query parameters.

What you need to do is: curl https://<lambda-url>/item=one

profile picture
EXPERT
Uri
answered 11 days ago
  • Hi Uri, Thank you for the reply. I tried: curl -X POST https://<lambda-id>.lambda-url.ap-southeast-2.on.aws/?item=two The result is null as well. This beats me. I created a test event:

    {"queryStringParameters":
    {
      "key1": "value1",
      "key2": "value2",
      "key3": "value3"
    }
    }
    

    I also added a print statement to the Lambda function:

    import json
    
    
    def lambda_handler(event, context):
        if "queryStringParameters" in event:
            print(event["queryStringParameters"])
            return
            {
            'statusCode': 200,
            'body': json.dumps(event["queryStringParameters"])
        }
        return {
            'statusCode': 200,
            'headers': {
                'Content-Type': 'text/html'
            },
            'body': 'Empty'
        }
    

    The execution results are:

    Test Event Name
    query-string-params
    
    Response
    null
    
    Function Logs
    START RequestId: 524dfae5-72de-4170-99bd-bc7bbcb18edf Version: $LATEST
    {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
    ...
    

    Any further help would be much appreciated.

0

Anwering my own question.

    return {
             'statusCode': 200}

and

     return
       { 
           `statusCode`: 200 }

are not equivalent. The first returns the object, while the second returns None (which somehow becomes null). I miss FORTRAN. Any plans of adding it to Lamdba runtimes?

Romanko
answered 11 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions