I was able to read the file using AmazonS3Client, but now I'm trying read the file using the package software.amazon.awssdk.services.s3.S3Client. I did not find the option to pass the file name to the GetObjectRequest constructoe unlike com.amazonaws.services.s3 package. Here is my sample code.
import software.amazon.awssdk.services.s3.model.ListObjectsV2Response;
import software.amazon.awssdk.services.s3.model.S3Object;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectResponse;
main(String[] args){
String bucketName = "some-name-s3";
Region region = Region.US_EAST_1;
S3Client s3client = S3Client
.builder()
.region(region)
.build();
ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder().bucket(bucketName).build();
ListObjectsV2Response listObjectsV2 = s3client.listObjectsV2(listObjectsV2Request);
List<S3Object> s3Objects = listObjectsV2.contents();
}
Now how to read the each file and process the stream from s3Objects.