// This function gets the state of a single instance and returns the code for it. func getInstanceState(instanceid string, ec2client *ec2.EC2) (int64, error) { //Build the struct to hold our instance ID we're requesting instanceReq := ec2.DescribeInstanceStatusInput{ InstanceIds: []*string{ aws.String(instanceid), }, } //Make the request to the API instanceResp, err := ec2client.DescribeInstanceStatus(&instanceReq) if err != nil { return -1, err } //We only requested one instance, so we should only get one if len(instanceResp.InstanceStatuses) != 1 { return -1, errors.New("The total number of instances did not match the request") } //Finally, let's get the code and return it. instance := instanceResp.InstanceStatuses[0] return *instance.InstanceState.Code, nil }