Search code examples
amazon-web-servicesamazon-s3amazon-cloudfrontcdn

Amazon S3 as cdn copying images from my server


I have searched a lot on this but all I get is using CloudFront (CDN) in collaboration with S3.

I want to do something different.

CloudFront works as a CDN with its Origin set to either my domain where images are, or S3.

If I set it to my domain, there is an issue of having my hosting space used.

If I use it with S3, the question is, how to get my images to S3 without much hassle? In case of CDN, this is automatic, as every call to CloudFront copies the image from my server automatically.

Is it possible that CloudFront works with S3 but if image is not present on S3, it copies it from my server to S3?

Or may be S3 itself works as CDN (best solution). I have seen on some sites that they use s3 urls for hosting their images, like this: https://retsimages.s3.amazonaws.com/14/A10363214_6.jpg

How is that possible?


Solution

  • If I set it to my domain, there is an issue of having my hosting space used.

    More expensive than the storage space is the cost of having a server sitting there ready to handle the request. Your application logic konws when the images change; that's the time to put them in S3.

    how to get my images to S3 without much hassle?

    There's an SDK for just about every language, so upload the image as it comes in. Use s3cmd sync to move the images you have. Then you can just turn off your server.

    Or may be S3 itself works as CDN

    CloudFront can use a customer provided dns name and matching certificate so that you can use a custom domain with https. It can integrate into AWS WAF which S3 cannot directly. Otherwise, CDN behaves similarly to s3. CloudFront should provide better caching and endpoint locality, but you'll see little functional difference at low volumes. Neither is read-after-write consistent, but Cloudfront caches additionally. Pricing is unlikely to make CloudFront cheaper for most uses.