How to import library inside the function node?

Hi Team,

Can we import the library from any inside the function node ?

Example : import { DescribeClustersCommand } from “@aws-sdk/client-redshift”;
var DescribeClustersCommand = require("@aws-sdk/client-redshift");

I am not able to use this, it’s showing an error.

Can anyone help me with this?

How to use AWS Redshift in n8n ? because there is now an AWS redshift node is there.

Thanks in advance!

Hi @rajesh-kumar, you can import libraries in the Function node but this would need to be specifically allowed using the NODE_FUNCTION_ALLOW_EXTERNAL environment variable.

If you’re still facing an error afterwards it’d be great if you could share the exact error message.

Hi, @MutedJam Thanks for the quick response.

Yes, i have added this in env files like below

After, my code in the function node

const { RedshiftClient, AcceptReservedNodeExchangeCommand } = require("@aws-sdk/client-redshift");

throwing this errors
1.ERROR: cannot find module ‘@aws-sdk/client-redshift’ (or)
2.ERROR: Access denied to require '@aws-sdk/client-redshift’


Is the module available in your n8n/node_modules directory as described on the documentation page?

Yes , axios,moment,aws-sdk ilb are available.

But @aws-sdk/client-redshift is not available(not in node_modules).

how can I import this?

Any other possiblities to work Redshift with n8n ?

That depends on how you have deployed n8n.

Are you running n8n right from the repository? In that case npm install @aws-sdk/client-redshift should be all you need.

If you’re using a custom docker image, this would be the way to go: Problem for Adding packages to a docker install - #2 by MutedJam

Yes @MutedJam, I tested with both.

From repo and docker image.

here I am running n8n with docker image is,

docker run -it -d --name n8n-container -p 5678:5678 -e N8N_ENCRYPTION_KEY=“XXXXXXXXXXXXXXXXXXXXXXXXX” -e NODE_FUNCTION_ALLOW_EXTERNAL=axios,moment,aws-sdk,@aws-sdk/client-redshift n8nio/n8n

Is that correct?

axios,moment,aws-sdk are working fine but , @aws-sdk/client-redshift throws error.

This looks like you’re running the default n8n docker image. Including custom modules would require building a custom docker image with the module you have in mind first (and then for every update afterwards). This is quite a bit of work. A possible approach to creating a custom docker image would be explained in the Use the n8n-nodes-module in production section of this page: Creating n8n-nodes-module | Docs

Is there maybe an alternative you can use? Afaik Redshift is based on an old Postgres version, could you possibly connect to your Redshift instance using the existing Postgres node?

Ok @MutedJam, Thanks. Let me check