Skip to content

Instantly share code, notes, and snippets.

@apal21
Last active February 5, 2019 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apal21/d9cd3cceb8050126fefb81238a8354a0 to your computer and use it in GitHub Desktop.
Save apal21/d9cd3cceb8050126fefb81238a8354a0 to your computer and use it in GitHub Desktop.
Example to generate Signed URLs in CloudFront using Canned Policy.
const AWS = require('aws-sdk');
// Try to use process.env.PRIVATE_KEY instead of exposing your key
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
XXXXXXXX
XXXXXXXX
XXXXXXXX
XXXXXXXX
-----END RSA PRIVATE KEY-----`
const cloudFront = new AWS.CloudFront.Signer('PUBLIC_ACCESS_KEY', privateKey);
cloudFront.getSignedUrl({
url: 'https://abcdefghijklmn.cloudfront.net/test/a.txt',
expires: Math.floor((new Date()).getTime() / 1000) + (60 * 60 * 1) // Current Time in UTC + time in seconds, (60 * 60 * 1 = 1 hour)
}, (err, url) => {
if (err) throw err;
console.log(url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment