Script to set cache control header to a large S3 bucket
Best let it run on the background. do
nohup /root/ > /root/set_cache.log &
p>Here is the code:

#set cache_control header on large buckets using s3cmd
#Felipe Ferreira
# Pre-Req s3cmd and aws-cli
#1. list directory and put into a clean file, I did this way: (could have done it with s3cmd)
#aws s3 ls s3://lalal-bucket// > /tmp/list.txt
#2. clean up and adjust list
#cat /tmp/list.txt |awk '{ print $2 }' |awk -F "/" '{ print "s3://lalal-bucket//"$1 }' > s3__PRD.lst
function timestamp() {
  date +"%T"
#Now open the file and set each permission
while read DIR
echo "--------------------------------------------------------------------------------"
echo "Working on $DIR "
s3cmd --recursive modify --add-header="Cache-Control:max-age=2592000,public" $DIR
echo "Done"
done < $FILE

Leave a Reply

Your email address will not be published. Required fields are marked *