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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则