Home > Amazon-AWS, HowTo > s3 set cache-control

s3 set cache-control

August 21st, 2015 Leave a comment Go to comments

Script to set cache control header to a large S3 bucket
Best let it run on the background. do

nohup /root/set_cache.sh > /root/set_cache.log &

p>Here is the code:


#!/bin/bash
#
#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
FILE="/root/s3_anuncio_PRD.lst"

while read DIR 
do

echo "--------------------------------------------------------------------------------"
timestamp
echo "Working on $DIR "
s3cmd --recursive modify --add-header="Cache-Control:max-age=2592000,public" $DIR
echo "Done"
#exit
done < $FILE

Categories: Amazon-AWS, HowTo Tags:
  1. No comments yet.
  1. No trackbacks yet.

VAMOVE *

*