Unable to load an HTTP implementation from any provider in the chain. You must declare a dependency on an appropriate HTTP implementation or pass in an SdkHttpClient explicitly to the client builder

See original GitHub issue

Hi,

I’m trying to do a GetObject() call from S3 using an SBT project. When I try to run the project within my IDE, or do “sbt run”, things work – that is, I’m able to read a file from S3, and do what I need to do with it.

However, when I do “sbt assembly” to get an uber jar (which I plan on uploading to an AWS Lambda), I end up with the below exception:

software.amazon.awssdk.core.exception.SdkClientException: Unable to load an HTTP implementation from any provider in the chain. You must declare a dependency on an appropriate HTTP implementation or pass in an SdkHttpClient explicitly to the client builder.

I tried doing something like below, but to no avail. Exact same behaviour as before I tried to explicitly create an HttpClient.

val apacheClient: SdkHttpClient = ApacheSdkHttpClientFactory.builder()
                                                                .build()
                                                                .createHttpClient()

    val client = S3Client.builder()
                          .httpConfiguration(ClientHttpConfiguration.builder()
                                                                    .httpClient(apacheClient)
                                                                    .build())
                         .region(Region.US_EAST_1)
                         .build()
    val stream: ResponseInputStream[GetObjectResponse] = client.getObject(GetObjectRequest.builder()
                                                            .bucket(s3Bucket)
                                                            .key(s3EventKey)
                                                            .build())

the lib dependencies look like this on my build.sbt:

libraryDependencies ++=
  Seq(
    "org.apache.kafka" %% "kafka" % "1.0.0",
    "com.typesafe" % "config" % "1.3.1",
//    "com.fasterxml.jackson.core" % "jackson-core" % "2.9.1",
//    "com.fasterxml.jackson.core" % "jackson-databind" % "2.9.1",
    "org.apache.avro" % "avro" % "1.8.2",
    "io.confluent" % "kafka-avro-serializer" % "3.3.1",
//    "com.typesafe.play" %% "play-json" % "2.6.7",
//    "com.typesafe.akka" %% "akka-http" % "10.0.11",
    //"software.amazon.awssdk" % "dynamodb" % "2.0.0-preview-2",
    "software.amazon.awssdk" % "dynamodb" % "2.0.0-preview-9",
    "software.amazon.awssdk" % "core" % "2.0.0-preview-9",
   // "com.amazonaws" % "aws-java-sdk" % "1.11.297",
    "com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
    "com.amazonaws" % "aws-lambda-java-events" % "2.1.0",
   // "com.amazonaws" % "aws-java-sdk-s3" % "1.11.301",
    "software.amazon.awssdk" % "sts" % "2.0.0-preview-9",
    "software.amazon.awssdk" % "s3" % "2.0.0-preview-9",
    "software.amazon.awssdk" % "aws-http-client-apache" % "2.0.0-preview-1"
  )

Your Environment

  • AWS Java SDK version used: 2.0
  • JDK version used: 1.8
  • Operating System and version: Mac OS High Sierra (although I get the same exception after uploading and running the uber jar on an AWS lambda function).

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:14 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
oripwkcommented, Jun 14, 2020

This error happens because of wrong configuration of SBT assembly. In your build.sbt whenever you have

case PathList("META-INF", _*) => MergeStrategy.discard

it will also discard the important services dir which includes info on the HTTP client. To resolve this, just do:

case PathList("META-INF", "MANIFEST.MF") => MergeStrategy.discard
4reactions
pazfernandocommented, Aug 10, 2021

I resolved it just adding dependency and a change in code.

static DynamoDbClient dynamoDB = DynamoDbClient.builder()
                .endpointOverride(URI.create("http://localhost:8000"))
                .httpClient(ApacheHttpClient.create())
                .region(Region.US_EAST_1)
                .build();

and

    <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>apache-client</artifactId>
    </dependency>

not “runtime” was necessary

Read more comments on GitHub >

github_iconTop Results From Across the Web

software.amazon.awssdk.core.exception.SdkClientException
If HTTP client is not specified on the SDK client builder, the SDK will use ServiceLoader to find HTTP implementations on the classpath....
Read more >
aws/aws-sdk-java-v2 - Gitter
You must declare a dependency on an appropriate HTTP implementation or pass in an SdkHttpClient explicitly to the client builder. software.amazon.awssdk.core.
Read more >
Introducing AWS Common Runtime HTTP Client in the AWS ...
If HTTP client is not specified on the SDK client builder, the SDK will use ServiceLoader to find HTTP implementations on the classpath....
Read more >
AWS SDK for Java 2.x のUnable to load an HTTP ...
You must declare a dependency on an appropriate HTTP implementation or pass in an SdkHttpClient explicitly to the client builder.
Read more >
software.amazon.awssdk.http.SdkHttpService Java Examples
You must declare a dependency on an appropriate HTTP " + "implementation or pass in an SdkHttpClient explicitly to the " + "client...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found