Coder Social home page Coder Social logo

aws-ec2's Introduction

aws-ec2

A small library for launching, describing, and terminating Amazon Web Services (AWS) EC2 instances

Disclaimer

This module has a suite of integration tests and I am using it in my production environment. That being said, this module allows you to start and terminate instances on EC2 which can have serious consequences. Running instances costs money, and terminating the wrong instances can be a serious problem in a production environment. You are STRONGLY encouraged to test this module thoroughly before deploying it in a production environment. I provide no warranty or guarantee that this module will perform as expected in your environment. Use this module wisely.

Installation

$ npm install aws-ec2

Usage

var aws = require('aws-ec2')(myAccessKey, mySecretAccessKey);

var instanceId;
var options = {
                'numToLaunch':1,
                'ami':'myAMI',
	            'awsZone':'us-east-1a',
	            'instanceType':'t1-micro',
			    'securityGroups':["Production", "Web"]
		    };
aws.launchOnDemandInstances(options, function (err, response) {
        instanceId = response.item.instanceId;
    });

Methods

launchOnDemandInstances(params, callback)

Launch one or more on demand instances. ami, awsZone, and instanceType are required. The other options can be found here

Receive a callback with callback(error,response) where the response is a RunningInstanceItemType

launchSpotInstances(params, callback)

Launch one or more spot instances. Spot instances are reserved based on a maximum price bid for each instance. See AWS Spot Instances for more info on this cheaper alternative. ami, awsZone, and instanceType are required.

Receive a callback with callback(error,response).

getInstanceDescriptionFromPrivateIp(privateIp, callback)

Get the description of an instance based on the instance's private up. The returned description is a RunningInstanceItemType

getInstanceDescriptionFromId(instanceId, callback)

Get the description of an instance based on the instance's id. The returned description is a RunningInstanceItemType

describeSpotInstanceRequest(requestId, callback)

Get the description of a spot instance request. The returned description is a SpotInstanceRequestSetItemType

terminateEc2Instance(instanceId, callback)

Shut down a running Ec2 instance based on an instanceId. The returned response is a TerminateInstancesResponse

cancelSpotRequest(requestId, callback)

Cancel a spot request based on the requestId. The returned response is a SpotInstanceRequestSetItemType

Running tests

WARNING the integration tests will launch and terminate actual instances on EC2 which will cost you $$$!!

Install dev deps:

$ npm install -d

Edit /test/testConfig.json to include your actual awsKey and awsSecretKey and the options you want to use for testing

  {
      'accessKey':'yourAccessKey',
      'secretAccessKey':'yourSecretAccessKey',
      'awsZone':'us-east-1a',
      'instanceType':'t1.micro',
      'securityGroups':["YourSecurityGroup1", "YourSecurityGroup2"],
      'ami':'ami-yourAmi',
      'spotPrice':0.001
  }

Run the integration tests: Again, will launch and terminate actual instances

$ make test-integration

License

MIT

aws-ec2's People

Contributors

camerondgray avatar m5m1th avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.