【问题标题】:Create a getMethod using serverless framework使用无服务器框架创建 getMethod
【发布时间】:2018-08-06 03:32:57
【问题描述】:

我使用无服务器框架。 我使用 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 控制台中手动设置了参数。 但等待正确的知识。 这样一来,是不是可以用 serverless 框架来消除手动输入呢? 反映API GateWay中参数的设置如果有人知道yml怎么写,请告诉我。

我想用 curl 轻松访问 API。

$ curl http://url.com/para?name=test&type=test

【问题讨论】:

    标签: amazon-web-services serverless-framework


    【解决方案1】:

    您需要添加正确的标识:

    functions:
      testfunc:
        handler: handler.func
        events:
          - http:
              path: testpath
              method: get
              request:
                querystrings:
                  name: true
                  type: true
                headers:
                  Accept: application/json
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-05
      • 2020-11-26
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2022-12-09
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多