无服务器框架/lambda

时间:2021-01-05 00:19:30

标签: sails.js serverless-framework

我目前正在尝试使用无服务器框架将我的 Sails.js 应用程序部署到 Lambda,但是在尝试访问我的应用程序索引时,Lambda 函数在提升 Sails.js 应用程序后超时;从不返回我非常简单的 json 响应。我已将测试超时增加到 14 秒。

11:00:05 am
START RequestId: 376d9d46-566e-45c6-bb04-58ebef3c50d7 Version: $LATEST
11:00:05 am
2021-01-05T00:00:05.240Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR (node:8) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
11:00:05 am
2021-01-05T00:00:05.295Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR debug: Since we are running with migrate: 'safe' and/or NODE_ENV=production (in the "development" Sails environment, to be precise), skipping the rest of the bootstrap to avoid data loss...
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info:
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: .-..-.
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info:
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: Sails <| .-..-.
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: v1.4.0 |\
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: /|.\
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: / || \
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: ,' |' \
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: .-'.-==|/_--'
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: `--'-------'
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: __---___--___---___--___---___--___
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: ____---___--___---___--___---___--___-__
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info:
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: Server lifted in `/var/task`
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: To shut down Sails, press <CTRL> + C at any time.
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO info: Read more at https://sailsjs.com/support.
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR debug: -------------------------------------------------------
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR debug: :: Tue Jan 05 2021 00:00:05 GMT+0000 (Coordinated Universal Time)
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 INFO
11:00:05 am
2021-01-05T00:00:05.302Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR debug: Environment : development
11:00:05 am
2021-01-05T00:00:05.303Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR debug: Port : 3000
11:00:05 am
2021-01-05T00:00:05.303Z 376d9d46-566e-45c6-bb04-58ebef3c50d7 ERROR debug: -------------------------------------------------------
11:00:19 am
END RequestId: 376d9d46-566e-45c6-bb04-58ebef3c50d7
11:00:19 am
REPORT RequestId: 376d9d46-566e-45c6-bb04-58ebef3c50d7 Duration: 14014.38 ms Billed Duration: 14000 ms Memory Size: 1024 MB Max Memory Used: 142 MB

serverless.yml

functions:
  app:
    handler: handler.app # reference the file and exported method
    events: # events trigger lambda functions
      - http: # this is an API Gateway HTTP event trigger
          path: /
          method: ANY
          cors: true

      - http: # all routes get proxied to the Express router
          path: /{proxy+}
          method: ANY
          cors: true
    timeout: 14

handler.js

const serverless = require('serverless-http');
var sails = require('sails').Sails;
var app = sails();

app.lift({
  port: 3000
});

// this is it!
module.exports.app = serverless(app);

索引操作(api/controllers/index.js)

module.exports = {

  friendlyName: 'Application index page',

  description: 'Return a simple JSON response as the applications index page',

  exits: {
    success: {
      responseType: 'json',
      description: 'Show a simple success message'
    },
  },

  fn: async function () {
    return this.res.json({
      'success': true,
      'http-code': 200
    });
  }
};

任何帮助都会很棒。我可以从 serverless-http 包中看到 Sails.js 是实验性的,但我认为它在某种程度上仍然可以工作。

0 个答案:

没有答案