This is my code
var AWS = require('aws-sdk');
AWS.config.region = 'ap-southeast-1';
var uuid = require('node-uuid');
ec2 = new AWS.EC2({apiVersion: 'latest'});
AWS.config.update({accessKeyId: xxxxxxxx, secretAccessKey: yyyyyyyyyyy});
AWS.config.update({region: 'zzzzzzzzzzzzzz'});
var util = require('util');
var opsworks = new AWS.OpsWorks();
var cloudformation = new AWS.CloudFormation();
var cloudwatch = new AWS.CloudWatch();
function listInstances(callback){
new AWS.EC2().describeInstances(function(error, data) {
if (error) {
callback(error);
} else {
callback(util.inspect(data, {depth: null})); //this returns a full fledged JSON response on the console
}
});
}
//Test above methods
listInstances(callback);
function callback(data){
console.log(data);
}
I tried parsing the JSON response by replacing the line
callback(util.inspect(data, {depth: null}));
with
JSON.parse(data);
I get the following error
{ [SyntaxError: Unexpected token o] statusCode: 200, retryable: false }
{ [200: null]
message: null,
code: 200,
time: Tue Jul 22 2014 22:59:42 GMT+0530 (India Standard Time),
statusCode: 200,
retryable: false }
i tried using eval() to parse it and i got the following error
[SyntaxError: Unexpected identifier]
Am I doing anything wrong, should I be parsing the JSON response using any other logic?
Please excuse my ignorance if any since I am new to both node.js and AWS