A CloudFront Function to remove a specific value at the beginning of an URL
Lucien Boix
Posted on January 25, 2023
My usecase was :
- the CDN was delivering images from a S3 bucket
- the images URL pattern was
https://URL/images/something.jpg
- there was not an "images" folder at the root of the S3 bucket, images like
something.jpg
were directly there
So I used this function and associated it to the right Behavior ("Viewer request" option) of my CloundFront Distribution :
function handler(event) {
var request = event.request;
if (request.uri.startsWith("/images/")) {
request.uri = request.uri.substring(7);
}
return request;
}
Let me know if that helped you or if you have suggestion for improvements. Take care !
š šŖ š
š©
Lucien Boix
Posted on January 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
aws Mastering AWS Microservices Architecture for High-Traffic Systems: Interview Preparation
November 29, 2024