Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect on response #27

Open
cipribucur opened this issue May 31, 2022 · 3 comments
Open

redirect on response #27

cipribucur opened this issue May 31, 2022 · 3 comments

Comments

@cipribucur
Copy link

cipribucur commented May 31, 2022

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.

@Eforen
Copy link

Eforen commented Jul 20, 2022

I have this same problem!

@rbpltr
Copy link

rbpltr commented Oct 19, 2022

Could you achieve this using custom error responses to respond with an HTML file that has a <meta http-equiv="refresh"> redirect?

@stschulte
Copy link

The original code seems to be incorrect. It returns newResponse but if the original status code is != 404, newResponse is not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants