i was trying to use Lambda@Edge to handle A/B testing in my site. i wonder is there a way to let Lambada@Edge functions load an external config data from a url, eg. i created an api to return the traffic rates of A/B channels,i want control that config data outside, so that i can dynamically adjust the traffics flow to A or B channel and no need to modify the Lambda function. what i did now is
var versions = [];
var isLoadingVersionData = false;
const https = require('https');
function loadVersions() {
if (isLoadingVersionData)
return null;
isLoadingVersionData=true;
https.get('https://example.com/getAbTestConfig', (res) => {
res.on('data', (d) => {
var parsedBody = JSON.parse(d);
if (parsedBody.status)
versions = parsedBody.data;
});
}).on('error', (e) => {
console.log(e);
});
}
//and load the function in handler
exports.handler = (event, context, callback) => {
context.callbackWaitsForEmptyEventLoop = false;
loadVersions();
}
i wonder this variable "versions" can be loaded correctly and shared in each later requests
do you have some more effectually solutions?