func (fw *Flywheel) Stop() error {
	fw.lastStopped = time.Now()
	var err error
	err = fw.stopInstances()
	if err == nil {
		err = fw.terminateAutoScaling()
	}
	if err == nil {
		err = fw.stopAutoScaling()
	}
	if err != nil {
		log.Printf("Error stopping: %v", err)
		return err
	}
	fw.ready = false
	fw.status = STOPPING
	fw.stopAt = fw.lastStopped
	return nil
}
Stop all resources managed by the flywheel
package flywheel
import (
	"log"
	"time"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/autoscaling"
	"github.com/aws/aws-sdk-go/service/ec2"
)
func (fw *Flywheel) Start() error {
	fw.lastStarted = time.Now()
	log.Print("Startup beginning")
	var err error
	err = fw.startInstances()
	if err == nil {
		err = fw.unterminateAutoScaling()
	}
	if err == nil {
		err = fw.startAutoScaling()
	}
	if err != nil {
		log.Printf("Error starting: %v", err)
		return err
	}
	fw.ready = false
	fw.stopAt = time.Now().Add(fw.idleTimeout)
	fw.status = STARTING
	return nil
}
func (fw *Flywheel) startInstances() error {
	if len(fw.config.Instances) == 0 {
		return nil
	}
	log.Printf("Starting instances %v", fw.config.Instances)
	_, err := fw.ec2.StartInstances(
		&ec2.StartInstancesInput{
			InstanceIds: fw.config.AwsInstances(),
		},
	)
	return err
}
func (fw *Flywheel) unterminateAutoScaling() error {
	var err error
	for groupName, size := range fw.config.AutoScaling.Terminate {
		log.Printf("Restoring autoscaling group %s to max/min size of %d", groupName, size)
		_, err = fw.autoscaling.UpdateAutoScalingGroup(
			&autoscaling.UpdateAutoScalingGroupInput{
				AutoScalingGroupName: &groupName,
				MaxSize:              &size,
				MinSize:              &size,
			},
		)
		if err != nil {
			return err
		}
	}
	return nil
}
func (fw *Flywheel) startAutoScaling() error {
	for _, groupName := range fw.config.AutoScaling.Stop {
		log.Printf("Starting autoscaling group %s", groupName)
		resp, err := fw.autoscaling.DescribeAutoScalingGroups(
			&autoscaling.DescribeAutoScalingGroupsInput{
				AutoScalingGroupNames: []*string{&groupName},
			},
		)
		if err != nil {
			return err
		}
		group := resp.AutoScalingGroups[0]
		instanceIds := []*string{}
		for _, instance := range group.Instances {
			instanceIds = append(instanceIds, instance.InstanceId)
		}
		_, err = fw.ec2.StartInstances(
			&ec2.StartInstancesInput{
				InstanceIds: instanceIds,
			},
		)
		if err != nil {
			return err
		}
	}
	return nil
}