I have Next.js Application that is deployed as Lambda Edge and Cloudfront that has S3 static files as origin. AWS Cloudfront URL is the value of example-domain.com CNAME.
Now I have a lot of changes to the Application and I want to deploy those changes. I don't want these changes to be override current deploy, instead I would like to create new environment and that environment should be available in few countries.
So in this case I would have 2 different Cloudfront URLS:
- oldfeatures.cloudfront.net
- newfeatures.cloudfront.net
Different origin url should be served depending on the geoloaction.
I am not sure that this is the right approach, but I am open for suggestions.
I am managing the domain settings in Cloudflare, all the rest is AWS environment.
How can I achieve this, without making changes to the Applications code.
The easiest (and cost-effective) option would be to create a Cloudflare (CF) Worker and attach it to your subdomains. Probably better to attach it to both subdomains to ensure they can't access the
newfeatures.cloudfront.netURL manually if they are 'not allowed' to. The second option would be to use CF Traffic Steering that comes with the CF Load Balancers feature. This option comes at a small cost and might not really fit your use case - it redirects based on regions rather than countries - I believe you'd need to fork more money and get an enterprise account for country based steering.That said, the following option using a CF Worker JavaScript, will require you to have CF Proxy (the orange cloud) turned on.
Here are 3 options to satisfy your requirements - Recommending option 1 based on my understanding of your question.