Setting Object Headers
This guide explains how to set headers for S3 objects using s3cmd and aws s3api. This is useful for managing caching, adding custom metadata, and optimizing bucket data handling.
Setting Headers via Control Panel Copy link
- Go to the S3 storage section and click on the bucket.
- In the Objects tab, click on the three dots next to the object and select Edit metadata.

- Add necessary headers. To set up a custom header, click +Add.

Setting Headers via CLI Copy link
Another way to configure headers is to use utilities like s3cmd or s3api.
Setting a Header for a Single Object Copy link
To set a header for a specific object, use the s3cmd modify command. For example, to add a Cache-Control header to a specific object:
s3cmd modify s3://<bucket_name>/<object_name> --add-header="cache-control:max-age=7000"In this case, the object will receive the Cache-Control header with the max-age=7000 parameter, instructing browsers or proxy servers to cache the object for 7000 seconds.
Setting Headers for All Objects in a Bucket Copy link
To set headers for all objects in a bucket, you can use the --recursive option to apply changes to all files:
s3cmd modify --recursive s3://<bucket_name> --add-header="cache-control:max-age=7001"This command recursively adds the Cache-Control header with the value max-age=7001 to all objects in the bucket.
Creating a Custom Header Copy link
To add custom headers, use the s3cmd modify command with the x-amz-meta prefix:
s3cmd modify s3://<bucket_name>/<object_name> --add-header="x-amz-meta-test-header:test"This creates a custom header x-amz-meta-test-header with the value test. In the object's metadata, the header will appear without the x-amz-meta- prefix, resulting in:
"Metadata": {
"test-header": "test"
}This allows you to store additional data in the object, which can be useful for processing or logging.
Verifying Set Headers Copy link
To verify the headers, use the aws s3api head-object command. This ensures that all headers and metadata have been successfully added:
aws s3api head-object --bucket <bucket_name> --key <object_name> --endpoint-url https://s3.hmstorage.netThe command will return information about the object, including its metadata and headers, allowing you to confirm that the changes were applied correctly.