我有多个GET参数,因此我应该如何传递lambda函数以及我的serverless.yml看起来如何。当前下面是配置
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
我还应该如何在sls中调用本地调用?
我尝试了没有参数的情况,它无法在无服务器环境中工作
答案 0 :(得分:2)
您可以创建一个请求模板,该模板将使用参数映射您的请求内容,如the documentation.中所述,您的函数将如下所示(例如,如果您想使用page
参数:
myFunc:
handler: com.mcm.in.MyHandler
events:
- http:
path: user
method: get
cors: true
integration: lambda
request:
template:
application/json: '{ "page" : "$input.params(''page'')" }'
答案 1 :(得分:1)
我已经以这种方式创建了请求模板,以便在URL中传递多个参数
template:
application/json: '{ "userid":"$input.params(''userid'')","activityid":"$input.params(''activityid'')"}'
这是完整的代码
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'"