aws-samples / aws-samples/amazon-cloudfront-functions
url redirect adding multiple path
- Dominant language
- JavaScript
- Stars
- 533
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
I have this simple function to route traffic equally to two APIGW as origin. I see few requests works but after that it starts giving me 403. Looks this function is adding same literal multiple times or in some way function cache is messing it up.
```
function handler(event) {
var randomnumber = Math.floor(Math.random() * 100)
if (randomnumber < 50) {
var reg = 'east'
console.log({
statusCode: 302,
statusDescription: 'Found',
headers: {
"location": {
"value": `https://${event.request.headers.host.value}//${reg}${event.request.uri}`
}
}
})
return {
statusCode: 302,
statusDescription: 'Found',
headers: {
"location": {
"value": `https://${event.request.headers.host.value}//${reg}${event.request.uri}`
}
}
};
}
return event.request
}
```
Correct redirect url would be something like this -
_https://XXXXXXXXXX.cloudfront.net//east/p1/p2/p3/p4_
But when it gives 403 and i check function log, i see these as return - (essentially "east" multiple times in path, which explains why i am getting 403). But I am unable to figure out what i am doing wrong. This function is associated with distribution as "Viewer request".
_https://XXXXXXXXXX.cloudfront.net//east//east/p1/p2/p3/p4
https://XXXXXXXXXX.cloudfront.net//east//east//east/p1/p2/p3/p4_
Contributor guide
Assessment
This issue has not been assessed yet.