- 
      
 - 
        
Save tuxpower/431e6327ff41b36f131b846342d2f0bb to your computer and use it in GitHub Desktop.  
    golang awssdk ec2 describe-instances
  
        
  
    
      This file contains hidden or 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-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