Node.js and Lambda

I’ve been working on the API Gateway/Lambda code for ConMagick now for a bit.  Everything was working quite well, then all of the sudden I was getting connection issues.  After searching the web I found some solutions, but the error still arose.  After trial and error I finally found the fix and wanted to document it for anyone else that runs into this.

Node.js (lambda) and MySql work well, but unless you build the code 100% clean it will not work properly and you will get drops after your connections to the db server are maxed out.  The code I present below is how to properly implement a query through lambda (node.js).

This code takes in two variables, one from the URL and the other from the head.  (I won’t cover the API Gateway portion on here, that’s for another day).  The entire key to this process is to make sure that your connection is properly setup and then closed.  That last part being the key, if you don’t close the connection it will keep them open and will eventually cause max connection issues with MySQL.

var mysql = require('mysql');
var env = process.env;
const fs = require('fs');

exports.handler = (event, context, callback) => {

    // Get values from the API Gateway
    var itemx = event.params.path.itemx;
    var itemz = event.params.header.itemz;
    // Open connection - using environment variables
    var connection  = mysql.createConnection({
        host                 : env.dbhost,
        user                 : env.dbuser,
        password             : env.dbpass,
        database             : env.dbdatabase,
        ssl                 : 'Amazon RDS'
    // Read in SQL from file and replace with provided data
    var sql = fs.readFileSync('sqlfile.sql').toString();            
    sql = sql.replace('{{itemx}}', itemx);
    sql = sql.replace('{{itemz}}', itemz);
    // Run query on sql
    connection.query(sql, function (error, results) {
            callback(400,'Bad request');
            if(results.length >= 1){
                callback(null, {"data": results});
            } else {
                callback(null, {"Valid": false});
    // Close connection
    connection.end(function(err) {

We have a name!

After a day of sitting in front of my pc staring at the network solutions site I finally came up with a name for my new application.  It will be dubbed “ConMagick“, catchy huh.

Anyway, v0.2b was released to a select beta tester group and should be done with this round of beta testing in the next week.  After I make some small changes given to me by the beta testers I will move on to v0.2c which will pull in the programming track management and also clean up the auto mailing and panel flow process.

Assignment to Tracks complete

I have the new module to assign submitted panels to tracks completed.  I need to clean up the page layout some and then work on the permissions for the track module  and it will be ready to test.

I’m close to completing v0.2b of the application.  Once I have this done I am going to have a few testers use the site and give initial feedback for changes.  Once this user testing is done I will move onto v0.2c, which is the panel track management module.

Fiddler2 to the rescue!

I have been working on a dynamic dropdown code for the last 2 days.  The problem was basically that the tutorials on the Yii website don’t speak to using the new CActiveForm methods to make the drop downs.

I decided to finally download Fiddler2 and test it out since it will read the HTML packets and let me see what’s going on behind the scenes.  Sure enough, my ajax call was getting an error, but the front end was not seeing it.  After about 5-10 minutes of final troubleshooting I got the darn dropdown process to work.

So, here’s my shameless plus for fiddler2.  If you don’t have it, get it, it will save you valuable testing time when an error happens… =D

Convention Manager Web Application

I started working on a new web application last week.  It’s going to help manage conventions in the future.  The main goal of the application right now is to help with the communication, processes, and schedules for the convention programming.  I will be testing this out over the next few months and plan to beta test this with Saboten-Con 2010.

I will use this blog to track the process and also announce when betas will be available for people to help me test the application.  If you are interested in testing or using this application please contact me via this blog.