I recently started using Amazon S3 to serve images to my visitors since this will reduce the server load. Now, there is a new problem: Today I looked into my AWS billings. I noticed that I have a huge bill waiting for me - there has been a total of 4TB AWS Data Transfer in 20 days.
Obviously this is because the high amount of outgoing Amazon S3 traffic (to Cloudflare which then serves it to the visitors). Now I should to reduce the amount of requested files by setting a Cache header (since Cloudflare's Crawler will respect that). I have modified my code like this:
$s3->putObjectFile($path, $bucket , 'images/'.$id.'.jpg', S3::ACL_PUBLIC_READ);
to
$s3->putObjectFile($path, $bucket , 'images/'.$id.'.jpg', S3::ACL_PUBLIC_READ, array('Cache-Control' => 'public,max-age=31536000'));
Still, it does not work. Cloudflare does not respect the Cache because the Cache-Control does not show up as "Cache-Control" in the Header but instead as "x-amz-meta-cachecontrol". Cloudflare ignores this.
Does anyone have an easy solution for this?
TL;DR: I have more or less the same problem as this guy: http://support.bucketexplorer.com/topic734.html (that was in 2008)
EDIT: I have stumbled upon this: Amazon S3 not caching images but unfortunately that solution does not work for me.
EDIT 2: Turns out it didn't work because I was using an old version of the "Amazon S3 class". I updated and the code works now.