{"id":13599382,"url":"https://github.com/akrylysov/algnhsa","last_synced_at":"2025-04-04T09:09:54.920Z","repository":{"id":37617174,"uuid":"118056255","full_name":"akrylysov/algnhsa","owner":"akrylysov","description":"AWS Lambda Go net/http server adapter","archived":false,"fork":false,"pushed_at":"2023-12-29T14:06:21.000Z","size":46,"stargazers_count":376,"open_issues_count":7,"forks_count":40,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-10-10T17:24:10.562Z","etag":null,"topics":["aws","aws-lambda","go","lambda","serverless"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akrylysov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-19T00:43:27.000Z","updated_at":"2024-09-10T04:40:11.000Z","dependencies_parsed_at":"2023-12-29T14:46:56.132Z","dependency_job_id":null,"html_url":"https://github.com/akrylysov/algnhsa","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akrylysov%2Falgnhsa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akrylysov%2Falgnhsa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akrylysov%2Falgnhsa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akrylysov%2Falgnhsa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akrylysov","download_url":"https://codeload.github.com/akrylysov/algnhsa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247149505,"owners_count":20891954,"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","aws-lambda","go","lambda","serverless"],"created_at":"2024-08-01T17:01:03.238Z","updated_at":"2025-04-04T09:09:54.896Z","avatar_url":"https://github.com/akrylysov.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# algnhsa [![GoDoc](https://godoc.org/github.com/akrylysov/algnhsa?status.svg)](https://godoc.org/github.com/akrylysov/algnhsa) ![Build Status](https://github.com/akrylysov/algnhsa/actions/workflows/test.yaml/badge.svg)\n\nalgnhsa is an AWS Lambda Go `net/http` server adapter.\n\nalgnhsa enables running Go web applications on AWS Lambda and API Gateway or ALB without changing the existing HTTP handlers:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"strconv\"\n\n\t\"github.com/akrylysov/algnhsa\"\n)\n\nfunc addHandler(w http.ResponseWriter, r *http.Request) {\n\tf, _ := strconv.Atoi(r.FormValue(\"first\"))\n\ts, _ := strconv.Atoi(r.FormValue(\"second\"))\n\tw.Header().Set(\"X-Hi\", \"foo\")\n\tfmt.Fprintf(w, \"%d\", f+s)\n}\n\nfunc contextHandler(w http.ResponseWriter, r *http.Request) {\n\tlambdaEvent, ok := algnhsa.APIGatewayV2RequestFromContext(r.Context())\n\tif ok {\n\t\tfmt.Fprint(w, lambdaEvent.RequestContext.AccountID)\n\t}\n}\n\nfunc main() {\n\thttp.HandleFunc(\"/add\", addHandler)\n\thttp.HandleFunc(\"/context\", contextHandler)\n\talgnhsa.ListenAndServe(http.DefaultServeMux, nil)\n}\n```\n\n## Plug in a third-party web framework\n\n### Gin\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/akrylysov/algnhsa\"\n\t\"github.com/gin-gonic/gin\"\n)\n\nfunc main() {\n\tr := gin.Default()\n\tr.GET(\"/\", func(c *gin.Context) {\n\t\tc.JSON(http.StatusOK, gin.H{\n\t\t\t\"message\": \"hi\",\n\t\t})\n\t})\n\talgnhsa.ListenAndServe(r, nil)\n}\n```\n\n### echo\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/akrylysov/algnhsa\"\n\t\"github.com/labstack/echo/v4\"\n)\n\nfunc main() {\n\te := echo.New()\n\te.GET(\"/\", func(c echo.Context) error {\n\t\treturn c.String(http.StatusOK, \"hi\")\n\t})\n\talgnhsa.ListenAndServe(e, nil)\n}\n```\n\n### chi\n\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\n\t\"github.com/akrylysov/algnhsa\"\n\t\"github.com/go-chi/chi\"\n)\n\nfunc main() {\n\tr := chi.NewRouter()\n\tr.Get(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\tw.Write([]byte(\"hi\"))\n\t})\n\talgnhsa.ListenAndServe(r, nil)\n}\n```\n\n### Fiber\n\n```go\npackage main\n\nimport (\n\t\"github.com/akrylysov/algnhsa\"\n\t\"github.com/gofiber/fiber/v2\"\n\t\"github.com/gofiber/fiber/v2/middleware/adaptor\"\n)\n\nfunc main() {\n\tapp := fiber.New()\n\tapp.Get(\"/\", func(c *fiber.Ctx) error {\n\t\treturn c.SendString(\"Hello, World!\")\n\t})\n\talgnhsa.ListenAndServe(adaptor.FiberApp(app), nil)\n}\n```\n\n## Deployment\n\nFirst, build your Go application for Linux and zip it:\n\n```bash\nGOOS=linux GOARCH=amd64 go build -tags lambda.norpc -o bootstrap\nzip function.zip bootstrap\n```\n\nWhen creating a new function, choose the \"Provide your own bootstrap on Amazon Linux 2\" runtime or \"Custom runtime on Amazon Linux 2\" when modifying an existing function. Make sure to use `bootstrap` as the executable name and as the handler name in AWS.\n\nAWS provides plenty of ways to expose a Lambda function to the internet.\n\n### Lambda Function URL\n\nThis is the easier way to deploy your Lambda function as an HTTP endpoint.\nIt only requires going to the \"Function URL\" section of the Lambda function configuration and clicking \"Configure Function URL\".\n\n### API Gateway\n\n#### HTTP API\n\n1. Create a new HTTP API.\n\n2. Configure a catch-all `$default` route.\n\n#### REST API\n\n1. Create a new REST API.\n\n2. In the \"Resources\" section create a new `ANY` method to handle requests to `/` (check \"Use Lambda Proxy Integration\").\n\n3. Add a catch-all `{proxy+}` resource to handle requests to every other path (check \"Configure as proxy resource\").\n\n### ALB\n\n1. Create a new ALB and point it to your Lambda function.\n\n2. In the target group settings in the \"Attributes\" section enable \"Multi value headers\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakrylysov%2Falgnhsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakrylysov%2Falgnhsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakrylysov%2Falgnhsa/lists"}