Skip to content

Instantly share code, notes, and snippets.

@vipin87
Last active January 23, 2021 12:46
Show Gist options
  • Save vipin87/715452f47e6b521ab35b575b92c51a1f to your computer and use it in GitHub Desktop.
Save vipin87/715452f47e6b521ab35b575b92c51a1f to your computer and use it in GitHub Desktop.
'use strict';
const path = require('path');
exports.handler = (event, context, callback) => {
// Extract the request from the CloudFront event that is sent to Lambda@Edge
var request = event.Records[0].cf.request;
// Extract the URI from the request
var olduri = request.uri;
var newuri = request.uri;
if (olduri === '/') {
newuri = '/index';
}
// Log the URI as received by CloudFront and the new URI to be used to fetch from origin
console.log("Old URI: " + olduri);
console.log("New URI: " + newuri);
// Replace the received URI with the URI that includes the index page
request.uri = newuri;
// Return to CloudFront
return callback(null, request);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment