Reputation: 8784
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:
GET
)Integration Request
Body Mapping Templates
application/json
{"name": "$input.params('name')" }
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.
Upvotes: 2
Views: 574
Reputation: 1058
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);
}
Upvotes: 3
Reputation: 8541
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')"
}
Upvotes: 2