Getting Information About the Metadata of an Object

You can get information about the metadata of an object without actually downloading it.

To use this command, you must have read permission on the object. For more information, see Managing Access to Your Objects.

Getting Information About the Metadata of an Object Using AWS CLI

Before you begin: Install and configure AWS CLI. For more information, see Installing and Configuring AWS CLI.

To get information about the metadata of an object, use the head-object command following this syntax:

Request sample
$ aws s3api head-object \
    --profile YOUR_PROFILE \
    --bucket BUCKET \
    --if-match "\"12345a6b76656da1b64f287c8627af7\"" \
    --if-modified-since "2022-01-20" \
    --if-none-match "\"12345a6b76656da1b64f287c8627af7\"" \
    --if-unmodified-since "2022-01-20" \
    --key OBJECT \
    --version-id "12345" \
    --part-number "1" \
    --endpoint https://oos.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • bucket: The name of the bucket in which the object is stored.

  • (optional) if-match: Requests the object only if its ETag matches the ETag you specify for this attribute.

  • (optional) if-modified-since: Requests the object only if it has been modified after the date (in ISO 8601 format) you specify for this attribute.

  • (optional) if-none-match: Requests the object only if its ETag does not match the ETag you specify for this attribute.

  • (optional) if-unmodified-since: Request the object only if it has not been modified since the date (in ISO 8601 format) you specify for this attribute.

  • key: The name of the object you want to retrieve the metadata from.

  • (optional) version-id: The ID of the version of the object you want to retrieve the metadata from. For more information, see Using Bucket Versioning.

  • (optional) part-number: The part number of the upload (between 1 and 10000, both included). For more information, see Using Multipart Upload.

  • endpoint: The endpoint corresponding to the Region you want to send the request to. For more information, see Installing and Configuring AWS CLI.

The head-object command returns the following elements:

  • DeleteMarker: If true, specifies that the retrieved object is a delete marker. For more information, see Listing the Versions of an Object.

    If false, the element is not returned in the output.

  • AcceptRanges: Specifies the type of range requests that the server supports for the object.

  • Expiration: If a lifecycle rule has been applied to the object, returns details on its configuration. For more information, see Managing the Lifecycle of Your Buckets.

    • expiry-date: The date and time at which the object is set to expire.

    • rule-id: The name given to the lifecycle rule.

  • LastModified: The date and time at which the object was last modified.

  • ContentLength: The size of the object, in bytes.

  • ETag: The ETag of the object.

If the high-level s3 command was used to upload the object in a bucket and if that object was sufficiently large (usually 5 MB or more), the number of parts making up the reconstructed object will be contained in its ETag. This is indicated by a hyphen and the corresponding number at the end of the ETag (for example, the object was split in 15 parts if the ETag ends with -15). For more information, see Tutorial: Using Multipart Upload With AWS CLI (s3).

  • MissingMeta: In the case of unconventional headers, the number of metadata entries not returned.

  • VersionId: The ID of the version of the object you requested to retrieve.

  • CacheControl: Specifies the adequate caching directives when handling the object.

  • ContentDisposition: Indicates how the content is displayed.

  • ContentEncoding: The encoding format of the object.

  • ContentLanguage: The language the content of the object is in, in language code.

  • ContentType: The MIME (Multipurpose Internet Mail Extensions) type of the object.

  • Expires: The date and time at which the object can no longer be cached, and is considered stale.

  • WebsiteRedirectLocation: If the object is located in a bucket that has been configured as a website, specifies the URL. For more information, see Managing a Bucket Website.

  • Metadata: A map of additional metadata entries you may have specified.

    • key: The name of the metadata.

    • value: The value of the metadata.

  • PartsCount: If you specified a part-number attribute in your request, the number of parts composing the object. For more information, see Using Multipart Upload.

  • ObjectLockMode: If Object Lock was enabled on the bucket containing the object, specifies its mode. For more information, see Configuring a Default Object Lock on Your Bucket.

  • ObjectLockRetainUntilDate: If a retention period has been set on an object, specifies the date during which the object is locked. For more information, see Configuring a Specific Object Lock on an Object.

Result sample
{
    "DeleteMarker": true,
    "AcceptRanges": "bytes",
    "Expiration": {
        "expiry-date": "Thu, 20 Jan 2022 13:18:18 GMT",
        "rule-id": "id"
    },
    "LastModified": "Thu, 20 Jan 2022 13:18:18 GMT",
    "ContentLength": 1534068,
    "ETag": "\"15943a31a76656da1b64f287c8627af7\"",
    "MissingMeta": "2",
    "VersionId": "12345",
    "CacheControl": "no-cache",
    "ContentDisposition": "inline",
    "ContentEncoding": "gzip",
    "ContentLanguage": "en",
    "ContentType": "application/pdf",
    "Expires": "Thu, 20 Jan 2022 13:18:18 GMT",
    "WebsiteRedirectLocation": "example.com",
    "Metadata": {
        "key": "value"
    },
    "PartsCount": "4",
    "ObjectLockMode": "COMPLIANCE",
    "ObjectLockRetainUntilDate": "2023-11-18T08:23:48.027000+00:00"
}

Related Pages

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.