Reputation: 444
Let me explain dilemma. I use 3 services from Amazon: EC2, S3 and CloudFront. EC2 receives an file as upload, stores it in the S3 bucket. Then CloudFront mirrors the S3 bucket. The only limit is to have user friendly URLs. Which approach to deliver those files is better?
Client > CloudFront > EC2 > S3
Client > EC2 ... redirect ... CloudFront > S3
There are two dimensions for this: the speed and the cost.
I see facebook using the second approach when serving profile images http://graph.facebook.com/platform/picture
Upvotes: 4
Views: 1648
Reputation: 71384
I personally would just give the files a nice name and a proper content type metatag in S3 when first doing the file upload and, as such, remove your EC2 instances from the download path altogether. You would just serve the clean-url to you client in your HTML content and that clean URL will point directly to you resources in Cloudfront/S3, which has the proper metatags to serve up the desired content-type header.
Upvotes: 1
Reputation: 5649
You certainly don't want to force the file transfer between S3 and your client to go through your EC2 instance. That will add load to the EC2 instance, increase bandwidth usage, and undoubtedly slow the response to the user.
Your EC2 instance gives you the greatest control over URL format, so you'll want the client to make the initial request to it (to have a "user-friendly" URL). The EC2 instance can just send the client a redirect to the CloudFront or S3 URL that actually has the content, and the client will pull it directly from there without the further involvement of EC2.
I wouldn't bother with CloudFront unless you have an enormous number of requests, or network latency has to be as low as possible.
Upvotes: 2