aws lambda-putitem dynamo db回调未调用

lnxxn5zx  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(314)
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!!!!”);
从不露面。有什么问题吗?

9ceoxa92

9ceoxa921#

您对dynamodb的请求正在超时,因为您正在vpc中运行lambda函数,但您没有提供nat网关或vpc端点来允许lambda函数访问存在于vpc之外的dynamodb。
我建议将vpc端点配置为dynamodb。

相关问题