Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My application uses all 3 service layers. Recent feature request to lower the outgoing traffic gives us some uncertainties.

Say, we have a requirement to distribute the image.jpg file with CloudFront. It's all good while there's no dynamic image resizing. Now that we don't need the original size of the image all the time we pass desired variable dimension along with the query string (image.jpg?w=100&h=100).

If we would have routed CF to EC2 directly, then there would not be any problems at all. But, we should have the S3 in between, since EC2 is too small to store media materials.

So the question is - how do you push inexistent file to S3 during the request?


share|improve this question
Did you actually manage to complete this setup? I am trying something similar where I want to CF to first check if a file is in S3 and if it's not there, to route the request to EC2, so the EC2 would then generate the file, return it and at the same time save it to S3 for future use. I'm trying to accomplish this with multiple origins but without luck. When the file is not in S3, CS immediately returns a 403 error instead of falling back to the next origin. – Jacket May 13 at 11:43

I don't think you need (or would want) to reroute the request after getting a 404 from the S3 bucket. You'd then be making two requests sequentially and slowing things down.

CloudFront does supports multiple origin servers. Don't think of it as S3 between CloudFront and EC2, but S3 next to EC2. Take a look here:

Origin Servers

You can configure one or more origin servers for your Amazon CloudFront download distribution. Origin servers can be an AWS resource, such as Amazon S3, Amazon EC2, Elastic Load Balancing, or a custom origin server outside of AWS. Amazon CloudFront will request content from each origin server by matching the URLs requested by the viewer with rules you configure for your distribution. This feature allows you the flexibility to use each AWS resource for what it’s designed for – Amazon S3 for storage, Amazon EC2 for compute, etc. – without the need to create multiple distributions and manage multiple domain names on your website. You can also continue to use origin servers you already have set-up without the need to move data or re-deploy your application code.

There's also a nice blog post about setting up multiple origins here.

share|improve this answer
This is awesome! How come we've missed this?! Anyway, will give it a go and tell you the outcome. – Aleksandr Makov Feb 20 '14 at 19:19
@AleksandrMakov Took me a bit to find anything on it actually. It doesn't seem to be outlined in the docs. If you stumble upon anything more detailed, please let me know! – Tanner Faulkner Feb 20 '14 at 20:22

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.