错误:scalac:找不到类com.amazonaws.services.s3.event.S3EventNotification - 继续存根

时间:2017-08-19 21:26:52

标签: amazon-web-services aws-lambda

我正在尝试使用aws lambda处理S3事件。以下是 build.sbt 文件,该文件已从Writing AWS Lambda Functions in Scala修改:

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 ++= Seq(
  "com.amazonaws" % "aws-lambda-java-core" % "1.1.0",
  "com.amazonaws" % "aws-lambda-java-events" % "1.0.0"
)

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

非常简单 Main.scala

package example;

import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.S3Event

class Main {
  def myHandler(event: S3Event, context: Context): String = s"Hello $event"
}

无法使用以下内容进行编译:

  

错误:scalac:找不到类com.amazonaws.services.s3.event.S3EventNotification - 继续存根。

似乎缺少依赖项,我添加了aws-java-sdk

libraryDependencies ++= Seq(
  "com.amazonaws" % "aws-java-sdk" % "1.11.179",
  "com.amazonaws" % "aws-lambda-java-core" % "1.1.0",
  "com.amazonaws" % "aws-lambda-java-events" % "1.0.0"
)

它编译得很好!!但后来我意识到包大小是79MB,这超过了lambda函数的硬限制:50MB。有解决方案吗

1 个答案:

答案 0 :(得分:5)

好的,我意识到我不必包含aws-java-sdk。我唯一需要的是s3相关部分。将依赖项更改为以下后,它可以正常工作。

libraryDependencies ++= Seq(
  "com.amazonaws" % "aws-java-sdk-s3" % "1.11.179",
  "com.amazonaws" % "aws-lambda-java-core" % "1.1.0",
  "com.amazonaws" % "aws-lambda-java-events" % "1.0.0"
)

最终的包装尺寸仅为11.8MB,小于50MB的限制。