Пример #1
0
func (c *ENIClient) DescribeInstancesByIDs(instanceIDs []string) ([]*model.Instance, error) {
	p := &ec2.DescribeInstancesInput{
		InstanceIds: aws.StringSlice(instanceIDs),
	}
	resp, err := c.svc.DescribeInstances(p)
	if err != nil {
		return nil, err
	}

	instances := make([]*model.Instance, 0)

	for _, r := range resp.Reservations {
		for _, i := range r.Instances {
			instances = append(instances, model.NewInstance(i))
		}
	}

	return instances, nil
}
Пример #2
0
func (c *ENIClient) DescribeInstanceByID(instanceID string) (*model.Instance, error) {
	p := &ec2.DescribeInstancesInput{
		InstanceIds: []*string{aws.String(instanceID)},
		MaxResults:  aws.Int64(1),
	}
	resp, err := c.svc.DescribeInstances(p)
	if err != nil {
		return nil, err
	}

	if len(resp.Reservations) < 1 {
		return nil, nil // Not found
	}

	instances := resp.Reservations[0].Instances

	if len(instances) < 1 {
		return nil, nil // Not found
	}

	return model.NewInstance(instances[0]), nil
}