0

I am stuck at this issue where I am using a particular Datadog HTTP API ( "com.datadoghq" % "datadog-api-client" % "1.0.0-beta10" % "compile" ) to send some custom stats to Datadog Agent from within my application. This client depends on jersey dependencies.

I have a few end to end test cases where the entire functionality / flow is working and I am able to send stats successfully.

The issue arises when when I start using the (fat) jar to create a Lambda Function that triggers with any incoming SNS event. I get the below error and I have tried many combinations of dependencies reading some earlier thread, but nothing seems to be working.

Could you please suggest something? Could this be due to the way how Lambda is invoked? As when I run in local, everything is fine. Although I don't think this matters, but the application is written in Scala 2.12.

I have tried the below threads:

  1. Jersey stopped working with InjectionManagerFactory not found
  2. HTTP Status 500 - Servlet.init()
  3. https://github.com/igniterealtime/REST-API-Client/issues/29
2021-05-03T23:58:12.412-04:00   java.lang.IllegalStateException: InjectionManagerFactory not found.
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
2021-05-03T23:58:12.412-04:00   at java.util.Optional.orElseThrow(Optional.java:290)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:98)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:68)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.ClientConfig$State.initRuntime(ClientConfig.java:432)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.internal.util.collection.Values$LazyValueImpl.get(Values.java:341)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.ClientConfig.getRuntime(ClientConfig.java:826)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.ClientRequest.getConfiguration(ClientRequest.java:285)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.JerseyInvocation.validateHttpMethodAndEntity(JerseyInvocation.java:143)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:112)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:108)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.JerseyInvocation.<init>(JerseyInvocation.java:99)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:445)
2021-05-03T23:58:12.412-04:00   at org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:351)
2021-05-03T23:58:12.412-04:00   at com.datadog.api.v1.client.ApiClient.sendRequest(ApiClient.java:1476)
2021-05-03T23:58:12.412-04:00   at com.datadog.api.v1.client.ApiClient.invokeAPI(ApiClient.java:1435)
2021-05-03T23:58:12.412-04:00   at com.datadog.api.v1.client.api.MetricsApi.submitMetricsWithHttpInfo(MetricsApi.java:533)
2021-05-03T23:58:12.412-04:00   at com.datadog.api.v1.client.api.MetricsApi.submitMetrics(MetricsApi.java:476)
2021-05-03T23:58:12.412-04:00   at com.organization.raw.beacon.metric.statsD.DataDogHttpMetricsApi.$anonfun$send$1(DataDogHttpMetricsApi.scala:115)
2021-05-03T23:58:12.412-04:00   at scala.util.Try$.apply(Try.scala:213)
2021-05-03T23:58:12.412-04:00   at com.organization.raw.beacon.metric.statsD.DataDogHttpMetricsApi.send(DataDogHttpMetricsApi.scala:115)
2021-05-03T23:58:12.412-04:00   at com.organization.raw.beacon.metric.application.EventHandler.pushStats(EventHandler.scala:102)
2021-05-03T23:58:12.412-04:00   at com.organization.raw.beacon.metric.application.SnsEventHandler.handle(SnsEventHandler.scala:67)
2021-05-03T23:58:12.412-04:00   at com.organization.raw.beacon.metric.SnsLambdaHandler.handleRequest(SnsLambdaHandler.scala:27)
2021-05-03T23:58:12.412-04:00   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2021-05-03T23:58:12.412-04:00   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2021-05-03T23:58:12.412-04:00   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2021-05-03T23:58:12.412-04:00   at java.lang.reflect.Method.invoke(Method.java:498)
2021-05-03T23:58:12.412-04:00   at lambdainternal.EventHandlerLoader$PojoMethodRequestHandler.handleRequest(EventHandlerLoader.java:263)
2021-05-03T23:58:12.412-04:00   at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:180)
2021-05-03T23:58:12.412-04:00   at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:902)
2021-05-03T23:58:12.412-04:00   at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:340)
2021-05-03T23:58:12.412-04:00   at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:63)
2021-05-03T23:58:12.412-04:00   at java.lang.Class.forName0(Native Method)
2021-05-03T23:58:12.412-04:00   at java.lang.Class.forName(Class.java:348)
2021-05-03T23:58:12.412-04:00   at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:150)

Invoking Handler as below:

class SnsLambdaHandler extends RequestHandler[SNSEvent, Unit] with LazyLogging {

  // base configuration
  lazy val baseConfig: Config = getRootConfig.getConfig(this.getClass.getPackage.getName)

  /**
   * Handles SNS notification triggered by CreateObject Request in S3
   *
   * @param snsEvent
   * @param context
   */
  override def handleRequest(snsEvent: SNSEvent, context: Context): Unit = {

    logger.info("Request handler invoking for {} messages from the Sns Topic.", snsEvent.getRecords.size())
    val sqsMessageHandler = SnsEventHandler.apply(baseConfig, snsEvent)

    // handle the event
    sqsMessageHandler.handle()
  }
}

Apratim Tiwari
  • 353
  • 1
  • 5
  • 9
  • I don't know what the equivalent is in SBT, but with Maven, we would use the maven-shade-plugin to solve this issue. It has to do with the META-INF service files not being included when you build a fat jar. You need some build transformer to concatenate all the service files into one. See [related](https://stackoverflow.com/q/37735728/2587435). – Paul Samsotha May 05 '21 at 18:13

0 Answers0