Skip to content

Instantly share code, notes, and snippets.

@tdegrunt
Forked from juno/nodejs-aws-example.js
Created August 9, 2011 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdegrunt/1133607 to your computer and use it in GitHub Desktop.
Save tdegrunt/1133607 to your computer and use it in GitHub Desktop.
AWS EC2 access example w/nodejs, express, aws-lib
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