gpt4 book ai didi

aws-sdk - 错误 : Cannot find module '@aws-sdk/client-sns'

转载 作者:行者123 更新时间:2023-12-04 12:56:38 25 4
gpt4 key购买 nike

调用我的 lambda 时出现此错误。
"errorType": "Runtime.ImportModuleError",
"errorMessage": "错误:找不到模块 '@aws-sdk/client-sns'\n需要堆栈:\n-/var/task/handler.js\n-/var/runtime/UserFunction.js\n-/var/runtime/index.js",
“痕迹”: [
"Runtime.ImportModuleError: 错误:找不到模块 '@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}`);
}
};

最佳答案

如果您使用的是 SDK 的 V2,请使用:

var AWS = require('aws-sdk');
AWS.config.update({region: 'REGION'});

// Create promise and SNS service object
const SNS = new AWS.SNS({apiVersion: '2010-03-31'})
如果出于大小原因,您只想在 Lambda 函数中使用 SNS 模块,我建议您使用适用于 JavaScript 的 AWS SKD V3。默认情况下,Lambda 仍然仅与 SDK 的 V2 兼容,但有一个解决方法。这是一个 example of creating a function using only modules of the AWS SDK for JavaScrpt - version 3 .

关于aws-sdk - 错误 : Cannot find module '@aws-sdk/client-sns' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66100387/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com