Score:0

S3 / Cloudfront / Load balancer Architecture explanation needed

id flag

My architecture is like so: I have a static website xyz.com hosted on s3 and served with cloudfront. The website is accessing an api that seats behind a load balancer. I want to make sure that only requests from my website xyz.com are allowed thorough my load balancer to my api. I thought that the flow is user -> cloudfront -> load balancer - so I added a rule on my load balancer's security group to only allow http access if it comes from cloudfront via prefix list for Amazon CloudFront.

This prevents my website from accessing the load balancer. So, I guess I was wrong, and the flow is that the user (browser) sends the request to the api and not cloudfront (So cloudfront is only sharing the website's assets for rendering)? Am I correct? If so, is there a way to make sure that only requests from my website go through?

Tim P avatar
af flag
If the web site is static, it is not making the request to the API. My guess is that it is a client side script (i.e. Javascript) that is making the call to the API. So you can look into authentication options or refer options for filtering. If it truly is a client side call to the API you are going to have a harder time limiting access to only users of your web site.
Score:1
gp flag
Tim

From what you've said CloudFront is in front of S3, rather than in front of your API. You can put CloudFront in front of your API if you want to, but you have to choose to do that. From memory, that's done in the API Gateway console / API.

It sounds to me like the user accesses S3 via Cloudfront which returns a web page. The web page then accesses the API for additional information. One solution is to authenticate user access to the API (AWS docs link) such as using AWS Cognito or a lambda authorizer.

If you don't want users to log in you're going to have to do some research about application authentication vs user authentication, or hope someone else gives an answers that helps.

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.