0
votes

How do I refer to API Gateway GET query string parameters in a Lambda function ?

When I test I can use my local test event with "username": "larry"
When I test with a post I can use the body parameters as the event with "username": "larry"
With a get request, I don't have a body. How could I use query string parameters and then refer to them in the request. What event or other attribute do I use to get at the query param or what setting or change do I need to make?

Method request

enter image description here

Integration request

enter image description here

Query String

enter image description here

When testing I've referred to event["username", what do I do for an API request passing it as a query string parameter?

1
If I understand your question, the event object passed into the Lambda has queryStringParameters and pathParameters. So, event.queryStringParameters.username (if you were using JavaScript, though you didn't indicate a language).jarmod

1 Answers

0
votes

Login and click to API gateway and click on method - GET method

Go to Method Execution - select URL Query String Parameter and add query String parameter username

Now go to Integration Request tab Choose Body Mapping Template,

        "content type application/json"

Generate Template like below

{
"username":  "$input.params('username')"
}

Now write ;ambda which accept key value in pair .

module.exports.get = (event, context, callback) => {
  const { username } = event.pathParameters;
  console.log("username", username); 
}

Now go and deploy your api on apigetway and find url and hit in browser example

          https://xxx.yyy-api.us-east-2.amazonaws.com/prod/username?vaquarkhan

Hope it will help