Last active
January 23, 2021 12:46
-
-
Save vipin87/715452f47e6b521ab35b575b92c51a1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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