4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

serverlessでScalaをLambdaにデプロイ

Posted at

ServerlessFrameworkでScala+Lambda+APIGateway構成プロジェクトを作成を参考にserverless frameworkを使ってScalaプロジェクトをLambdaにデプロイしてみる。

プロジェクトディレクトリの作成

mkdir [your_project_dir]
cd [your_project_dir]

serverless framework のインストール

npm install --g serverless

なぜかproject/plugin.sbtの下記の場所を削除しなければ動かなかった

  1 addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.0")

serverlessでLambdaへデプロイ

sls deploy --verbose

作成したFunction及び関連サービスを削除

sls remove -v

skinny-json周りでいろいろと変更する必要があった。

build.sbt

libraryDependencies ++= Seq(
...
  "org.skinny-framework" %% "skinny-json" % "2.5.2"

バージョンが進んでいるので最新に合わせる

Response.scala

package hello

import scala.beans.BeanProperty
import skinny.json4s.JSONStringOps._

case class Response(@BeanProperty body: String, @BeanProperty headers: Map[String, String], @BeanProperty statusCode: Int)
object Response {
  val contentJson = "Content-Type" -> "application/json"
  def apply(body: Map[String, Any], headers: Map[String, String] = Map(contentJson), statusCode: Int = 200) = {
    new Response(toJSONString(body), headers, statusCode)
  }
}

skinny.util.JSONStringOps ではなくskinny.json4s.JSONStringOpsを読み込む

ここまで設定したらserverlessでLambdaとAPIGatewayにデプロイしてみる

sls deploy --verbose

無事デプロイできた。
APIGatewayのテスト実行でもstatus=200を返すようになった。

細かい差異については後日もう少し付け足す予定です。
ようやくScalaでのbatch && API環境が整いそうです。

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?