Skip to content

Instantly share code, notes, and snippets.

@eMahtab
Created October 25, 2018 19:07
Show Gist options
  • Save eMahtab/5c6fe4a983fac976240c6c0a95943295 to your computer and use it in GitHub Desktop.
Save eMahtab/5c6fe4a983fac976240c6c0a95943295 to your computer and use it in GitHub Desktop.
Generating CloudFront Signed URL
var cfsign = require('aws-cloudfront-sign');
var currentTime = new Date()
var currentTimeinMillis = currentTime.getTime();
console.log("---------------------------------------------------------------------------")
console.log('Current Time is '+currentTime)
var expiryTime = currentTimeinMillis + 1*60*1000;
console.log("---------------------------------------------------------------------------")
console.log('Signed URL wiil expire on '+new Date(expiryTime));
var signingParams = {
keypairId: process.env.KEY_PAIR_ACCESS_KEY_ID,
privateKeyPath: '/Users/mahtab.alam/Downloads/cloudfront-key-pair-private-key.pem',
expireTime: expiryTime
}
// Generating a signed URL
var signedUrl = cfsign.getSignedUrl(
'http://aaaaaaaaaaaaaa.cloudfront.net/cat1.jpeg',
signingParams
);
console.log("---------------------------------------------------------------------------")
console.log('Signed URL ')
console.log("---------------------------------------------------------------------------")
console.log(signedUrl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment