6

I'm getting this error below when I try to call a DynamoDB AWS service:

Multiple HTTP implementations were found on the classpath. To avoid non-deterministic loading implementations, please explicitly provide an HTTP client via the client builders, set the software.amazon.awssdk.http.service.impl system property with the FQCN of the HTTP service to use as the default, or remove all but one HTTP implementation from the classpath

I'm using DynamoDbClient

My pom.xml:

       <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>dynamodb</artifactId>
        </dependency>
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>url-connection-client</artifactId>
        </dependency>

Client configuration:

@Singleton
public class DynamoClientConfig {

    @Produces
    @ApplicationScoped
    public DynamoDbClient getClientDb() {
        return DynamoDbClient.builder().region(Region.SA_EAST_1).build();
    }

I'm using Java and Quarkus.

Does anyone know what it could be and how to fix it?

ner
  • 173
  • 1
  • 1
  • 9
  • 1
    Did you search for that system property e.g. [here](https://aws.amazon.com/blogs/developer/aws-sdk-for-java-2-x-released/)? You can use AWS' default implementation by setting it to `software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService`, for example. – jarmod Jul 26 '22 at 20:29
  • Thanks your approach worked. – ner Jul 27 '22 at 14:02

5 Answers5

8

Sorted out! I added the parameter in dynamodbclient and it worked.

.httpClient(UrlConnectionHttpClient.builder().build())
ner
  • 173
  • 1
  • 1
  • 9
  • When I tried using the `UrlConnectionHttpClient` I received a "host not found" Exception. I had to use the `ApacheHttpClient`; which is the standard client anyway. – Ramón J Romero y Vigil May 01 '23 at 21:17
2

Actually it may be any compatible Http client. E.g. Apache Http client works for me:

import software.amazon.awssdk.http.apache.ApacheHttpClient;

CloudWatchLogsClient.builder.httpClient(ApacheHttpClient.builder().build()).build();
Mitrakov Artem
  • 1,355
  • 2
  • 14
  • 22
1

The issue is caused by the below behavior (source):

If HTTP client is not specified on the SDK client builder, the SDK will use ServiceLoader to find HTTP implementations on the classpath.

Though your approach works, instead of httpClient you should use httpClientBuilder most of the time, so that the SDK takes care of managing the httpClient lifecycle for you. See the DynamoDbClientBuilder javadoc for reference here and here . The difference:

httpClient:

This client must be closed by the user when it is ready to be disposed. The SDK will not close the HTTP client when the service client is closed.

whereas in case of httpClientBuilder:

Clients created by the builder are managed by the SDK and will be closed when the service client is closed.

Balu
  • 522
  • 6
  • 16
0

I had the same issue when I used

implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:dynamodb'
implementation 'software.amazon.awssdk:sts'
implementation 'software.amazon.awssdk:url-connection-client'
implementation 'software.amazon.awssdk:cognitoidentityprovider'

and tried to create

CognitoIdentityProviderClient.builder()
                .httpClientBuilder(UrlConnectionHttpClient.builder())
                .credentialsProvider(cognitoCredentials)
                .build();

Set the system property software.amazon.awssdk.http.service.impl with the fully qualified name of the HTTP service class you want to use by default. For example

System.setProperty("software.amazon.awssdk.http.service.impl", "software.amazon.awssdk.http.urlconnection.UrlConnectionSdkHttpService");
makson
  • 1,975
  • 3
  • 23
  • 31
-1

When I have upgraded amazon-kinesis-client to 2.4.0 I see this issue. Keep it to 2.3.5

springboard 2.5.6

jdk 11

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 05 '23 at 13:57