Giter VIP home page Giter VIP logo

ec2cluster's Introduction

EC2 Cluster Auto-discovery for GO

Build Status

This package provides simple cluster auto-discovery for go using EC2 metadata. This should be used to seed a more reliable group membership algorithm, such as github.com/hashicorp/memberlist. Most such algorithms require an initial seed list of nodes, which is what ec2cluster provides.

In this example we use all the EC2 instances tagged with the same value for app as the initial known members for a memberlist cluster:

ec2TagName := "app"
knownMembers, err := DiscoverClusterMembersByTag(&aws.Config{}, ec2TagName)
if err != nil {
    panic(err)
}
cluster := memberlist.Create(memberlist.DefaultLANConfig())
_, err := cluster.Join(knownMembers)
if err != nil {
    panic(err)
}
defer cluster.Leave(time.Second)

When run as a command this program produces output that can be used to set environment variables. You can invoke it like:

eval $(ec2cluster)

The output it produces can be passed to the shell, or parsed:

AVAILABILITY_ZONE="us-west-2a"
REGION="us-west-2"
ADVERTISE_ADDRESS="10.0.10.124"
TAG_AWS_CLOUDFORMATION_STACK_ID="arn:aws:cloudformation:us-west-2:012345678901:stack/myapp/d0a9d5eb-dfed-4455-ab4b-5e7214f337bb"
TAG_APPLICATION="myapp"
TAG_AWS_AUTOSCALING_GROUPNAME="example-Cluster1-Q0YWRWQJC5XL"
TAG_CLUSTER="myapp-cluster1"
TAG_AWS_CLOUDFORMATION_STACK_NAME="myapp"
TAG_AWS_CLOUDFORMATION_LOGICAL_ID="Cluster1"
TAG_NAME="myapp.example.com-master"
ASG_DESIRED_CAPACITY=3
ASG_MIN_SIZE=1
ASG_MAX_SIZE=5
CLUSTER="10.0.10.124 10.0.188.207 10.0.118.6"

Monitoring ASG Lifecycle events

You can also use this tool to monitor autoscaling lifecycle events. To do this, configure your autoscaling group with a lifecycle hook that emits events to an SQS queue. Then invoke ec2cluster --watch which will produce one line of output per event, like:

autoscaling:EC2_INSTANCE_TERMINATING    i-403e6d87

ec2cluster's People

Watchers

 avatar  avatar  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.