4

I have recently started learning AWS and created a basic Node based lambda as below:

exports.handler = async (event, context, callback) => {

    // TODO implement
    const response = {
        statusCode: 200,
        body: JSON.stringify([event, context, 'Hello from Saurabh Tiwari']),
    };
    return response;
};

I have configured the API gateway method request to expect a name query parameter as shown below: enter image description here

I have also assigned a request validator to the GET call for the API. Having done this the endpoint asks me to necessarily provide a query parameter.

The issue however is that I am unable to receive the query parameter in the lambda function. I expect it to be passed along the event parameter. However the event parameter (first parameter in the JSON body) is blank as can be seen in the response object below.

Please suggest how do I retrieve the query param in the lambda.

enter image description here

6
  • try event.queryStringParameters[name]. I think you have to done some configuration wrong thats why APIGateway event which is supposed to be passed as a param is an empty object. Commented Aug 18, 2019 at 7:51
  • @vibhor1997a As expected, doing above resulted in {"errorType":"TypeError","errorMessage":"Cannot read property 'name' of undefined","trace":["TypeError: Cannot read property 'name' of undefined"," at Runtime.exports.handler (/var/task/index.js:6:58)"," at Runtime.handleOnce (/var/runtime/Runtime.js:63:25)"," at process._tickCallback (internal/process/next_tick.js:68:7)"]}. The entire event object is blank for whatever reason. Commented Aug 18, 2019 at 7:56
  • Have you configured the integration request and set the lambda proxy integration? Commented Aug 18, 2019 at 8:04
  • I think not. As I am very new to this, Can you may be suggest how to do the same ? Commented Aug 18, 2019 at 8:14
  • You can first click on the GET as you can see in your screenshot. There you would find integration request. Click on it then you would see some options including a checkbox lambda proxy integration. Check the checkbox and save. I would recommend you to use a framework like serverless framework as they make config easier. Commented Aug 18, 2019 at 8:20

1 Answer 1

5

You have to enable ‘Lambda Proxy Integration’ under Request Integration tab. Then you can access the query string object as event.queryStringParameters.name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.