Writing a handler for AWS lambda in Scala can be as easy as...
package io.github.mkotsur.example
import io.github.mkotsur.aws.handler.LambdaHandler
import io.circe.generic.auto._
case class Ping(inputMsg: String)
case class Pong(outputMsg: String)
class PingPongHandler extends LambdaHandler[Ping, Pong] {
override def handle(ping: Ping) = Right(Pong(ping.inputMsg.reverse))
}
The input JSON will be automatically deserialized into Ping
, and the output into Pong
. The handle()
method is supposed to return Either[Throwable, Pong]
: Right
if the input was handled correctly, and Left
otherwise.
This handler can be used in AWS Lambda as: io.github.mkotsur.example::handle
.
Features:
- JSON (de)serialization of case classes;
- Plain strings are supported too;
- AWS API Gateway proxy integration;
Docs are coming soon... Feel free to look at src/test/scala
if you want to use it right now.
libraryDependencies += "io.github.mkotsur" % "aws-lambda-scala_2.12" % "0.0.5"
Don't define a companion object for the handler class. AWS won't appreciate that.