使用Google Cloud Functions的无服务器包装器

时间:2018-06-08 14:46:44

标签: google-cloud-functions serverless-framework serverless

我正在尝试使用无服务器和谷歌云功能编写自定义包装器。

const serverless = new Serverless({
    interactive: false,
    servicePath: "/Users/user/work/faas-artillery"
  })

  var options = {
    function: 'my-function',
    stage: 'my-stage',
    region: 'my-region'

  };
  //console.log(options)
  // Set the serverless artillery to use Google. 
  // This constructor then adds Google plugins to the serverless framework
  var googleIndex = new GoogleIndex(serverless, options);
  serverless.init();

  // Now find the GoogleInvoke by constructor name within the serverless 
  const invoke = serverless.pluginManager.plugins.find(
    plugin => Object.getPrototypeOf(plugin).constructor.name === 'GoogleInvoke' 
  )
  serverless.run()

在执行上述命令时,我收到未找到的调用命令。有没有办法为无服务器分配CLI选项。

1 个答案:

答案 0 :(得分:0)

使用serverless.init()方法存在一个promise,我们必须等待它完成。

 let googleInvoke;
  let SLS_DEBUG
  SLS_DEBUG = process.env.SLS_DEBUG
  process.env.SLS_DEBUG = '*'
  // pretend that SLS was called.
  process.argv[1] = Serverless.dirname
  const serverless = new Serverless({
    interactive: false,
    servicePath: "/Users/user/work/faas-artillery"
  })

  var options = {
    function: 'my-function',
    stage: 'my-stage',
    region: 'my-region'

  };
  //console.log(options)
  // Set the serverless artillery to use Google. 
  // This constructor then adds Google plugins to the serverless framework
  var googleIndex = new GoogleIndex(serverless, options);
  serverless.init().then(() => {
    // Now find the GoogleInvoke by constructor name within the serverless 
    const invoke = serverless.pluginManager.plugins.find(
      plugin => Object.getPrototypeOf(plugin).constructor.name === 'GoogleInvoke' 
    )
  }).then(() => {
    serverless.run()
  });