aws-butler
v3.0.1
Published
Extends the AWS SDK adding the ability to use either promises or callbacks and makes the extraction of data easier by allowing requests to take optional transform parameter
Downloads
9
Maintainers
Readme
aws-butler
Features
- all methods for all services can be executed using either promises or callbacks - promises use when.js for maximum compatibility
- pageable requests are handled for you - the promise or callback will only be resolved once all pages of data have been retrieved
- an optional transform function can be provided in request parameters - this allows you to get the data you want with ease
- aws-butler doesn't change the interface to the SDK methods nor does it alter the response so your current code will work with this module
NOTE: when requests are 'pageable', an array is returned with each element containing the data from a page. If you provide a transform function, the transform is executed for every page of data before it's added to the resulting array. This enables you to tailor the resulting array to get the data in a suitable format. Check out the transform example to see how this can be used to your advantage.
Usage
Simple example
var AWS = require("aws-butler");
var ec2 = new AWS.EC2({ region: "us-east-1" });
// example using promise
ec2.describeInstances()
.then(data => {
console.log(data); // data contains standard AWS response
})
.catch(err => {
throw err;
})
.done();
// example using callback
ec2.describeInstances(function(err, data) {
if (err) throw err;
console.log(data);
});
Example using a transform function to get the IDs of running instances
var AWS = require("aws-butler");
var ec2 = new AWS.EC2({ region: "eu-west-1" });
// params defined with optional transform function
var params = {
Filters: [
{
Name: "instance-state-name",
Values: ["running"]
}
],
Transform: function(data) {
var ids = [];
data.Reservations.map(function(r) {
ids = ids.concat(r.Instances.map(function(i) { return i.InstanceId; }));
});
return ids;
}
};
// example using promise
ec2.describeInstances(params)
.then(data => {
console.log(data); // data contains a flattened array of instance IDs as collated by the transform function
})
.catch(err => {
throw err;
})
.done();
// example using callback
ec2.describeInstances(params, function(err, data) {
if (err) throw err;
console.log(data); // data contains a flattened array of instance IDs as collated by the transform function
});
ES6/ES2015
Initially I wrote this using ES6 native promises, arrow functions etc. Unfortunately, ES6 support is still lacking in many places e.g. AWS Lambda uses Node v0.10.36 so no ES6 there. I tried using babel but it was too unreliable. I decided that for maximum compatibility and so people can use this module without issues I'd avoid ES6, at least for now.
Disclaimer
This module is open source and free to use however AWS is not free. I can't be held responsible for any charges you may incur from Amazon while using this module.
If you find any bugs or issues please raise them here.