Skip to content

Instantly share code, notes, and snippets.

@mkotsur
Created March 8, 2018 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkotsur/1426e3eb5ea541030bb2959274db09e9 to your computer and use it in GitHub Desktop.
Save mkotsur/1426e3eb5ea541030bb2959274db09e9 to your computer and use it in GitHub Desktop.
package hello
import io.circe.generic.auto._
import io.github.mkotsur.aws.handler.Lambda._
import io.github.mkotsur.aws.handler.Lambda
import com.amazonaws.services.lambda.runtime.Context
import io.github.mkotsur.aws.proxy
import io.github.mkotsur.aws.proxy.ProxyResponse
import ScalaHandler._
object ScalaHandler {
case class Req(key1: String, key2: String, key3: String)
case class Resp(message: String, request: Req)
}
class ScalaHandler extends Lambda[Req, Resp] {
override def handle(req: Req, context: Context): Either[Throwable, Resp] =
Right(Resp("And this is how you do it with mkotsur/aws-lambda-scala", req))
}
class ApiGatewayScalaHandler extends Proxy[Req, Resp] {
override def handle(input: proxy.ProxyRequest[Req], c: Context): Either[Throwable, ProxyResponse[Resp]] = {
val headers = Map("x-custom-response-header" -> "my custom response header value")
val responseBodyOption = input.body.map(req => Resp("And this is how you do it with mkotsur/aws-lambda-scala", req))
Right(ProxyResponse(200, Some(headers), responseBodyOption))
}
}
package:
artifact: target/scala-2.12/hello.jar
functions:
helloScala:
handler: hello.ScalaHandler::handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment