github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/aws/start_instance.go (about)

     1  package aws
     2  
     3  import (
     4  	"github.com/aws/aws-sdk-go/aws"
     5  	"github.com/aws/aws-sdk-go/service/ec2"
     6  	"github.com/emc-advanced-dev/pkg/errors"
     7  )
     8  
     9  func (p *AwsProvider) StartInstance(id string) error {
    10  	instance, err := p.GetInstance(id)
    11  	if err != nil {
    12  		return errors.New("retrieving instance "+id, err)
    13  	}
    14  	param := &ec2.StartInstancesInput{
    15  		InstanceIds: []*string{
    16  			aws.String(instance.Id),
    17  		},
    18  	}
    19  	ec2svc := p.newEC2()
    20  	_, err = ec2svc.StartInstances(param)
    21  	if err != nil {
    22  		return errors.New("failed to start instance "+instance.Id, err)
    23  	}
    24  	waitParam := &ec2.DescribeInstancesInput{
    25  		InstanceIds: []*string{aws.String(instance.Id)},
    26  	}
    27  	err = ec2svc.WaitUntilInstanceRunning(waitParam)
    28  	if err != nil {
    29  		return errors.New("waiting until instance running", err)
    30  	}
    31  	return nil
    32  }