Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Query Params in AWS CloudFront

I have an AWS cloudfront ahead of an S3 bucket that contains my frontend app (https://myapp.com). When I go to https://myapp.com/experts?profession=carpenter through the navigation elements of my site (button in this case) everything works fine. But when I try to access this same url by manually entering the url from the navigation bar of the browser the problem appears. The query params disappear and only in the navigation bar is the following url without the query params https://myapp.com.com/experts.

My question is, how should I configure AWS cloudfront to allow me to pass query parameters?

Many thanks!

like image 995
AlejoDev Avatar asked Mar 03 '19 05:03

AlejoDev


People also ask

How do I pass a query parameter in CloudFront?

For web distributions, you can choose whether you want CloudFront to forward query strings to your origin and, if so, whether to cache your content based on all parameters or on selected parameters. By default, Cloudfront does not forward query strings, to improve the cache hit rate.

Does CloudFront cache query string?

If you don't forward query strings, CloudFront doesn't cache based on query string parameters.

Does CloudFront scale automatically?

CloudFront integrates with other AWS services that are built to scale massively. Together, the solution can automatically scale to millions of users by leveraging the global reach of CloudFront and the auto scaling capability of AWS platform.


2 Answers

For web distributions, you can choose whether you want CloudFront to forward query strings to your origin and, if so, whether to cache your content based on all parameters or on selected parameters.

By default, Cloudfront does not forward query strings, to improve the cache hit rate.

You can change that parameters in the behaviour definition, as per screenshot below.

screenshot

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/QueryStringParameters.html

like image 193
Sébastien Stormacq Avatar answered Oct 16 '22 11:10

Sébastien Stormacq


Now AWS has a different way to setup this, which is selected by default. The method Sébastien has mentioned in his answer is marked as "Legacy cache settings"

enter image description here

like image 40
Lahiru Chandima Avatar answered Oct 16 '22 10:10

Lahiru Chandima