How to configure cache-control headers for objects in a bucket during HTTP requests
Written by
Updated at November 27, 2023
Scenario description
You need to set up cache-control headers for objects in the bucket during HTTP requests.
Solution
You can add the Cache-Control
header to system metadata during the upload or modification of an object in the bucket. For more details about object metadata, see the documentation.
To add Cache-Control
to a previously uploaded object, you can use the s3cmd
utility.
To do this, run the following command:
s3cmd --add-header 'Cache-Control:3600' modify s3://<your-bucket-name>/object-name.
To add the Cache-Control
header during the object upload to the bucket using s3cmd
, specify the --add-header
parameter:
s3cmd --add-header 'Cache-Control:3600' put local_file s3://<your-bucket-name>/object-name.
Note
You can install and configure the s3cmd
utility following this guide.
You can also use the AWS CLI utility to add the Cache-Control header.
Example command for AWS CLI:
aws --endpoint-url=https://storage.yandexcloud.net s3 \
cp local_file s3://bucket_name --cache-control 'max-age=3600'