created A/B test routing with cloudfront function

0

I have the following libs convention in my s3 origin serving/[0....19]/somefile.pm.js. and i added a the following cloudfront function to the viewer request . i want to randomly pick equally from libs 0 - 19 when we hit a request from the the following file path : https://myurl.com/serving/somefile.pm.js.

the final goal is to create A/B testing - the question is - if this function reliable to achieve that ? for instance

the file version in libs [0 - 9] was created/modifed and validated 4 weeks ago and a new version is deployed now for libs [10 -19] .. is this test good to go and can I trust that this way cloudfront will serve the 2 versions rate of 50/50??

function insertLib(request) { var originalURL = request.uri var headers = request.headers var pubmaxserver = headers["pubmaxserver"]; var lib = null if(pubmaxserver && pubmaxserver.value == '0' ){ lib = '0' } if(pubmaxserver && pubmaxserver.value ){ lib = pubmaxserver.value }

if (!originalURL.includes("serving") && originalURL.endsWith(".pm.js")) {
    if(!lib){
       lib = Math.floor(Math.random() * 20); 
    }
    originalURL =  originalURL.split(".pm.js")[0].replace("/","/serving/"+ lib +"/") +".pm.js"
}

// If the URL doesn't end with ".pm.js" or if the random number is >= the specified percentage, return the original URL
return originalURL;

}

Ronen
已提問 4 個月前檢視次數 175 次
1 個回答
0
AWS
SeanM
已回答 4 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南