Reputation: 310
I have multiple GET parameters so how should i pass in lambda function and how would my serverless.yml look like.Currently below is the configuration
serverless.yml
myFunc:
handler: com.mcm.in.MyHandler
events:
- http:
path: user
method: get
cors: true
Request:/mylist?page=1&size=10&filter=userId=abc&sort=-userId&version=1554304254262
Also how should i call in sls invoke local?
I have tried without the params,It's not working in serverless
Upvotes: 2
Views: 1624
Reputation: 519
I have created the request template this way for passing multiple parameters in URL
template:
application/json: '{ "userid":"$input.params(''userid'')","activityid":"$input.params(''activityid'')"}'
Here is the full code
functions:
hello:
handler: handler.hello
events:
- http:
path: /
method: get
likes:
handler: handler.likes
events:
- http:
path: /likes
method: get
integration: lambda
reqValidatorName: xMyRequestValidator
request:
passThrough: NEVER
parameters:
querystrings:
userid: true
activityid:true
template:
application/json: '{ "userid":"$input.params(''userid'')","activityid":"$input.params(''activityid'')"}'
response:
headers:
Content-Type: "'application/json'"
Upvotes: 1
Reputation: 3097
You can create a request template that will map your request contents using the parameters, as noted in the documentation. Your function will look something like this (if you want to take in the page
parameter for example:
myFunc:
handler: com.mcm.in.MyHandler
events:
- http:
path: user
method: get
cors: true
integration: lambda
request:
template:
application/json: '{ "page" : "$input.params(''page'')" }'
Upvotes: 2