Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an amazon cloudfront distribution with multiple origins conflict?

i have 2 different images in 2 websites at:

  • http://www.siteA.com/avatar.png
  • http://www.siteB.com/avatar.png

If i create an Amazon Cloudfront distribution with 2 origins: www.siteA.com and www.siteB.com and then i call for uniqueDistributionID.cloudfront.net/avatar.png, then which avatar.png will be returned? The one in siteA or the one in siteB?

Why & why not?

Trying to understand the potential of conflicts in Cloudfront distributions.

like image 401
Rakib Avatar asked Apr 05 '15 18:04

Rakib


People also ask

Can we have multiple origins in CloudFront?

You can configure a single CloudFront web distribution to serve different types of requests from multiple origins.

Can you have multiple CloudFront distributions?

See the S3 Bucket Names for CloudFront section below. You can create multiple distributions that reference the same S3 bucket. Only objects that have public-read access will be available for distribution. If you are using a CNAME, you must first be sure to register that domain with your DNS provider.

What types of origins are supported by Amazon CloudFront?

You can use several different kinds of origins with CloudFront. For example, you can use an Amazon S3 bucket, a MediaStore container, a MediaPackage channel, an Application Load Balancer, or an AWS Lambda function URL.

What is origin in CloudFront distribution?

An origin is the location where content is stored, and from which CloudFront gets content to serve to viewers. To specify an origin: Use S3OriginConfig to specify an Amazon S3 bucket that is not configured with static website hosting.


1 Answers

No, CloudfFront doesn't have a concept of a "conflict," because when you have a distribution with multiple origins, you have to define which path matches go to which origin.

CloudFront's path pattern matching is deterministic. It uses first match, not best match. Whichever pattern matches first is the one that will be used, even if that path is a dead-end at the origin server.

When CloudFront receives an end-user request, the requested path is compared with path patterns in the order in which cache behaviors are listed in the distribution. The first match determines which cache behavior is applied to that request.

http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern

Update

CloudFront now supports a concept of Origin Groups, which allow any given Cache Behavior to send a request to one origin, and then -- if one of the error types that you specify (e.g. 404 or 503) is returned by the first origin, then CloudFront will attempt to fetch the content from a second origin. This can be used for failover, but it can also be used for cases where you want CloudFront to try one origin, and then another. The two origins in the origin group are tried, in order, for every cache miss. If either origin returns a cacheable response, that response will be stored in the cache.

like image 196
Michael - sqlbot Avatar answered Oct 22 '22 14:10

Michael - sqlbot