2017-03-31 08:14:00 -0500 -

In this tutorial I show you how to package and deploy a simple Scala project to AWS Lambda. Then I show you how to add the lambda to API Gateway to run in response to GET requests.

Build the Scala Project

build.sbt

javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")

lazy val root = (project in file(".")).
  settings(
    name := "lambda-demo",
    version := "1.0",
    scalaVersion := "2.11.4",
    retrieveManaged := true,
    libraryDependencies += "com.amazonaws" % "aws-lambda-java-core" % "1.0.0",
    libraryDependencies += "com.amazonaws" % "aws-lambda-java-events" % "1.0.0"
  )

mergeStrategy in assembly :=
{
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x => MergeStrategy.first
}

src/main/scala/example/Main.scala

package example;

class Main {
  import java.io.{InputStream, OutputStream, PrintStream}

  def greeting(input: InputStream, output: OutputStream): Unit = {
    val result = s"Yo!"
    output.write(result.getBytes("UTF-8"))
  }
}

Deploy the Scala Project to AWS Lambda

At this point you could setup API Gateway to use the Scala Lambda in a similar way that I set it up for the node.js Lambda Function.