简体   繁体   English

如何将 Hapi.js API 部署到 AWS Lambda 和 API 网关?

[英]how to deploy a Hapi.js API to AWS Lambda and API gateway?

I developed a hapi App using Node.js and i want to deploy it as a Lambda and will be accessible through API gateway.我使用 Node.js 开发了一个 hapi 应用程序,我想将它部署为 Lambda 并且可以通过 API 网关访问。 I did this multiple times but with express based application (mostly using claudia.js) and i couldn't find any documentations showing how to do this with hapi.我多次这样做,但使用基于 express 的应用程序(主要使用 claudia.js),我找不到任何文档显示如何使用 hapi 执行此操作。

Can anyone point me to the right direction of how to achieve this ?谁能指出我如何实现这一目标的正确方向? thanks in advance提前致谢

The hapi-lambda package worked for me. hapi-lambda包对我hapi-lambda

Ensure you serverless path to the handler is {proxy+} and use the following:确保处理程序的无服务器路径是 {proxy+} 并使用以下内容:

const api = require('./api');
const { transformRequest, transformResponse } = require('hapi-lambda');

exports.handler = async (event) => {
  const server = await api.init();

  const request = transformRequest(event);
  const response = await server.inject(request);
  return transformResponse(response);
};

Taken off the website of the package developer: https://www.carbonatethis.com/hosting-a-serverless-hapi-17-api-with-aws-lambda/从包开发者的网站上摘下: https : //www.carbonatethis.com/hosting-a-serverless-hapi-17-api-with-aws-lambda/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM