iamcrypticcoder
iamcrypticcoder

Reputation: 2899

AWS ELB with multiple instances as Cloudfront origin

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 ?

Upvotes: 1

Views: 584

Answers (1)

Mark B
Mark B

Reputation: 201088

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.

Upvotes: 4

Related Questions