Created
October 2, 2012 14:19
-
-
Save paulbjensen/3819499 to your computer and use it in GitHub Desktop.
A wrapper around the aws2js npm module to provide some API calls specific to Amazon EC2
This file contains hidden or 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
| // Amazon AWS EC2 API wrapper | |
| // | |
| var aws2js = require('aws2js'); | |
| var ec2; | |
| var ec2Api = { | |
| // A helper function to supply API access credentials to Amazon | |
| // | |
| init: function(accessKeyId, secretAccessKey) { | |
| ec2 = aws2js.load('ec2', accessKeyId, secretAccessKey); | |
| }, | |
| // A helper function to set the region that the EC2 instances are read from and written to | |
| // | |
| setRegion: function(region) { | |
| ec2.setRegion(region); | |
| }, | |
| // DescribeInstances | |
| // | |
| // - Returns information about instances that you own. | |
| // - http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeInstances.html | |
| // | |
| DescribeInstances: function(cb){ | |
| ec2.request('DescribeInstances', function(err, res){ | |
| cb(err, res); | |
| }); | |
| }, | |
| // RunInstances | |
| // | |
| // - Launches the specified number of instances of an AMI for which you have permissions. | |
| // - http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-RunInstances.html | |
| // | |
| RunInstances: function(attributes, cb){ | |
| ec2.request('RunInstances', attributes, function(err, res){ | |
| cb(err, res); | |
| }); | |
| }, | |
| // StopInstances | |
| // | |
| // - Stops an Amazon EBS-backed instance. | |
| // - http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-StopInstances.html | |
| // | |
| StopInstances: function(attributes, cb){ | |
| ec2.request('StopInstances', attributes, function(err, res){ | |
| cb(err, res); | |
| }); | |
| }, | |
| // TerminateInstances | |
| // | |
| // - Shuts down one or more instances | |
| // - http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-TerminateInstances.html | |
| // | |
| TerminateInstances: function(attributes, cb){ | |
| ec2.request('TerminateInstances', attributes, function(err, res){ | |
| cb(err, res); | |
| }); | |
| }, | |
| // StartInstances | |
| // | |
| // - Starts an Amazon EBS-backed AMI that you've previously stopped. | |
| // - http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-StartInstances.html | |
| // | |
| StartInstances: function(attributes, cb){ | |
| ec2.request('StartInstances', attributes, function(err, res){ | |
| cb(err, res); | |
| }); | |
| } | |
| }; | |
| module.exports = ec2Api; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't everyone be able to see your access keys in:
init: function(accessKeyId, secretAccessKey) {
ec2 = aws2js.load('ec2', accessKeyId, secretAccessKey);
?
If so, is there some hidden encryption that could take place?