Comments/issues/"um there's totally a module that does exactly this" 
welcome.  Homepage is here  https://github.com/snupi/node-aws-command-stack

I've been working a lot recently with Amazon's newish VPC (Virtual Private 
Cloud) feature.  While the AWS management console gives you nice high-level 
operations like "Create a VPC with a
public subnet, a private subnet, and an EC2 instance acting as a NAT" the 
API is very low level, in fact to produce a similar VPC via the API 
requires at least the following (all part of the EC2 api):

createVpc, createInternetGateway, attachInternetGateway, createRoute, 
createSubnet, createRouteTable, associateRouteTable, createSubnet, 
createSecurityGroup, authorizeSecurityGroupIngress, 
authorizeSecurityGroupEgress, runInstances, allocateAddress, 
associateAddress, modifyInstanceAttribute, createRoute

Throw in tags and some Route53/DNS work and you're upwards of 20 API calls 
just to stand up a bare-bones VPC.  Naturally debugging this required 
creating and thus cleaning up a whole ton of these.  Most of the steps 
depend on earlier steps, e.g. you can't create the NAT instance until you 
create the subnet, you can't create the subnet until you create the VPC, 
etc., and the inverse applies when destroying objects.  Because the AWS 
API's are so uniform in calling form it worked out well to create a simple 
stack that I could push operations onto, this module is an extraction of 
just that bit.  I plan on releasing the higher level create/view/destroy 
VPC operations as a module as well once I have time to extract the company 
specific logic that's in there.

For illustration here's some code from the included sample (error handling 
left out for brevity), this finds all the VPCs in a given region and prints 
their subnets and instances.  (The stack approach isn't particularly 
relevant here, but the 'destroy a cloud' operation that birthed it is too 
long fit here).

var aws = new AWSCommandStack("EC2", {
  accessKeyId: 'yourAccessKeyId',
  secretAccessKey: 'yourSecretAccessKey',
  region: region
}}).on("end", function () {
  process.exit(0);
});

aws.push("EC2.describeVpcs", { }, function (error, data) {
  console.log("%s: found %d Vpcs", region, data.Vpcs.length);
  data.Vpcs.forEach(function (Vpc) {
    aws.push("EC2.describeSubnets", { Filters: [{ Name: "vpc-id", Values: [ 
Vpc.VpcId ] }]}, function (error, data) {
      console.log("  %s        %s", Vpc.VpcId, Vpc.CidrBlock));
      data.Subnets.forEach(function (Subnet) {
        aws.push("EC2.describeInstances", { Filters: [{ Name: "subnet-id", 
Values: [ Subnet.SubnetId ] }]}, function (error, data) {
          console.log("    %s   %s", Subnet.SubnetId, Subnet.CidrBlock);
          data.Reservations.forEach(function (Reservation) {
            Reservation.Instances.forEach(function (Instance) {
              console.log("      %s      %s   %s", Instance.InstanceId, 
Instance.PrivateIpAddress, Instance.PublicIpAddress));
            });
          });
          aws.done();
        });
      });
      aws.done();
    });
  });
  aws.done();
});

aws.run();

Which will output something like:

us-west-2: found 1 Vpcs
  vpc-71cbe109        10.0.0.0/16
    subnet-79cbe110   10.0.1.0/24
    subnet-7adbe112   10.0.0.0/24
      i-ea57cefd      10.0.0.162   54.213.18.102


-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to