-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_emr_master_ip.go
56 lines (51 loc) · 1.35 KB
/
get_emr_master_ip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/emr"
"log"
"os"
)
func main() {
if len(os.Args) != 2 {
log.Fatal("Bad arguments")
}
clusterName := os.Args[1]
sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String("eu-west-1"),
}))
svc := emr.New(sess)
states := []*string{aws.String(emr.ClusterStateWaiting), aws.String(emr.ClusterStateRunning)}
params := &emr.ListClustersInput{
ClusterStates: states,
}
clustersOutput, err := svc.ListClusters(params)
if err != nil {
log.Fatalf("ListCluters Error: %+v\n", err)
}
if len(clustersOutput.Clusters) == 0 {
log.Fatalf("No cluster found")
}
for _, element := range clustersOutput.Clusters {
if *element.Name == clusterName {
id := element.Id
groupTypes := []*string{aws.String(emr.InstanceGroupTypeMaster)}
instancesParams := &emr.ListInstancesInput{
ClusterId: id,
InstanceGroupTypes: groupTypes,
}
instancesOutput, err := svc.ListInstances(instancesParams)
if err != nil {
log.Fatalf("ListInstances Error: %+v\n", err)
}
if len(instancesOutput.Instances) == 0 {
log.Fatal("No master found")
}
master := instancesOutput.Instances[0]
fmt.Printf("%s\n", *master.PrivateIpAddress)
os.Exit(0)
}
}
log.Fatal("Cluster not found")
}