Case-sensitivity on AWS – redux

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.

Lion gargoyle

Loading similar posts...   Loading links to posts on similar topics...

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.

  •  Emphasize with italics: surround word with underscores _emphasis_
  •  Emphasize strongly: surround word with double-asterisks **strong**
  •  Link: surround text with square brackets, url with parentheses [text](url)
  •  Inline code: surround text with backticks `IEnumerable`
  •  Unordered list: start each line with an asterisk, space * an item
  •  Ordered list: start each line with a digit, period, space 1. an item
  •  Insert code block: start each line with four spaces
  •  Insert blockquote: start each line with right-angle-bracket, space > Now is the time...
Preview of response