From 880d068c6506fabc326985a4e31976acb1b446ae Mon Sep 17 00:00:00 2001 From: Peter Waller
Date: Thu, 23 Apr 2015 11:09:18 +0100 Subject: [PATCH] Update to aws-sdk-go --- instance.go | 13 ++++++++----- main.go | 23 +++++------------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/instance.go b/instance.go index 898033e..6ba8bdc 100644 --- a/instance.go +++ b/instance.go @@ -5,7 +5,7 @@ import ( "sort" "time" - "github.com/stripe/aws-go/gen/ec2" + "github.com/awslabs/aws-sdk-go/service/ec2" ) type Instance struct { @@ -15,10 +15,10 @@ type Instance struct { ICMPPing, SSHPing, HTTPPing, HTTPSPing <-chan PingResponse } -func NewInstance(i ec2.Instance) *Instance { +func NewInstance(i *ec2.Instance) *Instance { return &Instance{ *i.InstanceID, *i.PrivateIPAddress, *i.State.Name, - time.Since(i.LaunchTime), + time.Since(*i.LaunchTime), TagMap(i.Tags), ICMPPing(*i.PrivateIPAddress), SSHPing(*i.PrivateIPAddress), @@ -27,7 +27,7 @@ func NewInstance(i ec2.Instance) *Instance { } } -func TagMap(ts []ec2.Tag) map[string]string { +func TagMap(ts []*ec2.Tag) map[string]string { m := map[string]string{} for _, t := range ts { m[*t.Key] = *t.Value @@ -76,10 +76,13 @@ func (i *Instance) PrettyState() string { return fmt.Sprint("[" + color + "m" + s + "[m") } -func InstancesFromEC2Result(in *ec2.DescribeInstancesResult) []*Instance { +func InstancesFromEC2Result(in *ec2.DescribeInstancesOutput) []*Instance { out := []*Instance{} for _, r := range in.Reservations { for _, oi := range r.Instances { + if oi.PrivateIPAddress == nil || oi.PublicIPAddress == nil { + continue + } out = append(out, NewInstance(oi)) } } diff --git a/main.go b/main.go index 355cf5d..8d94c5f 100644 --- a/main.go +++ b/main.go @@ -12,19 +12,9 @@ import ( "github.com/olekukonko/tablewriter" - "github.com/stripe/aws-go/aws" - "github.com/stripe/aws-go/gen/ec2" + "github.com/awslabs/aws-sdk-go/service/ec2" ) -var AWS_REGION = os.Getenv("AWS_REGION") - -func init() { - // Default the region to eu-west-1. - if AWS_REGION == "" { - AWS_REGION = "eu-west-1" - } -} - func ShowInstances(instances []*Instance) { table := tablewriter.NewWriter(os.Stderr) table.SetAlignment(tablewriter.ALIGN_RIGHT) @@ -92,7 +82,7 @@ func ClearToEndOfScreen() { func JumpTo(client *ec2.EC2) { - ec2Instances, err := client.DescribeInstances(&ec2.DescribeInstancesRequest{}) + ec2Instances, err := client.DescribeInstances(&ec2.DescribeInstancesInput{}) if err != nil { log.Fatal("DescribeInstances error:", err) } @@ -113,8 +103,7 @@ func JumpTo(client *ec2.EC2) { } func Watch(client *ec2.EC2) { - creds := aws.IAMCreds() - c := ec2.New(creds, AWS_REGION, nil) + c := ec2.New(nil) finish := make(chan struct{}) go func() { @@ -129,7 +118,7 @@ func Watch(client *ec2.EC2) { queryStart := time.Now() ConfigureHTTP(true) - ec2Instances, err := c.DescribeInstances(&ec2.DescribeInstancesRequest{}) + ec2Instances, err := c.DescribeInstances(&ec2.DescribeInstancesInput{}) if err != nil { log.Fatal("DescribeInstances error:", err) } @@ -161,9 +150,7 @@ func main() { fmt.Fprintln(os.Stderr, "[41;1mWarning: agent forwarding not enabled[K[m") } - // Pull requests welcome: code to generalise this to other clouds. - creds := aws.IAMCreds() - client := ec2.New(creds, AWS_REGION, nil) + client := ec2.New(nil) if len(os.Args) > 1 && os.Args[1] == "@" { Watch(client)