通过无服务器AWS发布部署错误

时间:2019-04-10 17:57:43

标签: rest api

当我收到内部服务器错误时,在通过AWS lamda进行sls部署时,部署警告无法获得响应

Warning: handler 'getAll' returned a promise and also uses a callback!
This is problematic and might cause issues in your lambda

handler.js using serverless to deploy the rest-api

module.exports.getAll = async(event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = false;

  connectToDatabase()
    .then(() => {
      Restaurant.find()
        .then(Restaurants => callback(null, {
          statusCode: 200,
          body: JSON.stringify(Restaurants)
        }))
        .catch(err => callback(null, {
          statusCode: err.statusCode || 500,
          headers: { 'Content-Type': 'text/plain' },
          body: 'Could not fetch the Restaurants.'
        }))
    });
};

Serverless: Routes for getAll:
Serverless: GET /restaurant

Serverless: Routes for update:
Serverless: PUT /restaurant/{id}

Serverless: Routes for delete:
Serverless: DELETE /restaurant/{id}

Serverless: Routes for hello:
Serverless: GET /hello

Serverless: Offline listening on http://localhost:3000

Serverless: GET /restaurant (λ: getAll)
=> using new database connection

Serverless: Warning: handler 'getAll' returned a promise and also uses a callback!
This is problematic and might cause issues in your lambda.

Serverless: Warning: context.done called twice within handler 'getAll'!

Serverless: GET /restaurant (λ: getAll)
Serverless: Error while loading getAll

0 个答案:

没有答案