Skip to content

Commit e112fce

Browse files
authored
Merge pull request #591 from dataswift/she-config-test
She config test
2 parents 5415cb5 + 85ed949 commit e112fce

File tree

5 files changed

+46
-17
lines changed

5 files changed

+46
-17
lines changed

build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ lazy val hat = project
2929
DsLib.SilhouettePersistence,
3030
DsLib.SlickPostgresDriver,
3131
Lib.AwsV1Sdk,
32+
Lib.AwsV2SdkLambda,
33+
Lib.AwsV2SdkSts,
34+
Lib.AwsV2SdkAuth,
3235
Lib.BouncyCastle,
3336
Lib.Ficus,
3437
Lib.Guard,
@@ -39,7 +42,6 @@ lazy val hat = project
3942
Lib.PlayTest,
4043
Lib.PrometheusFilter,
4144
Lib.ScalaGuice,
42-
LocalThirdParty.AlpakkaAwsLambda,
4345
LocalThirdParty.CirceConfig,
4446
LocalThirdParty.PrettyTime,
4547
DsLib.IntegrationTestCommon % Test,

hat/app/org/hatdex/hat/she/models/LambdaFunctionExecutable.scala

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
package org.hatdex.hat.she.models
2626

2727
import akka.actor.ActorSystem
28-
import akka.stream.alpakka.awslambda.scaladsl.AwsLambdaFlow
29-
import akka.stream.scaladsl.{ Sink, Source }
3028
import akka.stream.{ ActorMaterializer, Materializer }
3129
import io.dataswift.models.hat.EndpointDataBundle
3230
import io.dataswift.models.hat.applications.Version
@@ -35,11 +33,11 @@ import org.hatdex.hat.api.service.RemoteExecutionContext
3533
import org.joda.time.DateTime
3634
import play.api.libs.json.{ Format, Json }
3735
import play.api.{ Configuration, Logger }
38-
import software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider
3936
import software.amazon.awssdk.core.SdkBytes
4037
import software.amazon.awssdk.regions.Region
4138
import software.amazon.awssdk.services.lambda.LambdaAsyncClient
4239
import software.amazon.awssdk.services.lambda.model.{ InvokeRequest, InvokeResponse }
40+
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider
4341

4442
import javax.inject.Inject
4543
import scala.concurrent.{ ExecutionContext, Future }
@@ -166,7 +164,7 @@ class AwsLambdaExecutor @Inject() (
166164
LambdaAsyncClient
167165
.builder()
168166
.region(Region.of(configuration.get[String]("she.aws.region")))
169-
.credentialsProvider(ContainerCredentialsProvider.builder().build())
167+
.credentialsProvider(DefaultCredentialsProvider.create())
170168
.build()
171169

172170
actorSystem.registerOnTermination(lambdaClient.close())
@@ -175,7 +173,38 @@ class AwsLambdaExecutor @Inject() (
175173
request: InvokeRequest
176174
)(implicit jsonFormatter: Format[T]): Future[T] =
177175
if (mock) Future.successful(null.asInstanceOf[T])
178-
else
176+
else {
177+
lambdaClient.invoke{request}.get match {
178+
case r: InvokeResponse if r.functionError() == null =>
179+
logger.debug(s"""Function responded with:
180+
| Status: ${r.statusCode()}
181+
| Body: ${r.payload().asUtf8String()}
182+
| Logs: ${Option(r.logResult()).map(log => java.util.Base64.getDecoder.decode(log))}
183+
""".stripMargin)
184+
val jsResponse =
185+
Json.parse(r.payload().asUtf8String()).validate[T] recover {
186+
case e =>
187+
val message = s"Error parsing lambda response: $e"
188+
logger.error(message)
189+
logger.error(s"Unable to parse: ${r.payload().asUtf8String()}")
190+
throw DataFormatException(message)
191+
}
192+
Future(jsResponse.get)
193+
case r: InvokeResponse if r.functionError() != null =>
194+
val message =
195+
s"Retrieving SHE function Response Error: ${r.functionError()}"
196+
logger.error(message)
197+
throw new ApiException(message)
198+
case r =>
199+
val message =
200+
s"Retrieving SHE function Response FAILED: $r, ${r.payload().asUtf8String()}"
201+
logger.error(message)
202+
throw new ApiException(message)
203+
}
204+
}
205+
206+
207+
/*
179208
Source
180209
.single(request)
181210
.via(AwsLambdaFlow(1)(lambdaClient))
@@ -200,5 +229,6 @@ class AwsLambdaExecutor @Inject() (
200229
s"Retrieving SHE function configuration failed: $r, ${r.payload().asUtf8String()}"
201230
logger.error(message)
202231
throw new ApiException(message)
203-
}
232+
}*/
233+
204234
}

hat/conf/she.conf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ she {
6060
endpoint = "insights/busy-time"
6161
experimental = true
6262
}
63-
{
64-
id = "common-locations"
65-
version = "1.0.0"
66-
baseUrl = "common-locations-dev"
67-
baseUrl = ${?COMMON_LOCATION_URL}
68-
namespace = "she"
69-
endpoint = "insights/common-locations"
70-
experimental = true
71-
}
7263
{
7364
id = "covid19-score"
7465
version = "1.0.0"

project/BasicSettings.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,10 @@ object BasicSettings extends AutoPlugin {
7272
// and https://github.com/travis-ci/travis-ci/issues/3775
7373
javaOptions += "-Xmx1G"
7474
)
75+
76+
object autoImport {
77+
// Do Nothing
78+
// Added by Terry 20220422
79+
// Not sure why this block is missing and how you got HAT to compile in the first place?
80+
}
7581
}

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ resolvers += "HAT Library Artifacts Releases" at "https://s3-eu-west-1.amazonaws
22
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.4")
33
addSbtPlugin("com.typesafe.sbt" % "sbt-gzip" % "1.0.2")
44
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.4.4")
5-
addSbtPlugin("io.dataswift" % "sbt-scalatools-common" % "0.5.12")
5+
addSbtPlugin("io.dataswift" % "sbt-scalatools-common" % "0.5.22")
66
addSbtPlugin("org.hatdex" % "sbt-slick-postgres-generator" % "0.1.2")
77
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.5.1")
88
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.1")

0 commit comments

Comments
 (0)