Using cloudfront to serve private content from s3 bucket using signed cookies. I am able to generate cookies, but when i request a resource, i get Missing Key-Pair-Id query parameter or cookie value error, either from node.js or even any client/browser/postman
const cloudFront = new AWS.CloudFront.Signer(
fs.readFileSync('./rsa-APKAIQSVJ2R3T6PYTOUQ.pem', 'utf8'),
fs.readFileSync('./pk-APKAIQSVJ2R3T6PYTOUQ.pem', 'utf8')
);
const policy = JSON.stringify({
Statement: [{
Resource: 'http*://d2q89b5pewg0ry.cloudfront.net/images/',
Condition: {
DateLessThan: {
'AWS:EpochTime': Math.floor(new Date().getTime() / 1000) + 60 * 60 * 3
}
},
}]
});
const cookie = cloudFront.getSignedCookie({
policy: policy
});
let cookieString = '';
for(var cookieKey in cookie)
{
cookieString += cookieKey + '=' + cookie[cookieKey] + ";";
}
return axios.get('https://d2q89b5pewg0ry.cloudfront.net/images/hikup.jpg',{
headers: {
Cookie: cookieString
}
}).then((response) => {
return response;
}).catch((error) => {
return error;
});