File tree 3 files changed +17
-4
lines changed
3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -67,13 +67,17 @@ func main() {
67
67
instanceID = resp
68
68
}
69
69
70
- creds := credentials .NewStaticCredentials (awsAccessKey , awsSecretAccessKey , "" )
70
+ var creds * credentials.Credentials
71
+ if len (awsAccessKey ) != 0 || len (awsSecretAccessKey ) != 0 {
72
+ creds = credentials .NewStaticCredentials (awsAccessKey , awsSecretAccessKey , "" )
73
+ }
71
74
72
- svc := ec2 .New (session .New (), & aws.Config {Credentials : creds , Region : aws .String (region )})
75
+ sess , err := session .NewSession (& aws.Config {Credentials : creds , Region : aws .String (region )})
76
+ svc := ec2 .New (sess , & aws.Config {Credentials : creds , Region : aws .String (region )})
73
77
74
78
params := & ec2.DescribeInstancesInput {
75
79
Filters : []* ec2.Filter {
76
- & ec2. Filter {
80
+ {
77
81
Name : aws .String ("instance-id" ),
78
82
Values : []* string {
79
83
aws .String (instanceID ),
@@ -94,7 +98,7 @@ func main() {
94
98
for idx := range resp .Reservations {
95
99
for _ , inst := range resp .Reservations [idx ].Instances {
96
100
// https: //godoc.org/github.com/awslabs/aws-sdk-go/service/ec2#Instance
97
- s := []string {}
101
+ var s []string
98
102
for _ , tag := range inst .Tags {
99
103
s = append (s , * tag .Key + kvdelim + * tag .Value )
100
104
}
Original file line number Diff line number Diff line change
1
+ module github.com/hmalphettes/go-ec2-describe-tags
2
+
3
+ go 1.13
4
+
5
+ require github.com/aws/aws-sdk-go v1.28.0
Original file line number Diff line number Diff line change
1
+ github.com/aws/aws-sdk-go v1.28.0 h1:NkmnHFVEMTRYTleRLm5xUaL1mHKKkYQl4rCd+jzD58c =
2
+ github.com/aws/aws-sdk-go v1.28.0 /go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo =
3
+ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM =
4
+ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af /go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k =
You can’t perform that action at this time.
0 commit comments