Step 1: Get the latest aws-java-sdk
<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-aws -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.660</version>
</dependency>
Step 2: The correct imports
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ListObjectsRequest;
import com.amazonaws.services.s3.model.ObjectListing;
If you are sure the bucket exists, Specified key does not exists error
would mean the bucketname is not spelled correctly ( contains slash or special characters). Refer the documentation for naming convention.
The document quotes:
If the requested object is available in the bucket and users are still
getting the 404 NoSuchKey error from Amazon S3, check the following:
Confirm that the request matches the object name exactly, including
the capitalization of the object name. Requests for S3 objects are
case sensitive. For example, if an object is named myimage.jpg, but
Myimage.jpg is requested, then requester receives a 404 NoSuchKey
error. Confirm that the requested path matches the path to the object.
For example, if the path to an object is
awsexamplebucket/Downloads/February/Images/image.jpg, but the
requested path is awsexamplebucket/Downloads/February/image.jpg, then
the requester receives a 404 NoSuchKey error. If the path to the
object contains any spaces, be sure that the request uses the correct
syntax to recognize the path. For example, if you're using the AWS CLI
to download an object to your Windows machine, you must use quotation
marks around the object path, similar to: aws s3 cp
"s3://awsexamplebucket/Backup Copy Job 4/3T000000.vbk". Optionally,
you can enable server access logging to review request records in
further detail for issues that might be causing the 404 error.
AWSCredentials credentials = new BasicAWSCredentials(AWS_ACCESS_KEY_ID, AWS_SECRET_KEY);
AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
ObjectListing objects = s3Client.listObjects("bigdataanalytics");
System.out.println(objects.getObjectSummaries());