无法找到模块'aws-cloudfront-sign'。

0

【以下的问题经过翻译处理】 我想通过这段代码在我的Lambda函数中创建CloudFront预签名URL:

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);
};

我不知道发生了什么事情。 另一个问题,我有两个密钥“rsa xxxxxxx.pem”和“pk xxxxxxxxx.pem”。我将rsa.pem放在keypairid中,将pk.pem放在私钥字符串中,从字符串中删除了“-----END RSA PRIVATE KEY-----”和“-----BEGIN RSA PRIVATE KEY-----”。

profile picture
EXPERT
asked 5 months ago74 views
1 Answer
0

【以下的回答经过翻译处理】 对于缺少的依赖项,您需要将 Lambda 函数作为包含所有依赖项的包进行部署。如果您的函数依赖于 AWS SDK for JavaScript 之外的其他库,请使用 npm 将它们包含在部署包中。请参阅https://docs.aws.amazon.com/lambda/latest/dg/nodejs-package.html#nodejs-package-dependencies

此外,请查看此处有关您用例的一些示例代码: https://www.npmjs.com/package/aws-cloudfront-sign?activeTab=explore

profile picture
EXPERT
answered 5 months 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