Cannot find module aws-sdk client-sns

0 votes

I am getting this error when calling my lambda.

"errorType": "Runtime.ImportModuleError", "errorMessage": "Error: Cannot find module '@aws-sdk/client-sns'\nRequire stack:\n- /var/task/handler.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js", "trace": [ "Runtime.ImportModuleError: Error: Cannot find module '@aws-sdk/client-sns'",

import * as AWS from '@aws-sdk/client-sns';
import { JamaSnsMessage } from './models/jama';
import { region, snsTopicArn } from './utils/constants';
import { log } from './utils/logger';

const client = new AWS.SNS({ region });

/**
 * Publishes given SNS formatted Jama items to SNS topic
 *
 * @param {JamaSnsMessage[]} items
 */
export const publishItems = async (items: JamaSnsMessage[]): Promise<void> => {
  if (!items || items.length <= 0) {
    return;
  }

  for (const item of items) {
    const params = {
      /* eslint-disable */
      MessageStructure: 'json',
      Message: JSON.stringify(item),
      TopicArn: snsTopicArn,
      /* eslint-enable */
    };
    log.info(`Sending jama item: ${JSON.stringify(item)} to sns`);
    await send(params);
  }
};

export const send = async (params: AWS.PublishInput): Promise<void> => {
  try {
    const data = await client.send(new AWS.PublishCommand(params));
    log.info(`Item: ${JSON.stringify(params)} was published with id: ${data.MessageId}`);
  } catch (error) {
    log.error(`Error while publishing message ${JSON.stringify(params)}. Cause: ${error}`);
  }
};

Feb 16, 2023 in AWS by Ashwini
• 5,430 points
1,637 views

1 answer to this question.

0 votes

This error occurs because the AWS SDK package named @aws-sdk/client-sns is not found in your Lambda function's node_modules folder.

To resolve this issue, you need to add the @aws-sdk/client-sns package to your Lambda function's dependencies.

You can do this by running the following command in your Lambda function's directory:

npm install @aws-sdk/client-sns

This command will install the required package and update the package.json file with the new dependency.

After that, you can deploy the updated code to your Lambda function, and the @aws-sdk/client-sns module should be found by your Lambda function without any issues.

Propel Your Skills with Comprehensive Microservices Training!

answered Feb 17, 2023 by sarit
• 1,830 points

Related Questions In AWS

0 votes
1 answer

Error creating DB Instance: InvalidParameterCombination: Cannot find version 5.6.10a for aurora-mysql

I guess engine name 'aurora-mysql' refers to ...READ MORE

answered Sep 24, 2018 in AWS by Priyaj
• 58,020 points
8,102 views
+1 vote
1 answer

[WinError 2] The system cannot find the file specified

Hi@akhtar, You may get this error, if you ...READ MORE

answered Jun 1, 2020 in AWS by MD
• 95,460 points
4,055 views
0 votes
1 answer

AmazonServiceException: Unable to find credentials

It should be a problem with AWS ...READ MORE

answered Feb 12, 2019 in AWS by Archana
• 5,640 points
2,536 views
0 votes
0 answers

How to get response from S3 getObject in Node.js?

I am attempting to get data back ...READ MORE

Apr 23, 2022 in Others by Kichu
• 19,040 points
1,877 views
0 votes
1 answer

Invalid Bucket name when creating s3 bucket with AWS SDK

AWS provides naming standards when naming an ...READ MORE

answered Aug 30, 2018 in AWS by Priyaj
• 58,020 points
4,535 views
0 votes
1 answer

Task Canceled Exception while invoking AWS Lambda

I'm guessing either the TaskCanceledException instance is ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,020 points
2,478 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP