Skip to content

Instantly share code, notes, and snippets.

@luanlmd
Created March 5, 2020 00:21
Show Gist options
  • Save luanlmd/1d1863d837d12fadeeff325f8346a2db to your computer and use it in GitHub Desktop.
Save luanlmd/1d1863d837d12fadeeff325f8346a2db to your computer and use it in GitHub Desktop.
const aws = require('aws-sdk');
const cloudFront = aws.CloudFront;
const privateKey = `-----BEGIN RSA PRIVATE KEY-----
YOUR_PRIVATE_KEY_HERE_WITHOUT_ANY_TABULATION_BEFORE
-----END RSA PRIVATE KEY-----`;
const cfSigner = new cloudFront.Signer('YOUR_ACCESS_KEY_ID', privateKey);
const url = `https://randomaddress.cloudfront.net/path/to/file.jpg`;
const expires = Math.floor((new Date()).getTime() / 1000) + (60 * 60 * 1);
const signedUrl = cfSigner.getSignedUrl({ url, expires });
console.log(singedUrl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment