To use it, as it is not published to maven, you need to clone this repository and issue:
sbt publishLocal
Then you can use it in your build.sbt
as:
libraryDependencies += "io.camilosampedro" %% "scala-aws-lambda-json" % "0.1"
You can use this library to get the requests from Lambda as your case classes. You just need to implement io.github.camilosampedro.lambda.RequestHandler[I, O]
.
case class MyInput(field: String, field2: Int, field3: Boolean)
case class MyOutput(my: Double, response: String)
import io.camilosampedro.lambda.runtime.JsonRequestHandler
import _root_.com.amazonaws.services.lambda.runtime.Context
class MyHandler extends JsonRequestHandler[MyInput, MyOutput] {
override def handleRequest(input: MyInput, context: Context): MyOutput = {
println(s"Your input was: $input")
MyOutput(2.5, "")
}
}
This will receive Json like
{
"field": "Fus Roh Dah",
"field2": 2,
"field3": false
}
And produce the hardcoded output
{
"my": 1.5,
"response": "It's no use crying over spilt milk -- it only makes it salty for the cat."
}
Then export it as fat-jar
sbt assembly
And upload it to lambda with MyHandler
as a Handler.