3

I use API-Gateway to map rest requests to some Lambda functions. It works fine for post methods, where i send my information in the body as JSON and access it in the lambda like so

module.exports.handler = function(event, context, cb) {
   var email = event.email;
   var name = event.name;
}

Now i wanted to create a GET, with query strings. On the request side on API-Gateway its fine you can select the query string names, but for the life of me I cant figure out what to do on the Integration Request side. How do i get my query strings into my lambda so that i can access them like above. Or are they accessed differently.

I went through the docs, and still dont understand it. You would think this is like the most basic use case and they have an example, but no.

Please can somebody help me

Thanks

1
  • I agree, their API-Gateway documentation is incomplete Commented Jul 6, 2016 at 20:10

2 Answers 2

4

You have to create method request parameters for your query string parameters, then you need to create a mapping template to map your query string parameters to the integration request body.

The mapping template will be something like this,

{
    "email": "$input.params('email')",
    "name": "$input.params('name')"
}
Sign up to request clarification or add additional context in comments.

2 Comments

Do you know what's the proper way of calling this through a JS SDK? I've tried something along the lines of client.methodGet( {}, {email: email} ) but it is not passing the parameters for me.
SOLVED: In API Gateway, Resources, GET, Method Request, URL Query String Parameters, you also need to include the param you wish to pass.
0

In order to get query string parameters in AWS lambda, you'll need to map those parameters to attributes on the event object. Step 3 in this AWS Guide illustrates how to add them via the API Gateway console.

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.