Importing a function from a module in functionGlobalContext

I have a module specified in functionGlobalContext

cloudfrontSigner: require ('@aws-sdk/cloudfront-signer')

I plan to use this in a function node, but I'm having trouble importing the function.
Traditional node.js code will look like this:

import { getSignedURL } from '@aws-sdk/cloudfront-signer'

I have imported into the function node using this method:

let CFS = global.get('cloudfrontSigner') //as listed in functionGlobalContext { ... }

How can I access or import the getSignedURL function from this sdk?
I want to do something like this ie:

CFS.getSignedURL({ ... });

But I am getting error "TypeError: CFS.getSignedURL is not a function"

How do we import these functions in a function node?

Is there any reason you are not simply using the function node setup tab?

https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option

In the code I posted I've gotten past the error and onto the next:
"Error: Invalid policy"

So I am afraid my original issue was merely due to a case-sensitive typo.

I've come across the naming error:
In this code it should be: getSignedUrl and not getSignedURL

I will look into your suggestion for the mean time.

Ahhh. I see this was implemented back in 1.3?
I remember using NR before 1.0, and I guess I've never really gotten to use this, nor remembered it was an implementation.
https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option

The policy parameters were entered incorrectly as well:

msg.payload = CFS.getSignedUrl({
    url :domain + '/content/demo.mp3',
    dateLessThan : new Date(Date.now() + 1000 * 60 * 60 * 24),
    privateKey: privateKey,
    keyPairId: 'K3LQ6E4XYZABCDEFG'
})

The dateLessThan was using the key: expires.
This is resolved.

This is pertaining to the AWS-SDK for CloudFront Signer

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.