The import com.amazonaws.services.s3.AmazonS3ClientBuilder cannot be resolved

Viewed 17301

I am trying to access my s3 buckets from my java application, trying to implement this

https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/examples-s3-buckets.html

I've added the lib/aws-java-sdk-1.8.6.jar to my lib folder and added the dependency in my pom.xml as well.

I still get this import error

"The import com.amazonaws.services.s3.AmazonS3ClientBuilder cannot be resolved" for "import com.amazonaws.services.s3.AmazonS3ClientBuilder;"

Whereas the imports

"import com.amazonaws.services.s3.AmazonS3;" and "import com.amazonaws.services.s3.model.Bucket;" gave no errors.

Any help would be appreciated. I found some people trying to implement for Android ran in similar issues but not this exactly

6 Answers

I was having the same issue, and after some research I realized that AmazonS3ClientBuilder is not part from AWS Android SDK instead of that the class is part of AWS JAVA SDK so you have to include this on your dependencies:

implementation 'com.amazonaws:aws-java-sdk:1.11.404'

  • Definitely the dependency as mentioned in Amazon documentation did not work. The path to the dependency does not exist, in Maven central repository.

    "software.amazon.awssdk" % "aws-java-sdk" % "2.0.0"

  • The following too, did not resolve com.amazonaws.services.s3.AmazonS3ClientBuilder, though the JAR path is correct in Maven central -

    "software.amazon.awssdk" % "aws-sdk-java" % "2.1.3"

  • I had to fallback to the following as mentioned in the previous comment.

    "com.amazonaws" % "aws-java-sdk" % "1.11.465"

As I mentioned in my comment - Amazon recommends moving to V2:

The AWS SDK for Java 2.x is a major rewrite of the version 1.x code base. It’s built on top of Java 8+ and adds several frequently requested features. These include support for non-blocking I/O and the ability to plug in a different HTTP implementation at run time.

All V2 examples have been thoroughly unit tested and work (V1 code examples are old).

https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/s3

For people running Spring using Maven build, the pom.xml dependency you need to import com.amazonaws.services.s3.AmazonS3ClientBuilder; into the Java class is this:

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-s3</artifactId>
        <version>1.11.267</version>
    </dependency>

The AWS Documentation is not correct, add this to your pom.xml file:

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-sqs</artifactId>
    <version>1.11.1005</version>
</dependency>

The AWS Documentation is not correct, add this to your pom.xml file:

<dependency>
  <groupId>software.amazon.awssdk</groupId>
  <artifactId>s3</artifactId>
  <version>2.15.32</version>
</dependency>
Related