0

I have been trying to get the node-fetch module in a CDK project. So that i can use it in a Lambda function.

The dependency is in the package.json file. npm list I installed it in the node package manager. error I keep getting: Cannot find module 'node-fetch.

I have looked at: https://github.com/node-fetch/node-fetch/issues/1027 But this didn't seem to work.

Function definition:

const lambdaJiraApi = new lambda.Function(this, 'lambda_Jira_api', {
  runtime: lambda.Runtime.NODEJS_16_X,
  code: Code.fromAsset('lambda'),
  handler: 'apiJiraFetcher.handler',
  timeout: Duration.seconds(20),
  functionName: 'lambda_Jira_api',
  environment: { QUEUEURL: queueSQS.queueUrl },
  layers: [nodeFetchLayer],
});
var fetch = require("node-fetch");
  • How is your Lambda Function construct defined? Please add a text codeblock. [It's best to avoid images](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors/285557#285557) in questions. – fedonev Nov 11 '22 at 16:34
  • const lambdaJiraApi = new lambda.Function(this, "lambda_Jira_api",{ runtime: lambda.Runtime.NODEJS_16_X, code: Code.fromAsset("lambda"), handler: "apiJiraFetcher.handler", timeout: Duration.seconds(20), functionName: "lambda_Jira_api", environment: { QUEUEURL: queueSQS.queueUrl }, layers: [nodeFetchLayer] }); – joey visbeen Nov 14 '22 at 07:24
  • sorry i don't know how to print it out nicely on Stackoverflow – joey visbeen Nov 14 '22 at 07:26
  • No worries. I added it to your question. How are you importing the `nodeFetch` module in your code? Please edit your question with the `require` or `import` line of code from your handler. – fedonev Nov 14 '22 at 10:14

0 Answers0