【问题标题】:serverless rest api gateway nodejs无服务器rest api网关nodejs
【发布时间】:2016-10-10 21:11:04
【问题描述】:

嘿,我怎样才能获得参数数据?

// this is serverless.yml
test_function:
    handler: handler.test
    events:
    - http:
        path: "registry/{some_data}"
        method: get
        request:
          template:
            application/json: >
              {
                "damn": "$input.params('some_data')"
              }

// this is handle.js
module.exports.test= (event, context, cb) => {
  cb(null, { bangke: 'Dorrrrr !!'+event.some_data});
};

但是 event.some_data 打印 undefine 有人知道代码有什么问题吗?

【问题讨论】:

    标签: amazon-web-services aws-lambda serverless-framework


    【解决方案1】:

    如果我理解正确,您正在尝试传递路径参数。在这种情况下,请使用以下内容:

    serverless.yml:

    test_function:
      handler: handler.test
      events:
        - http:
            path: registry/{some_data}
            method: get
    

    handler.js:

    module.exports.test= (event, context, cb) => {
      cb(null, { bangke: 'Dorrrrr !!'+ event.path.some_data});
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-08
      • 2021-01-03
      • 1970-01-01
      • 2021-01-29
      • 1970-01-01
      • 2018-01-23
      • 2015-01-31
      相关资源
      最近更新 更多