Using HeadObject with directory buckets - Amazon Simple Storage Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Using HeadObject with directory buckets

The following Amazon SDK and Amazon CLI examples show how to use the HeadObject API operation to retrieve metadata from an object in an Amazon S3 directory bucket without returning the object itself.

SDK for Java 2.x
public static void headObject(S3Client s3Client, String bucketName, String objectKey) { try { HeadObjectRequest headObjectRequest = HeadObjectRequest .builder() .bucket(bucketName) .key(objectKey) .build(); HeadObjectResponse response = s3Client.headObject(headObjectRequest); System.out.format("Amazon S3 object: \"%s\" found in bucket: \"%s\" with ETag: \"%s\"", objectKey, bucketName, response.eTag()); } catch (S3Exception e) { System.err.println(e.awsErrorDetails().errorMessage());

The following head-object example command shows how you can use the Amazon CLI to retrieve metadata from an object. To run this command, replace the user input placeholders with your own information.

aws s3api head-object --bucket bucket-base-name--azid--x-s3 --key KEY_NAME

For more information, see head-object in the Amazon CLI Command Reference.