aws-samples / aws-samples/amazon-cloudfront-functions
redirect on response
- Dominant language
- JavaScript
- Stars
- 533
- Forks
- 76
- PR merge metrics
- No merged PRs in 30d
Description
hi guys, my use case is if the response is 404 from S3, to redirect to the original source to create it.
currently if I do
```
function handler(event) {
var response = event.response;
if (response.statusCode == '404') {
var newResponse = {
statusCode: 302,
statusDescription: 'Found',
headers:{
"location": { "value": "https://alternative-cdn-cname.com/path-to-regenerate-asset/" }
}
}
}
return newResponse;
}
```
on the response I get
502 ERROR
The request could not be satisfied.
The CloudFront function tried to add, delete, or change a read-only header.
1. is there a way to create a redirect (edit location header) on the response?
2. can lambda solve this?
Thanks.
Contributor guide
Assessment
This issue has not been assessed yet.