dowjones123
dowjones123

Reputation: 3837

Use AWS S3 vs Cloudfront

Since heroku file system is ephemeral , I am planning on using AWS for static assets for my django project on heroku

I am seeing two conflicting articles one which advises on using AWS S3. This one says to use S3

https://devcenter.heroku.com/articles/s3

While another one below says, S3 has disadvantages and to use Cloudfront CDN instead

https://devcenter.heroku.com/articles/using-amazon-cloudfront-cdn

Many developers make use of Amazon’s S3 service for serving static assets that have been uploaded previously, either manually or by some form of build process. Whilst this works, this is not recommended as S3 was designed as a file storage service and not for optimal delivery of files under load. Therefore, serving static assets from S3 is not recommended.

Upvotes: 6

Views: 4105

Answers (3)

Tapaswi Panda
Tapaswi Panda

Reputation: 1051

Amazon CloudFront is a Content Delivery Network (CDN) that integrates with other Amazon Web Services like S3 that give us an easy way to distribute content to end users with low latency, high data transfer speeds.

CloudFront makes your static files available from data centers around the world (called edge locations). When a visitor requests a file from your website, he or she is invisibly redirected to a copy of the file at the nearest edge location (Now AWS has around 35 edge locations spread across the world), which results in faster download times than if the visitor had accessed the content from S3 bucket located in a particular region.

So if your user base is spread across the world its a better option to use CloudFront else if your users are localized you would not find much difference using CloudFront than S3 (but in this case you need to choose right location for your your S3 bucket: US East, US West, Asia Pacific, EU, South America etc)

Comparative features of Amazon S3 and CloudFront

Upvotes: 5

Yuval Adam
Yuval Adam

Reputation: 165340

My recommendation is to use CloudFront on top of Whitenoise. You will be serving the static assets directly from your Heroku app, but CloudFront as the CDN will take over once you reach scale.

Whitenoise radically simplifies build processes and the need to use convoluted caching headers.

Read http://whitenoise.evans.io/en/latest/ for the full manifesto.

(Note that Whitenoise is relevant only for static assets bundled with your app, not for user-uploaded files, which still require S3 for proper storage. You'd still want to use CF though.)

Upvotes: 3

andreimarinescu
andreimarinescu

Reputation: 3641

Actually, you should use both.

CloudFront only acts as a CDN, which basically means it caches resources in edge locations all over the world. In order for this to work, it has to initially download those resources from an origin location, whenever they expire or don't yet exist.

CloudFront distributions can have one of two possible origin types. S3 or EC2. In your case, you should store your assets in S3 and connect the bucket to a CloudFront distribution. Use the CloudFront links for actually serving the assets, and S3 for storage.

This will ensure the best possible performance, as well as correct and scalable load handling.

Hope this helps, let me know if you need additional info in the comments section.

Upvotes: 2

Related Questions