Cannot find module 'aws-cloudfront-sign'

0

I want to create cloudfront presigned URL in my lambda function through this code:

import { createRequire } from 'module';
const require = createRequire(import.meta.url);
var AWS = require('aws-cloudfront-sign');

export const handler = async(event) => {

    
    var signingParams = {
  keypairId: "************************************",
  privateKeyString: "****************************************",

  privateKeyPath: '/path/to/private/key',
  expireTime: 1426625464599
}

var signedUrl = AWS.getSignedUrl(
  'http://example.cloudfront.net/path/to/s3/object', 
  signingParams
);

console.log(signedUrl);
};

I don't know what is happening. Another question, I have 2 keys rsa xxxxxxx.pem & pk xxxxxxxxx.pem. I'm placing the rsa.pem in keypairid and pk.pem in private key string by removing -----END RSA PRIVATE KEY----- & -----BEGIN RSA PRIVATE KEY----- from the strings.

1 Answer
0
Accepted Answer

For the missing dependency, you need to deploy your Lambda function as a package with all of the dependencies included. If your function depends on libraries other than the AWS SDK for JavaScript, use npm to include them in your deployment package. See https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies

Also please take a look at some example code for your use case here: https://www.npmjs.com/package/aws-cloudfront-sign?activeTab=explore

profile pictureAWS
EXPERT
Matt-B
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions