-
-
Save tdegrunt/1133607 to your computer and use it in GitHub Desktop.
AWS EC2 access example w/nodejs, express, aws-lib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = require('express').createServer(); | |
var aws = require('aws-lib'); | |
var access_key_id = '***'; | |
var secret_access_key = '***'; | |
var endpoint = 'ec2.ap-southeast-1.amazonaws.com'; // ap-southeast-1 | |
var ec2 = aws.createEC2Client(access_key_id, secret_access_key, {host: endpoint}); | |
app.get('/', function(req, res) { | |
console.log('/'); | |
res.send('<html><head><title>AWS Example</title><body><h1>AWS Example</h1><p><a href="/instances">Instances</a></p></body></html>'); | |
}); | |
app.get('/instances', function(req, res) { | |
console.log('/instances'); | |
ec2.call('DescribeInstances', {}, function(result) { | |
var body = '<h1>Instances</h1><ul>'; | |
for (var i = 0; i < result.reservationSet.item.length; i++) { | |
var item = result.reservationSet.item[i].instancesSet.item; | |
body += '<li>' + item.instanceId + ' (' + item.instanceState.name + ')</li>'; | |
} | |
body += '</ul>'; | |
res.send(body); | |
}); | |
}); | |
app.listen(3000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment