Using HeadObject with directory buckets - Amazon Simple Storage Service

Using HeadObject with directory buckets

The following AWS SDK and AWS 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 AWS 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 AWS CLI Command Reference.