我使用无服务器框架。 我使用AWS API GateWay。 我想创建一个API,以便在终端上输入此命令并接收参数“ name”和参数“ type”。
$ mkdir test-serverless
$ cd test-serverless
$ sls create --template aws-nodejs --name test
$ vi serverless.yml
$cat serverless.yml
service:test
provider:
name: aws
runtime: nodejs6.10
region: ap-northeast-1
functions:
testfunc:
handler: handler.func
events:
- http:
path: testpath
method: get
request:
querystrings:
name: true
type: true
headers:
Accept: application/json
$ sls deploy -v
使用此命令,已成功创建API。 但是,没有设置任何参数。 结果,我在AWS控制台中手动设置了参数。 但是请等待正确的知识。 结果,使用无服务器框架是否有可能消除手工输入? 在API GateWay中反映参数的设置如果有人知道如何编写yml,请告诉我。
我想轻松地使用curl来访问API。
$ curl http://url.com/para?name=test&type=test
答案 0 :(得分:0)
您需要添加正确的标识:
functions:
testfunc:
handler: handler.func
events:
- http:
path: testpath
method: get
request:
querystrings:
name: true
type: true
headers:
Accept: application/json