A couple of times now I’ve been “caught out” by the fact that I’m a Windows guy and AWS is Linux-based. Or, to put it another way, I’m used to case insensitivity with file names (so foobar.txt
and FooBar.txt
are the same file), whereas AWS is case-sensitive (those two names are for different files).
When this invalid assumption first hit me, I cheated and just duplicated the folder structure with lower-case file names for the website where the issue was happening. Later on, I wrote a Lambda@Edge function that converted all file requests to lower-case and installed it for my websites. All I needed to do then was to upload the files with lower-case names.
Time passed.
And then I ran into a security header problem and remembered that AWS had added request/response functions directly to CloudFront. No more Lambda@Edge needed, at least for my simple cases. In that blog post, I forgot to say that I’d also removed the Lambda@Edge function that converted file names to lower-case, and made it a CloudFront function instead.
Here is that CloudFront function code for completeness’ sake:
function handler(event) {
var request = event.request;
var cleanPath = request.uri.toLowerCase();
// console.log("clean path is : " + cleanPath);
var htmlIndex = cleanPath.indexOf(".html");
if (htmlIndex !== -1) {
request.uri = cleanPath;
// console.log("request uri is : " + request.uri);
}
return request;
};
Basically: if it’s a request for an HTML file, convert the requested file name to lower-case and proceed. Other files, such as images, did not suffer from this need for case-sensitivity, at least in my sites. Your mileage may vary, etc.
No Responses
Feel free to add a comment...
Leave a response
Note: some MarkDown is allowed, but HTML is not. Expand to show what's available.
_emphasis_
**strong**
[text](url)
`IEnumerable`
* an item
1. an item
> Now is the time...
Preview of response