Setup AB test with Lambda@edge function

Issue

Amplify doesn't forward query string when it's 301 redirection.

Here is the code that how to fix this issue with lambda@edge function

Code

js

export const handler = (event, context, callback) => {
    const request = event.Records[0].cf.request;
    const response = event.Records[0].cf.response;
    
    if (response.status === "301" && request.querystring) {
        response.headers.location[0].value += `?${request.querystring}`;
    }

    return callback(null, response);
}