通过Lambda函数将数据添加到Amazon RDS

我一直在尝试创build一个用nodejs编写的Alexa技巧,我想把一些数据推送到RDS数据库。 我已经configuration了VPC和安全组,这应该意味着lambda函数可以访问数据库,因为我刚刚在节点中编写代码我认为我可能错误地编写了我的查询函数。 我有我的zip文件中的lambda函数node-mysql模块,所以没有问题。

var mysql = require('mysql'); var connection = mysql.createConnection({ host : rds endpoint, user : 'mohammad', password : 'password', database : 'motivate' }); connection.connect(function(err){ if (err) { console.error('error connecting: ' + err.stack); return; } console.log('connected as id ' + connection.threadId); }); for(var i = 0; i < authors.length; i++){ var postData = {author: authors[i], quote: quotes[i]}; var query = connection.query('INSERT INTO quotes SET ?', postData, function(err, result) { console.log(err); }); console.log(query.sql); } connection.end(); 

除了require('mysql')之外,这些都在我的exports.handler中。 我假设代码运行成功,因为没有错误,控制台打印如下。

 2017-01-11T00:20:47.141Z c41a492d-d793-11e6-8344-27807a741276 INSERT INTO quotes SET `author` = 'Theodore Roosevelt', `quote` = 'Keep your eyes on the stars, and your feet on the ground.' 2017-01-11T00:20:47.141Z c41a492d-d793-11e6-8344-27807a741276 INSERT INTO quotes SET `author` = 'Nelson Mandela', `quote` = 'It always seems impossible until it\'s done.' 2017-01-11T00:20:47.141Z c41a492d-d793-11e6-8344-27807a741276 INSERT INTO quotes SET `author` = 'Og Mandino', `quote` = 'Failure will never overtake me if my determination to succeed is strong enough.' 2017-01-11T00:20:47.199Z c41a492d-d793-11e6-8344-27807a741276 New Session 2017-01-11T00:20:47.199Z c41a492d-d793-11e6-8344-27807a741276 Launch Request REPORT RequestId: c41a492d-d793-11e6-8344-27807a741276 Duration: 925.98 ms Billed Duration: 1000 ms Memory Size: 128 MB Max Memory Used: 21 MB 

我注意到的一件事是,console.log('连接为ID'+ connection.threadId); 没有被执行,因为日志中没有任何东西。 我不确定是否在createConnection部分中错误地设置了连接,或者错误来自我的另一部分代码。