Install OpenSSL on your machine and generate the keypairs
openssl genrsa -out private_key.pem 2048
openssl rsa -pubout -in private_key.pem -out public_key.pem
Install and import the cloudfront signer
npm i @aws-sdk/cloudfront-signer
import { getSignedUrl } from "@aws-sdk/cloudfront-signer"
Sign the urls before sending them to the browser
const signedUrl = getSignedUrl({
keyPairId: process.env.CLOUDFRONT_KEYPAIR_ID,
privateKey: process.env.CLOUDFRONT_PRIVATE_KEY,
url: url,
dateLessThan: new Date( Date.now() + (1000 /*sec*/ * 60))
})