ec2 := ec2.New(session.New(), &aws.Config{ Region: aws.String("us-west-2"), }) instance, err := ec2.RunInstances(&ec2.RunInstancesInput{ ImageID: aws.String("ami-0c55b159cbfafe1f0"), InstanceType: aws.String("t2.micro"), MinCount: aws.Int64(1), MaxCount: aws.Int64(1), }) if err != nil { log.Fatal(err) } fmt.Printf("Launched instance %v\n", *instance.Instances[0].InstanceID)
ec2 := ec2.New(session.New(), &aws.Config{ Region: aws.String("us-west-2"), }) resp, err := ec2.DescribeInstances(nil) if err != nil { log.Fatal(err) } for _, reservation := range resp.Reservations { for _, instance := range reservation.Instances { fmt.Printf("Instance ID: %s\n", *instance.InstanceID) } }This code uses the `DescribeInstances` function to list all EC2 instances in the us-west-2 region. It loops through the reservations and instances returned and prints out each instance's ID. Overall, the goamz.ec2 package is a powerful library for managing EC2 instances and related resources in Go programs.