node.jsamazon-web-servicesamazon-cloudfront

AWS cannot signed CloudFront urls PEM error


I'm using NodeJS to get a signed URL from Cloudfront... I have the credentials to get them but I'm always getting an error, it tells me the credentials are wrong, I'm using this library.

aws-cloudfront-sign

var cfsign = require('aws-cloudfront-sign');

var signingParams = {
  keypairId: process.env.PUBLIC_KEY,
  privateKeyString: process.env.PRIVATE_KEY,
  expireTime: 1426625464599
}

// Generating a signed URL
var signedUrl = cfsign.getSignedUrl(
  'http://example.cloudfront.net/image.png', 
  signingParams
);

enter image description here

Obviously I have replaced example.cloudfront with the name of my distribution


Solution

  • Solved.. you must add the break lines with \n in a variable

    const pk = "-----BEGIN RSA PRIVATE KEY-----\nABDECASFAFSAS\n