Trying to invalidate an AWS cloudfront path that contains a tilde ~ character results in an invalid argument error. A tilde is a valid URL character, and invoking things like encodeURI
or encodeURIComponent
against strings that contain it do not encode it.
I've tried encoding the tile as %7E in the invalidation URL. This does not yield an invalid argument error, but it does not invalidate the path for the desired file either.
I've been able to work around this by finding the first index of ~, replacing it with a *, and chopping off the rest of the string afterward. This creates the needed invalidation, though not the desired invalidation, as it can also invalidate paths that may be optimized by remaining cached.
AWS Support says that this is an issue with invalidating paths that contain special characters, that they are aware of the issue, and are actively working toward a solution.
The reason that %7E doesn't work is because cloudfront caches it separately from the tilde.