I wanted to list directories under a particular bucket but S3client does not return directories but objects I have been struggling with this I couldn't find anything on google but after some research i got my answers so i thought to put my solution here
private static List<String> listDirectoryFromS3FS(URI baseURI)
{
UnderFsObjectMeta underFsObjectMeta = new UnderFsObjectMeta(baseURI);
S3Client client = S3Client.builder().region(Region.US_EAST_1).build();
ListObjectsV2Request request = ListObjectsV2Request.builder().bucket(underFsObjectMeta.m_sBucketName)
.prefix(underFsObjectMeta.m_sDirectoryPath).delimiter(Utility.PART_FILE_SEPARATOR).build();
List<CommonPrefix> prefixes = client.listObjectsV2(request).commonPrefixes();
List<String> listDirectories = new LinkedList<>();
for (CommonPrefix prefix:prefixes)
{
listDirectories.add(prefix.prefix());
}
return listDirectories;
}