Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
golang awssdk ec2 describe-instances
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)
}
}
}
module gist.github.com/farrellit/e8b26c1f385124bb65a67bb2002a3dfe
go 1.13
require github.com/aws/aws-sdk-go v1.26.2 // indirect
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