Creates and signs private Cloudfront Urls (http, https, and rtmp)
JavaScript
Latest commit 996bc69 Jan 31, 2016 @maxnachlinger Using standard style.

README.md

cloudfront-private-url-creator

Creates and signs private Cloudfront Urls (http:, https:, rtmp:, rtmpt:, rtmpe:, and rtmpte:)

travis npm downloads standard

Installation:

npm install cloudfront-private-url-creator

Note:

Version 2.0.0 is for Node versions >4.0.0. If you are using Node 0.10 - 0.12, please use version 1.1.0.

Usage:

'use strict'
const fs = require('fs')
const cf = require('cloudfront-private-url-creator')

const urlToSign = 'https://somedistro.cloudfront.net/somefolder/someFile'
const keyPairId = 'yourKeyPaidId'
const privateKeyPath = './yourKey.pem'

// date when the private url will expire (1 hour from now in this case)
const dateLessThan = new Date()
dateLessThan.setHours(dateLessThan.getHours() + 1)

loadPrivateKey((err, keyContents) => {
    if (err) {
        console.error(err)
        return
    }
    const config = {
        privateKey: keyContents,
        keyPairId: keyPairId,
        dateLessThan: dateLessThan
    }
    // sign the url and return it, or just get the signature
    const signatureQueryString = cf.getSignatureQueryString(urlToSign, config)
    // OR
    const signedUrl = cf.signUrl(urlToSign, config)
})

function loadPrivateKey(cb) {
    fs.realpath(privateKeyPath, (err, resolvedPath) => {
        if (err) {
            return cb(err)
        }

        fs.readFile(resolvedPath, (err, data) => {
            if (err) {
                return cb(err)
            }
            cb(null, data)
        })
    })
}

Relevant AWS docs:

Creating a Signed URL Using a Canned Policy

Creating a Signed URL Using a Custom Policy

Contributors

Here's a list, thanks for your help!