I have an AWS Elastic Beanstalk instance that deals with search queries from my application, and a AWS CloudFront instance that caches duplicate queries because its cost a lot less if CloudFront can satisfy request rather than Elastic Beanstalk.
Currently the CloudFront behaviour uses the Legacy Cache Settings option and is set to include All Query strings. This is need because this is where the search query is
e.g
?license1=licensekey&type=release&query=reid:12345564 AND src=22&limit=1&offset=0
but notice I have one parameter called license1 and I want it to ignore this so that two queries with a different license key
?license1=123456&type=release&query=reid:12345564 AND src=22&limit=1&offset=0
?license1=i979798&type=release&query=reid:12345564 AND src=22&limit=1&offset=0
will both retrieve the same cached element from CloudFront, but currently I just set it to the same value for everyone because I don't know how to do this. The license1 field is only of interest to ElasticBeanstalk, and I want CloudFront to ignore this.
I was looking at the Create Custom Cache Policy option and this has an additional option of Include all query strings except and I was hoping I could use to just ignore the license1 parameter but I'm not sure works this way, I don't understand what I have to enter as the query String here.
I have resolved the issue
Create another policy to use as the Origin request policy, this determines what is sent to the server if CloudFront has a miss. If not specified it will use the Cache policy and therefore strip out the license1 field which we don't want, so for this one we set Query strings - All
Then we use both in our CloudFront instance
I also then temporarily enabled Standard Logging in CloudFront and did some tests to ensure that including license1 with different values from different users still allowed for a Hit if the actual search query was the same. Its slightly confusing because the CloudFront logs show the url with license1 included even though ignored by CloudFront, but it worked as expected
And I also checked server to ensure the license1 value was coming through when CloudFront had a miss.