diff --git a/build.sbt b/build.sbt index 6e4e03536..8a8d470f7 100644 --- a/build.sbt +++ b/build.sbt @@ -29,6 +29,9 @@ lazy val hat = project DsLib.SilhouettePersistence, DsLib.SlickPostgresDriver, Lib.AwsV1Sdk, + Lib.AwsV2SdkLambda, + Lib.AwsV2SdkSts, + Lib.AwsV2SdkAuth, Lib.BouncyCastle, Lib.Ficus, Lib.Guard, @@ -39,7 +42,6 @@ lazy val hat = project Lib.PlayTest, Lib.PrometheusFilter, Lib.ScalaGuice, - LocalThirdParty.AlpakkaAwsLambda, LocalThirdParty.CirceConfig, LocalThirdParty.PrettyTime, DsLib.IntegrationTestCommon % Test, diff --git a/hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala b/hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala index 941b3f71f..3f79bbc07 100644 --- a/hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala +++ b/hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala @@ -25,8 +25,6 @@ package org.hatdex.hat.she.models import akka.actor.ActorSystem -import akka.stream.alpakka.awslambda.scaladsl.AwsLambdaFlow -import akka.stream.scaladsl.{ Sink, Source } import akka.stream.{ ActorMaterializer, Materializer } import io.dataswift.models.hat.EndpointDataBundle import io.dataswift.models.hat.applications.Version @@ -35,11 +33,11 @@ import org.hatdex.hat.api.service.RemoteExecutionContext import org.joda.time.DateTime import play.api.libs.json.{ Format, Json } import play.api.{ Configuration, Logger } -import software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider import software.amazon.awssdk.core.SdkBytes import software.amazon.awssdk.regions.Region import software.amazon.awssdk.services.lambda.LambdaAsyncClient import software.amazon.awssdk.services.lambda.model.{ InvokeRequest, InvokeResponse } +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider import javax.inject.Inject import scala.concurrent.{ ExecutionContext, Future } @@ -166,7 +164,7 @@ class AwsLambdaExecutor @Inject() ( LambdaAsyncClient .builder() .region(Region.of(configuration.get[String]("she.aws.region"))) - .credentialsProvider(ContainerCredentialsProvider.builder().build()) + .credentialsProvider(DefaultCredentialsProvider.create()) .build() actorSystem.registerOnTermination(lambdaClient.close()) @@ -175,7 +173,38 @@ class AwsLambdaExecutor @Inject() ( request: InvokeRequest )(implicit jsonFormatter: Format[T]): Future[T] = if (mock) Future.successful(null.asInstanceOf[T]) - else + else { + lambdaClient.invoke{request}.get match { + case r: InvokeResponse if r.functionError() == null => + logger.debug(s"""Function responded with: + | Status: ${r.statusCode()} + | Body: ${r.payload().asUtf8String()} + | Logs: ${Option(r.logResult()).map(log => java.util.Base64.getDecoder.decode(log))} + """.stripMargin) + val jsResponse = + Json.parse(r.payload().asUtf8String()).validate[T] recover { + case e => + val message = s"Error parsing lambda response: $e" + logger.error(message) + logger.error(s"Unable to parse: ${r.payload().asUtf8String()}") + throw DataFormatException(message) + } + Future(jsResponse.get) + case r: InvokeResponse if r.functionError() != null => + val message = + s"Retrieving SHE function Response Error: ${r.functionError()}" + logger.error(message) + throw new ApiException(message) + case r => + val message = + s"Retrieving SHE function Response FAILED: $r, ${r.payload().asUtf8String()}" + logger.error(message) + throw new ApiException(message) + } + } + + + /* Source .single(request) .via(AwsLambdaFlow(1)(lambdaClient)) @@ -200,5 +229,6 @@ class AwsLambdaExecutor @Inject() ( s"Retrieving SHE function configuration failed: $r, ${r.payload().asUtf8String()}" logger.error(message) throw new ApiException(message) - } + }*/ + } diff --git a/hat/conf/she.conf b/hat/conf/she.conf index 7049c0c67..afce723c2 100644 --- a/hat/conf/she.conf +++ b/hat/conf/she.conf @@ -60,15 +60,6 @@ she { endpoint = "insights/busy-time" experimental = true } - { - id = "common-locations" - version = "1.0.0" - baseUrl = "common-locations-dev" - baseUrl = ${?COMMON_LOCATION_URL} - namespace = "she" - endpoint = "insights/common-locations" - experimental = true - } { id = "covid19-score" version = "1.0.0" diff --git a/project/BasicSettings.scala b/project/BasicSettings.scala index 10586322c..7d6e5a35b 100644 --- a/project/BasicSettings.scala +++ b/project/BasicSettings.scala @@ -72,4 +72,10 @@ object BasicSettings extends AutoPlugin { // and https://github.com/travis-ci/travis-ci/issues/3775 javaOptions += "-Xmx1G" ) + + object autoImport { + // Do Nothing + // Added by Terry 20220422 + // Not sure why this block is missing and how you got HAT to compile in the first place? + } } diff --git a/project/plugins.sbt b/project/plugins.sbt index 8b21b1ee9..0adbb15dc 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,7 +2,7 @@ resolvers += "HAT Library Artifacts Releases" at "https://s3-eu-west-1.amazonaws addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.4") addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.2") addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.4") -addSbtPlugin("io.dataswift" % "sbt-scalatools-common" % "0.5.12") +addSbtPlugin("io.dataswift" % "sbt-scalatools-common" % "0.5.22") addSbtPlugin("org.hatdex" % "sbt-slick-postgres-generator" % "0.1.2") addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.5.1") addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")