/
main.go
51 lines (42 loc) · 1.24 KB
/
main.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
package main
import (
"fmt"
"os"
"text/tabwriter"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/photosojourn/aws-tools/pkg/awstools"
)
func main() {
ec2session := ec2.New(session.New(), aws.NewConfig())
params := &ec2.DescribeVolumesInput{}
result, err := ec2session.DescribeVolumes(params)
if err != nil {
fmt.Println(err)
return
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 2, '\t', 0)
fmt.Fprintln(w, "Volume ID\tName\tInstance ID\tDevice\tAvailabilityZone\tSize (GB)\tType\tIOPS\tEncrypted")
for _, volume := range result.Volumes {
name := awstools.GetVolumeName(*volume)
fmt.Fprintf(w, "%v\t", *volume.VolumeId)
fmt.Fprintf(w, "%v\t", name)
if len(volume.Attachments) > 0 {
for _, attachment := range volume.Attachments {
fmt.Fprintf(w, "%v\t", *attachment.InstanceId)
fmt.Fprintf(w, "%v\t", *attachment.Device)
}
} else {
fmt.Fprintf(w, "\t")
fmt.Fprintf(w, "\t")
}
fmt.Fprintf(w, "%v\t", *volume.AvailabilityZone)
fmt.Fprintf(w, "%v\t", *volume.Size)
fmt.Fprintf(w, "%v\t", *volume.VolumeType)
fmt.Fprintf(w, "%v\t", *volume.Iops)
fmt.Fprintf(w, "%v\t", *volume.Encrypted)
fmt.Fprintf(w, "\n")
}
w.Flush()
}