Is there a way to add cache control in AWS S3?

+2 votes
I have moved about more 10000 files to AWS S3 using s3cmd command. Is there a way to add cache control in S3 for all the images.

if my files are reside ( s3://bucket-name/images/ ). How do i proceed?
Apr 10, 2018 in Cloud Computing by code_ninja
• 5,980 points
563 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
+1 vote

use of  current upstream master branch will help for sure. use this github repository: https://github.com/s3tools/s3cmd. Next refer this command for the solutions

./s3cmd --recursive modify --add-header="Cache-Control:max-age=86400" s3://yourbucket/
I hope this helps 
answered Apr 10, 2018 by hemant
• 5,750 points
0 votes

To adjust metadata such as cache-control on an object in S3 without having to re-upload it and without having to use any third party tools, you can do the following with the AWS CLI. It copies the object to itself while overriding the metadata with your chosen settings:

aws s3api copy-object --copy-source <bucket-name>/<file> --bucket <bucket-name> --key <file> --metadata-directive REPLACE --cache-control "max-age=3600"

Process this command in a find to do it on an existing set of files that already exists in the bucket as you mention:

find . -type f -exec aws s3api copy-object --copy-source <bucket-name>/{} --bucket <bucket-name> --key {} --metadata-directive REPLACE --cache-control "max-age=3600"

replace <bucket-name> with the name of your bucket

WARNING: this will overwrite all your existing metadata on the files such as acl, just add additional flags to the command e.g. --acl public-read to set what you need.

answered Sep 6, 2018 by eatcodesleeprepeat
• 4,670 points

Related Questions In Cloud Computing

0 votes
1 answer

Is there a way to find out the number of objects stored in an S3 bucket?

Frankly, that is not possible. This is ...READ MORE

answered Apr 17, 2018 in Cloud Computing by code_ninja
• 5,980 points
25 views
0 votes
1 answer

Is there a way to transfer files between AWS s3 and ec2

The answer is a definite yes yes. ...READ MORE

answered Apr 17, 2018 in Cloud Computing by brat_1
• 7,080 points
35 views
0 votes
1 answer

AWS: Is there a way I can edit files in S3 right away in the browser?

There is not currently an AWS-supported method ...READ MORE

answered Jun 19, 2018 in Cloud Computing by Meci Matt
• 9,400 points
20 views
+1 vote
1 answer

How to add cache control in AWS S3?

Use modify command along with s3cmd  to ...READ MORE

answered Jul 25, 2018 in Cloud Computing by Gopalan
• 1,260 points
59 views
+3 votes
3 answers

Is there a way to install apache drill on an EMR cluster on AWS that is already Running?

It looks to be trying to get ...READ MORE

answered Oct 11, 2018 in Cloud Computing by findingbugs
• 4,750 points
233 views
0 votes
1 answer

Is there a way to test codes that are written against AWS API?

Please note that you should not integrate ...READ MORE

answered Apr 17, 2018 in Cloud Computing by brat_1
• 7,080 points
12 views
0 votes
2 answers

Is there a way to copy AMI from one AWS account to another AWS account using boto?

You could share the AMI from one ...READ MORE

answered Aug 21, 2018 in Cloud Computing by Priyaj
• 56,140 points
223 views
0 votes
1 answer

Is there a way to use amazon ECR image from one account in the code build of another account?

These forums might just about help https://forums.aws.amazon.com/t ...READ MORE

answered May 7, 2018 in Cloud Computing by brat_1
• 7,080 points
112 views
+3 votes
5 answers

AWS EFS vs EBS vs S3 (differences & when to use?)

EFS is: May not yet be available in ...READ MORE

answered Apr 9, 2018 in Cloud Computing by hemant
• 5,750 points
895 views
+1 vote
2 answers

I want to Migrate from Oracle RDBMS to AWS S3 using Kinesis

Try to understand AWS Schema Conversion Tool ...READ MORE

answered Apr 20, 2018 in Cloud Computing by hemant
• 5,750 points
303 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.