code: public static S3ObjectSummary getSingleObjectSummary(ServerSideEncryptingAmazonS3 s3Client, String bucket, String key)
    {
      final ListObjectsV2Request request = new ListObjectsV2Request()
          .withBucketName(bucket)
          .withPrefix(key)
          .withMaxKeys(1);
      final ListObjectsV2Result result = s3Client.listObjectsV2(request);
  
      // Using getObjectSummaries().size() instead of getKeyCount as, in some cases
      // it is observed that even though the getObjectSummaries returns some data
      // keyCount is still zero.
      if (result.getObjectSummaries().size() == 0) {
        throw new ISE("Cannot find object for bucket[%s] and key[%s]", bucket, key);
      }
      final S3ObjectSummary objectSummary = result.getObjectSummaries().get(0);
      if (!objectSummary.getBucketName().equals(bucket) || !objectSummary.getKey().equals(key)) {
        throw new ISE("Wrong object[%s] for bucket[%s] and key[%s]", objectSummary, bucket, key);
      }
  
      return objectSummary;
    }
docs: Gets a single {@link S3ObjectSummary} from s3. Since this method might return a wrong object if there are multiple
  objects that match the given key, this method should be used only when it's guaranteed that the given key is unique
  in the given bucket.
  
  @param s3Client s3 client
  @param bucket   s3 bucket
  @param key      unique key for the object to be retrieved