{"id":19589767,"url":"https://github.com/supercharge/hapi-aws-lambda","last_synced_at":"2025-04-27T12:33:03.978Z","repository":{"id":57163614,"uuid":"227382437","full_name":"supercharge/hapi-aws-lambda","owner":"supercharge","description":"Serverless functions on AWS Lambda with hapi.js","archived":false,"fork":false,"pushed_at":"2022-07-16T10:12:20.000Z","size":116,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-18T15:32:04.024Z","etag":null,"topics":["aws-lambda","hapi","hapijs","nodejs","serverless","supercharge"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/supercharge.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-12-11T14:16:29.000Z","updated_at":"2024-02-21T19:35:08.000Z","dependencies_parsed_at":"2022-08-23T03:31:13.566Z","dependency_job_id":null,"html_url":"https://github.com/supercharge/hapi-aws-lambda","commit_stats":null,"previous_names":["superchargejs/hapi-aws-lambda"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fhapi-aws-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fhapi-aws-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fhapi-aws-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/supercharge%2Fhapi-aws-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/supercharge","download_url":"https://codeload.github.com/supercharge/hapi-aws-lambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251138934,"owners_count":21541976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","hapi","hapijs","nodejs","serverless","supercharge"],"created_at":"2024-11-11T08:20:42.816Z","updated_at":"2025-04-27T12:33:03.235Z","avatar_url":"https://github.com/supercharge.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\r\n  \u003ca href=\"https://superchargejs.com\"\u003e\r\n    \u003cimg width=\"471\" style=\"max-width:100%;\" src=\"https://superchargejs.com/images/supercharge-text.svg\" /\u003e\r\n  \u003c/a\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ch3\u003ehapi on AWS Lambda\u003c/h3\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    Run your hapi server on AWS Lambda.\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003eInstallation\u003c/strong\u003e\u003c/a\u003e ·\r\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cbr/\u003e\r\n  \u003cbr/\u003e\r\n  \u003cp\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/@supercharge/hapi-aws-lambda\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@supercharge/hapi-aws-lambda.svg\" alt=\"Latest Version\"\u003e\u003c/a\u003e\r\n    \u003ca href=\"https://www.npmjs.com/package/@supercharge/hapi-aws-lambda\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/@supercharge/hapi-aws-lambda.svg\" alt=\"Monthly downloads\"\u003e\u003c/a\u003e\r\n  \u003c/p\u003e\r\n  \u003cp\u003e\r\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e and \u003ca href=\"http://twitter.com/superchargejs\"\u003e@superchargejs\u003c/a\u003e for updates!\u003c/em\u003e\r\n  \u003c/p\u003e\r\n\u003c/div\u003e\r\n\r\n---\r\n\r\n## Introduction\r\nServerless is becoming popular and widely accepted in the developer community. Going serverless requires a mindset shift. Going serverless requires you to think stateless.\r\n\r\nThis `@supercharge/hapi-aws-lambda` package let’s you use your [hapi.js](https://hapi.dev) HTTP server on AWS Lambda.\r\n\r\nThis package wraps your hapi server and transforms an incoming API Gateway event into an HTTP request. The request will be injected into your hapi server and the resulting response transformed *back* into an API-Gateway-compatible format.\r\n\r\nIt’s basically a “done for you” package to run your hapi server in a serverless function AWS Lambda.\r\n\r\n\r\n## Requirements\r\n\u003e **hapi v19 (or later)** and **Node.js v12 (or newer)**\r\n\r\nThis plugin requires **hapi v19** (or later) and **Node.js v12 or newer**.\r\n\r\n\r\n### Compatibility\r\n| Major Release | [hapi.js](https://github.com/hapijs/hapi) version | Node.js version |\r\n| --- | --- | --- |\r\n| `v2` | `\u003e=19 @hapi/hapi` | `\u003e=12` |\r\n| `v1` | `\u003e=18 hapi` | `\u003e=8` |\r\n\r\n\r\n## Installation\r\n\r\n```\r\nnpm i @supercharge/hapi-aws-lambda\r\n```\r\n\r\n\r\n## Usage\r\nUsing `@supercharge/hapi-aws-lambda` is a two-step process:\r\n\r\n1. [Implement the function’s entrypoint](#the-lambda-function)\r\n2. [Configure Binary Media Types for your API Gateway](#configure-binary-media-types)\r\n\r\n\r\n### The Lambda Function\r\nUsing `@supercharge/hapi-aws-lambda` is pretty straightforward:\r\n\r\n```js\r\n'use strict'\r\n\r\nconst Hapi = require('@hapi/hapi')\r\nconst LambdaHandler = require('@supercharge/hapi-aws-lambda')\r\n\r\n// this `handler` will be used as a cached instance\r\n// a warm Lambda function will reuse the handler for incoming events\r\nlet handler\r\n\r\nmodule.exports.handler = async event =\u003e {\r\n  if (!handler) {\r\n     // First, compose your hapi server with all the plugins and dependencies\r\n    server = new Hapi.Server()\r\n\r\n    await server.register({\r\n      plugin: require('@hapi/vision')\r\n    })\r\n\r\n    // Second, create a handler instance for your server which will\r\n    // transform the Lambda/API Gateway event to a request, send\r\n    // the request through your hapi server and then create\r\n    // an API Gateay compatible response\r\n    handler = LambdaHandler.for(server)\r\n  }\r\n\r\n  return handler.proxy(event)\r\n}\r\n```\r\n\r\n\r\n### Configure Binary Media Types\r\nServing images from an HTTP server running in a Lambda function won’t work out of the box. When neccessary, `@supercharge/hapi-aws-lambda` Base64-encodes the response data so that AWS API Gateway can handle the response body.\r\n\r\nYou need to explicitely configure binary media types in your the API Gateway that is responsible for your Lambda function. Here’s a screenshot of the `*/*` configuration we use:\r\n\r\n![AWS API Gateway: Binary Media Types configuration](https://github.com/superchargejs/hapi-aws-lambda/blob/master/media/hapi-aws-api-gateway-binary-media-types.png?raw=1)\r\n\r\n\r\n## Deployment Example\r\nThere’s a deployment example in the [superchargejs/playground-aws-lambda](https://github.com/superchargejs/playground-aws-lambda) repository.\r\n\r\nWe used the [Serverless](https://serverless.com/cli/) framework to deploy the Supercharge app in the `playground-aws-lambda` repository. The Serverless CLI is sweet. Here’s the sample `serverless.yml` used to deploy the app:\r\n\r\n```yaml\r\nservice: supercharge-aws-lambda\r\n\r\nprovider:\r\n  name: aws\r\n  runtime: nodejs12.x\r\n  region: eu-central-1\r\n\r\nfunctions:\r\n  app:\r\n    handler: server.handler\r\n    memorySize: 384 # default is 1024 MB\r\n    events:\r\n      - http: ANY /\r\n      - http: 'ANY {proxy+}'\r\n\r\nplugins:\r\n  - serverless-offline\r\n\r\ncustom:\r\n  serverless-offline:\r\n    noStripTrailingSlashInUrl: true\r\n\r\n```\r\n\r\n\r\n## Contributing\r\nDo you miss a string function? We very much appreciate your contribution! Please send in a pull request 😊\r\n\r\n1.  Create a fork\r\n2.  Create your feature branch: `git checkout -b my-feature`\r\n3.  Commit your changes: `git commit -am 'Add some feature'`\r\n4.  Push to the branch: `git push origin my-new-feature`\r\n5.  Submit a pull request 🚀\r\n\r\n\r\n## License\r\nMIT © [Supercharge](https://superchargejs.com)\r\n\r\n---\r\n\r\n\u003e [superchargejs.com](https://superchargejs.com) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e GitHub [@supercharge](https://github.com/supercharge) \u0026nbsp;\u0026middot;\u0026nbsp;\r\n\u003e Twitter [@superchargejs](https://twitter.com/superchargejs)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fhapi-aws-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsupercharge%2Fhapi-aws-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsupercharge%2Fhapi-aws-lambda/lists"}