Last active
December 13, 2019 21:42
-
-
Save farrellit/e8b26c1f385124bb65a67bb2002a3dfe to your computer and use it in GitHub Desktop.
golang awssdk ec2 describe-instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ec2" | |
) | |
func main() { | |
session := session.Must(session.NewSession(&aws.Config{Region: aws.String("us-west-2")})) | |
svc := ec2.New(session) | |
filters := []*ec2.Filter{ | |
&ec2.Filter{ | |
Name: aws.String("tag:Name"), | |
Values: []*string{ | |
aws.String("*dev*"), | |
}, | |
}, | |
} | |
input := ec2.DescribeInstancesInput{Filters: filters} | |
result, err := svc.DescribeInstances(&input) | |
if err != nil { | |
panic(err.Error()) | |
} | |
for _, reservation := range result.Reservations { | |
for _, instance := range reservation.Instances { | |
fmt.Printf("%s", *instance.InstanceId) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module gist.github.com/farrellit/e8b26c1f385124bb65a67bb2002a3dfe | |
go 1.13 | |
require github.com/aws/aws-sdk-go v1.26.2 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github.com/aws/aws-sdk-go v1.26.2 h1:MzYLmCeny4bMQcAbYcucIduVZKp0sEf1eRLvHpKI5Is= | |
github.com/aws/aws-sdk-go v1.26.2/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= | |
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= | |
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment