{"id":16908220,"url":"https://github.com/howardjohn/scala-server-lambda","last_synced_at":"2025-03-22T10:31:21.028Z","repository":{"id":54876985,"uuid":"117397981","full_name":"howardjohn/scala-server-lambda","owner":"howardjohn","description":"Run http4s or akka-http over API Gateway and AWS Lambda","archived":false,"fork":false,"pushed_at":"2020-05-05T14:29:28.000Z","size":59,"stargazers_count":51,"open_issues_count":2,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-18T10:37:37.123Z","etag":null,"topics":["akka-http","akka-http-lambda","api-gateway","aws-lambda","http4s","http4s-lambda","scala","serverless"],"latest_commit_sha":null,"homepage":"","language":"Scala","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/howardjohn.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-01-14T03:18:28.000Z","updated_at":"2023-11-24T01:25:27.000Z","dependencies_parsed_at":"2022-08-14T05:30:40.716Z","dependency_job_id":null,"html_url":"https://github.com/howardjohn/scala-server-lambda","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardjohn%2Fscala-server-lambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardjohn%2Fscala-server-lambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardjohn%2Fscala-server-lambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/howardjohn%2Fscala-server-lambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/howardjohn","download_url":"https://codeload.github.com/howardjohn/scala-server-lambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244943769,"owners_count":20536290,"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":["akka-http","akka-http-lambda","api-gateway","aws-lambda","http4s","http4s-lambda","scala","serverless"],"created_at":"2024-10-13T18:50:39.282Z","updated_at":"2025-03-22T10:31:20.762Z","avatar_url":"https://github.com/howardjohn.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Scala Servers for Lambda\nScala Servers for Lambda allows you to run existing Scala servers over API Gateway and AWS Lambda.\n\nBenefits:\n* Define logic once, and use it in both a server and serverless environment.\n* Simpler testing, as the logic has been isolated from Lambda completely.\n* No need to deal with Lambda's API directly, which aren't easy to use from Scala.\n* All code is deployed to single Lambda function, meaning our functions will be kept warm more often.\n\n## Supported Servers\n\n* [http4s](http://http4s.org) - version 0.20\n* [akka-http](https://doc.akka.io/docs/akka-http/current) - version 10.1.1\n\n## Dependencies\n\nHaving a large JAR can increase cold start times, so dependencies have been kept to a minimum. All servers depend on [circe](https://circe.github.io/circe/). Additionally:\n\n* http4s depends on `http4s-core`.\n* akka-http depends on `akka-http` and `akka-stream`.\n\nNeither of these depend on the AWS SDK at all, which substantially reduces the size.\n\n## Getting Started\n\nMore thorough examples can be found in the examples directory.\n\n### http4s\n\nFirst, add the dependency:\n\n```scala\nlibraryDependencies += \"io.github.howardjohn\" %% \"http4s-lambda\" % \"0.3.1\"\n```\n\nNext, we define a simple `HttpService`. Then, we simply need to define a new class for Lambda.\n\n```scala\nobject Route {\n  // Set up the route\n  val service: HttpService[IO] = HttpService[IO] {\n    case GET -\u003e Root / \"hello\" / name =\u003e Ok(s\"Hello, $name!\")\n  }\n\n  // Define the entry point for Lambda\n  class EntryPoint extends Http4sLambdaHandler(service)\n}\n```\n\nThats it! Make sure any dependencies are initialized in the Route object so they are computed only once.\n\n\n### akka-http\n\nFirst, add the dependency:\n\n```scala\nlibraryDependencies += \"io.github.howardjohn\" %% \"akka-http-lambda\" % \"0.3.1\"\n```\n\nNext, we define a simple `Route`. Then, we simply need to define a new class for Lambda.\n\n```scala\nobject Route {\n  // Set up the route\n  val route: Route =\n    path(\"hello\" / Segment) { name: String =\u003e\n      get {\n        complete(s\"Hello, $name!\")\n      }\n    }\n\n  // Set up dependencies\n  implicit val system: ActorSystem = ActorSystem(\"example\")\n  implicit val materializer: ActorMaterializer = ActorMaterializer()\n  implicit val ec = scala.concurrent.ExecutionContext.Implicits.global\n\n  // Define the entry point for Lambda\n  class EntryPoint extends AkkaHttpLambdaHandler(route)\n}\n```\n\nThats it! Make sure any dependencies are initialized in the Route object so they are computed only once.\n\n## Deploying to AWS\n\nTo deploy to Lambda, we need to create a jar with all of our dependencies. The easiest way to do this is using [sbt-assembly](https://github.com/sbt/sbt-assembly).\n\nOnce we have the jar, all we need to do is upload it to Lambda. The preferred way to do this is using the [serverless](https://github.com/serverless/serverless) framework which greatly simplifies this (and is what is used in the examples), but there is no issues with doing it manually.\n\nWhen deploying to Lambda, the handler should be specified as `\u003cPACKAGE_NAME\u003e.Route$EntryPoint::handle` (if you followed the example above).\n\nFinally, an API can be created in API Gateway. [Lambda Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html) must be enabled.\n\n## Versions\n\n| Version      | http4s Version | akka-http Version |\n|--------------|----------------|-------------------|\n| 0.4          | 0.20           | 10.1              |\n| 0.3.1        | 0.18           | 10.1              |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowardjohn%2Fscala-server-lambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhowardjohn%2Fscala-server-lambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhowardjohn%2Fscala-server-lambda/lists"}