- Newest
- Most votes
- Most comments
@CorinJA you can't do that via DNS configuration for the reason I mentioned. However, what you're describing should be possible by using the continuous deployment feature of CloudFront to distribute requests between two different distributions. The DNS name should point to the "production" (current) distribution, and once received there, the CD configuration will send a percentage of traffic to the associated "staging" distribution.
The continuous deployment feature is explained in the release blog post: https://aws.amazon.com/blogs/networking-and-content-delivery/use-cloudfront-continuous-deployment-to-safely-validate-cdn-changes/ and in more detail in documentation: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/continuous-deployment.html
Hello.
CloudFront cannot be accessed with a custom domain unless an alternative domain is set, so I don't think it is possible to route between multiple CloudFront using weighted routing.
Therefore, as you know, I think the only option is to use one CloudFront and route using CloudFront Functions or Lambda@Edge.
I think the following documents will be helpful.
https://aws.amazon.com/developer/application-security-performance/articles/a-b-testing/?nc1=h_ls
Specifically, each DNS name has to belong to at most 1 CloudFront distribution at a time. Otherwise, when any random CloudFront edge location received a request for the name, it'd have no way of knowing which of the multiple distributions should process it. That's why it's logically impossible to spread a single name across multiple distributions and achieve controlled behaviour (like weighted routing).
Thanks, that is slightly helpful although not the answer.
I essentially do have an A/B testing scenario where I want to roll-out a new version of my app to users who will be acessing it largely from a link on my homepage. I want to weight traffic initially so that only a small percentage see the new app.
How this differs from all of the examples I have seen using CloudFront distributions is that I am dealing with a wholly new app - hosted in its own S3 bucket - not just variants on the same site like images or even data layer variance.
I just want to route a percentage of traffic from an arbitrary URL to one subdomain and a percentage to another.
So this is the code I am using to implement a redirect in my PoC and it does seem to be working. I have this as a CloudFront Function:
function handler(event) { var request = event.request; var headers = request.headers; let response = {}; var url = Math.random() < 0.2 ? 'https://new.sandbox.mydomain.com/' : 'https://classic.sandbox.mydomain.com/'; response = { statusCode: 302, statusDescription: 'Found', headers: { "location": { "value": url } } } console.log(`Redirecting to ${url}`); return response; }Not sure if there's a cleaner way to do it but seems to be working. I'm just setting up some logging now to monitor the traffic here.

This looks really good, thanks. I'm just building a POC on this and if that's successful I will mark this as the Accepted Answer.
Well, I've set up a POC for this. I am disappointed that the maximum weight of traffic that can be sent to the Staging distribution is 15%. However, I am not yet seeing any traffic going through to the Staging distribution, so I am not sure how useful this is for a canary deployment.
There are some limitations with the CD feature, it seems. This documentation article mentions that during times of high utilisation of CloudFront itself (rather than traffic destined for your site specifically), all requests may get sent to the production distribution: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/continuous-deployment-quotas-considerations.html#all-requests-to-primary-distribution
I set up my CF distributions again in case I had made a mistake. What I get now is the Primary returned the first time I visit the site, and then on refresh the dreaded
ERR_SSL_VERSION_OR_CIPHER_MISMATCHerror. I am using a wildcard SSL certificate for the distributions, and a subdomain registered as a CNAME record in Route53.Are you using a certificate issued by AWS Certificate Manager (ACM) or an imported one issued by an external certificate issuer, such as DigiCert? To keep users locked to the distribution they got sent to initially, you could configure session stickiness: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/understanding-continuous-deployment.html#understanding-continuous-deployment-sessions