Skip to content

Commit

Permalink
Update to aws-sdk-go
Browse files Browse the repository at this point in the history
  • Loading branch information
pwaller committed Apr 23, 2015
1 parent e20583f commit 880d068
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
13 changes: 8 additions & 5 deletions instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -76,10 +76,13 @@ func (i *Instance) PrettyState() string {
return fmt.Sprint("[" + color + "m" + s + "")
}

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))
}
}
Expand Down
23 changes: 5 additions & 18 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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() {
Expand All @@ -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)
}
Expand Down Expand Up @@ -161,9 +150,7 @@ func main() {
fmt.Fprintln(os.Stderr, "Warning: agent forwarding not enabled")
}

// 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)
Expand Down

0 comments on commit 880d068

Please sign in to comment.