1

I am a beginner of AWS. I already know how to setup EC2, ELB, S3 and CF.

Now I have a question in my mind about how cloudfront request will be processed when an ELB with multiple instances (instance0 and instance1) set as Cloudfront origin.

Consider a request came to Cloudfront edge like following:

http://distributionId.cloudfront.net/profile_pic_1.png

For the first time, request goes to ELB. ELB passes the request to either instance0 or instance1. But "profile_pic_1.png" exist in only instance1. So in this situation is there any possibility to get 404 error from CF.

My Objective: I have to create an upload server. So there will be many instance of upload server behind an ELB. That ELB set as origin of CF. When user uploads a photo it will be saved temporarily in instance's storage with public access. When upload finishes I will provide cloudfront URL of the uploaded image to user. In this case will user get proper response from CF ?

1 Answer 1

4

For the first time, request goes to ELB. ELB passes the request to either instance0 or instance1. But "profile_pic_1.png" exist in only instance1. So in this situation is there any possibility to get 404 error from CF.

Yes, in that instance there would be a 50% chance of CloudFront getting a 404 response instead of the image, and CloudFront would simply pass that error response along to the client. You do not ever want to put instances with different content behind a load balancer.

What you are missing from your design is Amazon's S3 service. You should upload all the images to S3 instead of your EC2 servers. And you should configure CloudFront to pull the images directly from S3.

2
  • Hi Mark... Probably you read my objective. I know I can use S3 bucket. To store in S3 bucket I need to upload to ec2 instance at first and then transfer from ec2 instance to S3 bucket. Isn't ? There is way to upload directly form client to S3 bucket. In that case client got S3 credentials which is not acceptable. So what is your advice in this case ? (I am using Node.JS as backend) Commented Apr 18, 2016 at 3:41
  • You can upload through an EC2 instance if you want. Or you can use S3 pre-signed upload URLs allowing your users to upload directly to S3 without exposing your AWS credentials. Either way, serving the images via S3 is still going to be preferable.
    – Mark B
    Commented Apr 18, 2016 at 4:50

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