gpt4 book ai didi

node.js - AWS Lambda - PutItem Dynamo DB 回调未调用

转载 作者:太空宇宙 更新时间:2023-11-03 22:58:12 24 4
gpt4 key购买 nike

exports.handler = function(event, context) {
var AWS = require('aws-sdk');
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
var kafka = require('kafka-node');
var Consumer = kafka.Consumer,
// The client specifies the ip of the Kafka producer and uses
// the zookeeper port 2181
client = new kafka.KafkaClient({kafkaHost: '172.16.35.115:9092,172.16.35.217:9092,172.16.37.14:9092'});



// The consumer object specifies the client and topic(s) it subscribes to
consumer = new Consumer( client, [ { topic: 'BillKazTopic', partition: 0, fromOffset: 'latest'} ], { autoCommit: true });
consumer.on('message', function (message) {
console.log("hellow");
console.log(message);

// Add to Dynamo
var tableName = "dev-AM-Appointment";
console.log(JSON.stringify(event, null, ' '));
dynamodb.putItem({
"TableName": tableName,
"Item" : {
"appointment_id": {S: 'message=' + message.value}
}
}, function(err, data) {
console.log("HELLO WORLD!!!!");
if (err) {
console.log('Error putting item into dynamodb failed: '+err);
context.succeed('error');
}
else {
console.log('great success: '+JSON.stringify(data, null, ' '));
context.succeed('Done');
}
});

});
};

我正在尝试监听 Kafka 并消费消息(有效)。

但是 putItem() 的回调永远不会被调用,因此语句:console.log(" Hello World !!!");

从不显示。可能是什么问题?

最佳答案

您对 DynamoDB 的请求超时,因为您在 VPC 中运行 Lambda 函数,但您没有提供 NAT 网关或 VPC Endpoint以允许 Lambda 函数访问 VPC 外部的 DynamoDB。

我建议将 VPC 端点配置为 DynamoDB。

关于node.js - AWS Lambda - PutItem Dynamo DB 回调未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54207229/

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