Created
September 2, 2012 23:56
-
-
Save possibilities/3605727 to your computer and use it in GitHub Desktop.
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
| AWSSum = { | |
| load: function(module) { | |
| var awssum = NodeModules.require('awssum'); | |
| return awssum.load(module); | |
| }, | |
| loadSyncInterface: function(module, className) { | |
| // Get a reference to the original interface | |
| var interface = AWSSum.load(module)[className]; | |
| _.each(interface.prototype, function(fn, name) { | |
| if (_.isFunction(fn) && (name === _.classify(name))) { | |
| var syncName = name + 'Sync'; | |
| interface.prototype[syncName] = function() { | |
| var fut = new Future(); | |
| var args = _.toArray(arguments); | |
| args.push(function(error, data) { | |
| if (error) | |
| data = { error: error }; | |
| fut.return(data); | |
| }); | |
| // Run the method with our Future-ized callback | |
| fn.apply(this, args); | |
| return fut.wait(); | |
| }; | |
| } | |
| }); | |
| return interface; | |
| } | |
| }; |
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
| if (Meteor.is_client) { | |
| Meteor.startup(function() { | |
| Meteor.call('describeInstances', function(error, instances) { | |
| var instances = instances.Body.DescribeInstancesResponse.reservationSet.item; | |
| if (!_.isArray(instances)) instances = [instances]; | |
| Session.set('instances', instances); | |
| }); | |
| }); | |
| Template.instances.helpers({ | |
| instances: function() { | |
| return Session.get('instances'); | |
| } | |
| }); | |
| } | |
| if (Meteor.is_server) { | |
| var amazon = AWSSum.load('amazon/amazon'); | |
| var Ec2 = AWSSum.loadSyncInterface('amazon/ec2', 'Ec2'); | |
| var ec2 = new Ec2({ | |
| 'accessKeyId' : "XXX", | |
| 'secretAccessKey' : 'YYY', | |
| 'region' : amazon.US_EAST_1 | |
| }); | |
| Meteor.methods({ | |
| describeInstances: function() { | |
| var data = ec2.DescribeInstancesSync(); | |
| if (data.error) | |
| throw new Meteor.Error(500, data.error.Body.Response.Errors.Error.Message, data.error); | |
| return data; | |
| } | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment