Questions about using Amazon CloudFront and / or S3 as an image server (compared to the standard Apache server)

Currently, I have a website that serves dynamic (PHP-MySQL) content from the Apache server and serves static content (JavaScript, images) from a separate Lighthttpd server.

For scale reasons, I would like to use Amazon Cloudfront and possibly S3. Honestly, I'm not quite sure how S3 or CloudFront works. I'm used to the normal server behavior of “downloading a file ... it becomes available”, and the S3 buckets and CloudFront edge mirroring are complex.

I need a better understanding of how this works, and you have a few questions:

1) I do not want to store images on my servers. I want them to be completely in the cloud. Is it right that this means that I will need to use S3 for storage as the "source server"? Will CloudFront alone not enough? Is CloudFront just an edge-CDN service?

2) We are currently uploading images via a PHP script that transfers them via FTP to our image server or via FTP upload manually. How will this change if I use S3? I heard that you can not use FTP ?: (

3) If you use S3, can I create hierarchical directories and store images inside them? Images are stored in different folders deeply and I can’t afford to change the code, but did I hear that the S3 was a flat “bucket”?

4) Finally, I heard that with CloudFront, if the file changes, you need to issue an invalidation request that costs money. Is this because CloudFront caches the image from the source? I'm not used to it, because in my current setup I just replace the image via FTP and it is updated! Is there no way to imitate this classic behavior?

Thanks sincerely for your help.

+8
php apache amazon-s3 amazon-cloudfront
source share
2 answers

1) I do not want to store images on my servers. I want them to be completely in the cloud. Is it right that this means that I will need to use S3 for storage as the "source server"? Will CloudFront alone not enough? Is CloudFront just an edge-CDN service?

S3 is designed for long-term and reliable data storage with eleven 9s of durability. Buckets (as they are called) are region-specific and live in one of Amazon 's regional data centers .

Conversely, CloudFront is designed as a series of edge servers. By default, when you request an object (i.e. a File) from the CloudFront host name, this object is pulled out of the place of origin and cached at the nearest EdgeFront location for 24 hours (this can be configured programmatically). After 24 hours, the cache expires and CloudFront pulls out a new copy the next time the object is requested.

A common setting is to configure CloudFront to use S3 as the source location. CloudFront also has the ability to use any server if that is what you prefer (it seems like not).

2) We are currently uploading images via a PHP script that transfers them via FTP to our image server or via FTP upload manually. How will this change if I use S3? I heard that you can not use FTP ?: (

S3 is not an FTP server, so it does not talk about the (S) FTP protocol. However, almost all Mac OS X FTP clients include Amazon S3 support. Amazon S3 has a web service API, so you can automate push using one of the AWS SDKs if you want.

One tool, Cyberduck , does SSH, SFTP, FTP, Amazon S3, and some other things. It is available for both Mac and Windows. There are also other tools that provide a graphical interface for uploading to S3 as easy as if you were uploading via FTP.

3) If you use S3, can I create hierarchical directories and store images inside them? Images are stored in different folders deeply and I can’t afford to change the code, but did I hear that the S3 was a flat “bucket”?

Yes and no.

Yes, S3 is a flat file system, but files can have slashes in their names. For example, "abc / def / ghi / jkl.txt" is actually not 3 folders and a file, but a single file with a slash in the file name. Most GUI tools allow you to visualize this as folders and subdirectories, and the S3 URL looks just like any other URL. Speaking personally, I have never had to do something different for S3 than I did for SFTP.

4) Finally, I heard that with CloudFront, if the file changes, you need to issue an invalidation request that costs money. Is this because CloudFront caches the image from the source? I'm not used to it, because in my current setup I just replace the image via FTP and it is updated! Is there no way to imitate this classic behavior?

Right Because CloudFront caches the source file to the nearest edge server. By default, the expiration is 24 hours, but you can set it to 1 hour or even faster to expire with an "expression of invalidity." I saw that it takes 3 to 15 minutes, because CloudFront needs to check all the edge servers to make sure they are all cleaned up.

If you do not want to cache, you can simply use S3 directly. This is the closest equivalent to replacing an image via FTP, but then you lose all the benefits of using CDN in the first place.

According to Amazon CloudFront pricing page :

"No extra charge for the first 1000 files that you request for invalidation each month is $ 0.005 for each file indicated in your invalidation requests thereafter."

This half penny for each file is invalid for more than 1000 per month. I use CloudFront regularly and never cross this limit, but if you use a large site with a lot of changes, then this is certainly possible.

Hope this helps! :)

+18
source share

I tested a number of client applications and found that CloudBerry S3 Explorer for Windows and CrossFTP for Mac are more powerful than Cyberduck, but I work a lot with private video and audio streaming, so my requirements are slightly higher than displaying images on a site.

But to answer your last question, you can drag the folder with subfolders into the bucket, the hierarchy is respected. You can work with folders in a bucket, just as you work with FTP. But you must make sure that your images are open to the public or your images will not be displayed.
Standard, any file is uploaded as a private file, which requires a signed URL. But with the client application, you can set bucket inheritance so that files become automatically public. You can find a lot of information about this here: http://www.miracletutorials.com/category/s3-amazon-cloudfront/

Cheers, Rudolph +++

0
source share

All Articles