0

The project has a domain name foobar.com pointing to a legacy system, hosting and serving mainly static files. The project got more complex over time and in AWS ALB certain /routes are pointed to particularly isolated micro-applications (for example, a nodejs api service, a php service like a cms, etc); all that deployed through AWS ECS. But today, I'd like to deploy a project that is just static files to s3+cloudfront (to take the CDN advantages and lower pricing) but use that same foobar.com + ALB and route /foobar path to the s3+cloudfront location. I haven't found a solution yet, and I'm not sure if this is possible to setup? What options exist there to solve my use case? So, the current state is that the main domain name is pointing to A record ALIAS dualstack-alb.

Cloudfront has the optional CNAME, but as mentioned above the domain name foobar.com is pointing to the legacy project container and only certain /routes elsewhere.

When a new distribution is created I get a foobar.cloudfront.net domain that I can use to access the deployed static files. But obviously that's not what I want and I'd like to use the main domain name foobar.com and when the /routeX is requested to point or serve the foobar.cloudfront.net. This is:

foobar.com > shows the legacy project, in ec2 container 1
foobar.com/cms > shows the cms project, in ec2 container 2
foobar.com/myNewProject/ > should show the X project, in s3

The following diagram demonstrates how this works or should work:

enter image description here

After the research I did so far, it seems that I have to point the main domain name A record to Cloudfront instead of having the A record pointing to ALB ALIAS dualstack.xxxxxxs-alb-xxxxx and have cloudfront /route point to s3. And everything else to the ALB. That's where my question comes from!

I'm just spying at the moment and can't seem to find how to set /route to s3 and everything else to the alb though! I can see the CNAME option in cloudfront but no route rules or anything like it.

0

After some research, looking at the documentation I found a solution!

First, we need to point the DNS A record to Cloudfront, so that Cloudfront process happens before anything else.

Second, we need to identify the content origin as described here (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesDomainName).

Third, we specify the path patterns (https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/distribution-web-values-specify.html#DownloadDistValuesPathPattern) to point to the content origin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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