jeudi 15 octobre 2015

Display retrieved aws instances to HTML page in Node.js

i have a code which retrieved instance from aws

var aws = require('aws-sdk');

aws.config.update({
    accessKeyId: 'YOUR_ACCESS_KEY', 
    secretAccessKey: 'YOUR_SECRET_KEY', 
    region: 'us-west-2'
});

var ec2 = new aws.EC2();

function printStatuses() {
    ec2.describeInstances({}, function(err, data) {
        if(err) {
            console.error(err.toString());
        } else {
            var currentTime = new Date();
            console.log(currentTime.toString());

            for(var r=0,rlen=data.Reservations.length; r<rlen; r++) {
                var reservation = data.Reservations[r];
                for(var i=0,ilen=reservation.Instances.length; i<ilen; ++i) {
                    var instance = reservation.Instances[i];

                    var name = '';
                    for(var t=0,tlen=instance.Tags.length; t<tlen; ++t) {
                        if(instance.Tags[t].Key === 'Name') {
                            name = instance.Tags[t].Value;
                        }
                    }
                    console.log('\t'+name+'\t'+instance.InstanceId+'\t'+instance.PublicIpAddress+'\t'+instance.InstanceType+'\t'+instance.ImageId+'\t'+instance.State.Name);
                }
            }
        }
    });    
} 

the above code works fine, it retrieved instances and displayed in terminal,i want to display it on HTML page I've already developed the front-end page and wish to have the instances come up on this page(inside table tag> instead of the console.




Aucun commentaire:

Enregistrer un commentaire