https://github.com/markosski/lambdaweb4s
Library for building serverless web APIs on AWS Lambda
https://github.com/markosski/lambdaweb4s
aws-lambda rest-api scala
Last synced: 5 months ago
JSON representation
Library for building serverless web APIs on AWS Lambda
- Host: GitHub
- URL: https://github.com/markosski/lambdaweb4s
- Owner: markosski
- License: mit
- Created: 2022-10-18T21:06:07.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-29T18:46:19.000Z (over 3 years ago)
- Last Synced: 2023-05-25T23:32:36.216Z (about 3 years ago)
- Topics: aws-lambda, rest-api, scala
- Language: Scala
- Homepage:
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lambdaweb4s
**lambdaweb4s** is a lightweight library that bridges multiple AWS web integrations into single
response/request model. The benefits of this approach are the following:
* convenient pattern matching syntax to map request to response objects
* zero dependency built-in development web server to test lambda locally
* lambda can be deployed in front of ALB or API Gateway without any change to source code
## Coordinates
https://repo1.maven.org/maven2/io/github/markosski/lambdaweb4s_2.13/
## Usage
Add `lambdaweb4s` dependency to your build system and create class that extends `LambdaWebHandler`.
When deploying to AWS, configure your lambda function to be backed either by Application Load Balancer or API Gateway in passthrough mode. When executed locally, built-in web server will start up that you can use to test your application endpoints locally.
```scala
import lambdaweb4s.models.Methods._
import lambdaweb4s.LambdaWebHandler
import lambdaweb4s.DevWebServer
import lambdaweb4s.models._
import lambdaweb4s.models.Path.Root
import lambdaweb4s.models.Codes._
class Handler extends LambdaWebHandler {
def accountInfo(accountId: String): Response = {
Response.ok(s"Info for account: $accountId")
}
def routes = {
case GET -> Root => Response.ok("Hello World")
case GET -> Root / "_health" => Response.ok("healthy")
case GET -> Root / "accounts" / accountId / "info" => accountInfo(accountId)
case _ => Response.text(NOT_FOUND, "page not found")
}
}
object Handler extends App {
val server = new DevWebServer(new Handler)
server.listen(8080)
}
```
## Run Example with SBT
`sbt "project example; run"`
## Run Locally
After building uber jar with build plugin of your choice you can run lambda app locally
`java -jar application.jar`