Created
October 7, 2023 16:33
-
-
Save javanigus/44276938816437c47639f2832e2dd2d4 to your computer and use it in GitHub Desktop.
AWS Lambda Function to Redirect HTTP Requests
This file contains 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
export const handler = async (event, context) => { | |
const request = event.request; | |
var newLocation = ""; | |
var statusCode = 301; | |
var statusDescription = "Moved Permanently"; | |
switch(request.uri) { | |
case "/test-pdf-1.pdf": | |
newLocation = "/test-pdf-2.pdf"; | |
statusCode = 301; | |
break; | |
case "/test-pdf-2.pdf": | |
newLocation = "https://www.google.com"; | |
statusCode = 302; | |
break; | |
} | |
if (statusCode === 302) { | |
statusDescription = "Found"; | |
} | |
if (newLocation !== "") { | |
var response = { | |
statusCode: statusCode, | |
statusDescription: statusDescription, | |
headers: { | |
'location': { value: newLocation } | |
} | |
}; | |
return response; | |
} else { | |
return request; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment