I am performing a simple process in nodejs/expressjs using the aws-sdk module:
- upload file (using browser form post)
- send it to AWS S3
- put a message in AWS SQS for further processing.
- respond to the client with the SQS return object.
The code below works perfectly, but only one time. After the first post of a file, the node app no longer responds to other posts or actions (it even stops any process I have running with SetInterval(method,10000). When I try to post a second file, it just hangs. If I restart the server it works fine for just one post. I am running nodejs-v0.10.9 inside WebStorm 5 IDE. The code that the client is routed to after the file is posted is below - queueXml:
var fs = require('fs');
var step = require('step');
var AWS = require('aws-sdk');
AWS.config.loadFromPath('./lib/aws/config.json');
var bucketName = 'xxxxxx';
var sqsEndPoint = 'http://xxxx';
exports.queueXml = function(req,res){
var key = getGuid();
step(
function readPostedFile(){
fs.readFile(req.files.postedfile.path, this);
},
function sendToS3(err, data){
if(err) throw err;
var s3Bucket = new AWS.S3({params:{Bucket: bucketName}});
var fileData = {Bucket: bucketName, Key: key, Body: data};
s3Bucket.putObject(fileData,this);
},
function sendSQSMessage(err, path){
if(err) throw err;
var sqs = new AWS.SQS();
var message = {Bucket:bucketName, Key:key};
sqs.sendMessage({QueueUrl:sqsEndPoint,MessageBody:JSON.stringify(message)},this);
},
function end(err, data){
if(err) throw err;
res.send(JSON.stringify(data));
}
)
}