The company I work for is currently trying to migrate some of our existing codebase over to AWS Lambda. We are running node.js 4.3 (highest version offered for lambda) and we are executing inside a VPC to connect to an RDS database. The Lambda function is connecting to the database just fine, however a simple select query to our MySQL table isn't executing or returning any errors. Here is the code we are trying:
exports.handler = (event, context, callback) => {
/**
* Require Config file
**/
var config = require('./config.js');
/**
* AWS/MWS Configuration
**/
var AWS = require('aws-sdk');
var MWS = require('mws');
var mws = require('./lib/mws-reports/lib/mws.js');
var XML = require('./lib/mws-reports/pixl-xml');
var mwsReportsAPI = require('./lib/mws-reports/lib/reports.js');
var mwsFeedsAPI = require('./lib/mws-reports/lib/feeds.js');
AWS.config.region = config.AWS.region;
AWS.config.credentials = config.AWS.credentials;
var client = new mws.Client(
config.MWS.credentials.accessKeyId,
config.MWS.credentials.secretAccessKey,
config.MWS.credentials.sellerID,
{}
);
/**
* Configure DB
* @var Promise - A library to maintain Promises (used for chained MySQL queries)
* @var Utils - A wrapper for utility functions.
* @var connection - The MySQL DB Connection
**/
var Promise = require('bluebird');
var utils = require('./lib/Utils');
var mysql = require('mysql');
var MySQLConnection = mysql.createConnection(config.mysql);
MySQLConnection.connect(function (err) {
if(err) {
console.log("Error connection: " + err.stack);
return;
}
console.log("Connected as id " + connection.threadId);
});
var connection = Promise.promisifyAll(MySQLConnection);
var InventoryHealth = require('./app/models/InventoryHealth');
var Items = require('./app/models/Items');
connection.query("SELECT * FROM items", function(err, rows) {
rows.forEach(function(item) {
console.log(JSON.stringify(item));
});
});
connection.end();
context.done(null, "Finished :)");
}
As I mentioned, the strangest part of all of this is the lack of response I get from Lambda. This is all it tells me:
START RequestId: f726f0ba-ecec-11e6-b0b3-9d51c554a5ac Version: $LATEST
2017-02-07T04:22:01.123Z f726f0ba-ecec-11e6-b0b3-9d51c554a5ac (node) crypto.createCredentials is deprecated. Use tls.createSecureContext instead.
END RequestId: f726f0ba-ecec-11e6-b0b3-9d51c554a5ac
REPORT RequestId: f726f0ba-ecec-11e6-b0b3-9d51c554a5ac Duration: 4232.01 ms Billed Duration: 4300 ms Memory Size: 128 MB Max Memory Used: 22 MB
Any advice would be amazing. Thank you.