Skip to content

Commit 088cdae

Browse files
committed
modules, improvements
1. Go Modules supports 2. Authorize with default credentials chain if specific ones are not provided 3. Code cleanup Signed-off-by: Andrey Klimentyev <[email protected]>
1 parent b61e9f6 commit 088cdae

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

ec2_describe_tags.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,17 @@ func main() {
6767
instanceID = resp
6868
}
6969

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+
}
7174

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)})
7377

7478
params := &ec2.DescribeInstancesInput{
7579
Filters: []*ec2.Filter{
76-
&ec2.Filter{
80+
{
7781
Name: aws.String("instance-id"),
7882
Values: []*string{
7983
aws.String(instanceID),
@@ -94,7 +98,7 @@ func main() {
9498
for idx := range resp.Reservations {
9599
for _, inst := range resp.Reservations[idx].Instances {
96100
// https: //godoc.org/github.com/awslabs/aws-sdk-go/service/ec2#Instance
97-
s := []string{}
101+
var s []string
98102
for _, tag := range inst.Tags {
99103
s = append(s, *tag.Key+kvdelim+*tag.Value)
100104
}

go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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=

0 commit comments

Comments
 (0)