# Importing a function from a module in functionGlobalContext

**URL:** <https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384>\
**Category:** General\
**Created:** [17 September 2023 02:12 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384 "2023-09-17T02:12:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 September 2023 02:12 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384/1 "2023-09-17T02:12:57Z")

</div>

I have a module specified in `functionGlobalContext`

```auto
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:

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

```

I have imported into the function node using this method:

```auto
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:

```auto
CFS.getSignedURL({ ... });

```

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

How do we import these functions in a function node?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [17 September 2023 05:29 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384/2 "2023-09-17T05:29:34Z")

</div>

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](https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option)

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 September 2023 06:43 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384/3 "2023-09-17T06:43:17Z")

</div>

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.

-

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 September 2023 06:46 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384/4 "2023-09-17T06:46:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mrSidX](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mrsidx/32/18935_2.png) [@mrSidX](https://discourse.nodered.org/u/mrSidX)\
**Post date:** [17 September 2023 06:52 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384/5 "2023-09-17T06:52:29Z")

</div>

The policy parameters were entered incorrectly as well:

```auto
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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 October 2023 06:52 UTC](https://discourse.nodered.org/t/importing-a-function-from-a-module-in-functionglobalcontext/81384/6 "2023-10-01T06:52:55Z")

</div>

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