I would like to create an Atlas function to generate AWS CloudFront signed urls using the aws-sdk (v2.1127.0), as written below:
exports = function makeDownloadUrl ({ objectKey, expiresInMinutes }) {
const cloudfrontInfo = context.environment.values.aws.cloudfront
const cloudfrontDistributionDomain = cloudfrontInfo.distributionDomain
const url = `${cloudfrontDistributionDomain}/${objectKey}`
const keyPairId = cloudfrontInfo.keyPairId
const privateKey = context.values.get('cloudfrontPrivateKey').replace(/\\n/g, '\n')
const CloudFront = require('aws-sdk').CloudFront
const signer = new CloudFront.Signer(keyPairId, privateKey)
const expirationEpoch = makeExpirationEpoch(expiresInMinutes)
const options = { url, expires: expirationEpoch }
return signer.getSignedUrl(options)
}
function makeExpirationEpoch (expiresInMinutes) {
const now = new Date()
const millisecondsPerMinute = 60000
const expirationDate = new Date(now.getTime() + expiresInMinutes * millisecondsPerMinute)
return expirationDate.valueOf()
}
However, when running this code, it results in the error: FunctionError: 'crypto' module: error creating sign
I believe the issue occurs when the aws-sdk module calls crypto.createSign
. I checked your JavaScript Support Documentation for the crypto module, and it indicates that this method should be supported, but in practice it does not appear to work.
Do you guys support this crypto method? If not, I believe you need to update your documentation accordingly.
If you do support this method, am I doing something else wrong? The code appears to work fine when run on my local computer.