Skip to content

Instantly share code, notes, and snippets.

@Greyeye
Created January 14, 2014 03:45
Show Gist options
  • Save Greyeye/8412696 to your computer and use it in GitHub Desktop.
Save Greyeye/8412696 to your computer and use it in GitHub Desktop.
sample EC2 code for aws-sdk
/* use http://localhost:8080/api/:environment/:searchstring
environment and searchstring is case sensitive.
please install express (npm install express)
*/
var aws = require('aws-sdk');
var express = require('express');
var app = express();
aws.config.logger = process.stdout;
//setup your AWS security
aws.config.loadFromPath('./aws.config');
var ec2 = new aws.EC2({region: 'ap-southeast-2'});
app.use(express.logger('dev'));
app.get('/api/:environment/:search', function (req,res){
var environmentString = req.params.environment;
var searchString = req.params.search;
var params = {
Filters:[
{'Name':'tag:EnvironmentCode','Values':[environmentString]},
{'Name':'tag:Name', 'Values':[searchString]}
]
};
ec2.describeInstances(params,function(err,data){
if (err) {
console.log("ERROR" + err);
res.end("ERROR"+ JSON.stringify(err));
};
//console.log('params submitted' + params);
res.end(JSON.stringify(data.Reservations));
});
});
app.listen(8080, function(){
console.log('Booting up Express @ http://localhost:8080');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment