Skip to content

Instantly share code, notes, and snippets.

@tuxpower
Forked from farrellit/ec2-describe-instances.go
Created February 1, 2018 13:24
Show Gist options
  • Save tuxpower/431e6327ff41b36f131b846342d2f0bb to your computer and use it in GitHub Desktop.
Save tuxpower/431e6327ff41b36f131b846342d2f0bb to your computer and use it in GitHub Desktop.
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-east-1")}))
svc := ec2.New(session)
filters := []*ec2.Filter{
&ec2.Filter{
Name: aws.String("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)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment