Score:0

How to serve both static and dynamic content via AWS cloudfront?

it flag

I have a site hosted on a digital ocean droplet which serves both static and dynamic content. The static content (e.g. /images, /js, /css, /fonts) is served from an s3 bucket with folders /images, /js, /css, /fonts via cloudfront which has a path pattern behaviour of Default (*). To use a custom url for this distribution i added an alternate name of assets-dev.example.com and added a cname record in my DNS control panel which points assets-dev.example.com to the cloudfront distribution. This part all works fine.

Now I want to serve the rest of my site e.g. dev.example.com which also serves dynamic content via cloudfront.

I tried to set up a custom origin using domain dev.example.com and added another alternate name for the distribution of dev.example.com

However in my DNS control panel I have an A record pointing dev.example.com to my digital ocean droplet and get an error if I try to add a cname record with dev.example.com pointing to the cloudfront url.

So my questions are:

  • What's the correct way to configure the DNS settings so that dev.example.com is returning content from cloudfront which then gets it from my custom origin digital ocean droplet?
  • There is an AWS tutorial on how to serve dynamic content using ec2 and cloudfront (https://aws.amazon.com/cloudfront/getting-started/EC2/) but doesn't go into the detail of configuring the DNS settings and his set up doesn't cache any content so not sure purpose not caching content in his tutorial serves?
  • If I have 2 origins defined (s3 and digital ocean droplet) and two alternate name (assets-dev.example.com and dev.example.com) how would cloudfront know from which origin to serve content from? Note in my site the url to return assets is defined as https://assets-dev.example.com/js/test.js etc

The only way I can think of is to set up an origin to be something like content.example.com and create an new dns record using that name which points to the digital ocean droplet. Then add a CNAME record e.g. dev.example.com which points to the cloudfront distribution. This way users can use dev.example.com to view the site content via cloudfront.

The only issue I have with the above set up is that anyone can bypass cloudfront by using content.example.com so how would any benefits such cloudfront ddos protect help in this scenario?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.