2

I am wanting to pass a query parameter from API Gateway into AWS Lambda but I am always receiving null values.

Here's my Lambda function which I merely want to return the value of http://foo.bar?name=Dan

'use strict';

exports.handle = (context, event, callback) => {
  callback(null, event.name);
}

In API Gateway I have done the following:

  1. Create a Resource
  2. Create a Method (GET)
  3. Selected the correct Lambda function
  4. Selected my GET method and clicked on Integration Request
  5. Selected Body Mapping Templates
  6. Set Content-Type to application/json
  7. Added {"name": "$input.params('name')" }
  8. Save and deploy!

However, when I load up my API the value of event.name is always null. Accessing the API is done via ...amazonaws.com/beta/user?name=dan

Edit: I've tried the accepted answer here but after simply returning the event in the callback, I only receive this data:

{
  "callbackWaitsForEmptyEventLoop": true,
  "logGroupName": "",
  "logStreamName": "",
  "functionName": "",
  "memoryLimitInMB": "",
  "functionVersion": "",
  "invokeid": "",
  "awsRequestId": "",
  "invokedFunctionArn": ""
}

I have omitted the values.

Dan
  • 8,041
  • 8
  • 41
  • 72

2 Answers2

3

The function arguments' placement for context and event are misplaced. Change their placement as below

'use strict';

exports.handle = (event, context, callback) => {
   callback(null, event.name);
}
Popoi Menenet
  • 1,018
  • 9
  • 20
2

Even I had the same issue before and I have modified body mapping template like below. Please try it out.

#set($inputRoot = $input.path('$'))
{    
"name" : "$input.params('$.name')"
}

If you are using path parameter then please try below,

#set($inputRoot = $input.path('$'))
{
"name" : "$input.path('$.name')"
}
Vijayanath Viswanathan
  • 8,027
  • 3
  • 25
  • 43