How to make redirect using Lambda@Edge?
This instruction will help you to make 301 redirect using CloudFront(CF) and Lambda@Edge.
exports.handler = (event, context, callback) => {
const request = event.Records[0].cf.request;
const uri = request.uri;
if (uri === "/some-url-you-want-to-redirect/") {
const response = {
status: '301',
statusDescription: 'Permanently Moved',
headers: {
location: [{
key: 'Location',
value: 'https://site.com/url-for-redirection'
}]
}}
callback(null, response);
} else {
callback(null, request)
}
};
Create the function using Lambda Functions of AWS
Deploy it on Lambda@Edge
Attach it to Viewer Request on needed "Behavior" on CF.
Last updated