func (es *ECSService) ServiceRollback(serviceName, clusterName, taskARN string) error {
	updateInput := &ecs.UpdateServiceInput{
		Cluster:        aws.String(clusterName),
		Service:        aws.String(serviceName),
		TaskDefinition: aws.String(taskARN),
	}
	_, err := es.client.UpdateService(updateInput)
	switch e := err.(type) {
	case nil:
		return nil
	case awserr.Error:
		if e.Message() != "TaskDefinition is inactive" {
			return e
		}
	default:
		return fmt.Errorf(awsApisErrorFmt, err)
	}
	describeInput := &ecs.DescribeTaskDefinitionInput{
		TaskDefinition: aws.String(taskARN),
	}
	out, err := es.client.DescribeTaskDefinition(describeInput)
	if err != nil {
		return fmt.Errorf(awsApisErrorFmt, err)
	}
	taskDef := out.TaskDefinition
	registerInput := &ecs.RegisterTaskDefinitionInput{
		ContainerDefinitions:    taskDef.ContainerDefinitions,
		Cpu:                     taskDef.Cpu,
		ExecutionRoleArn:        taskDef.ExecutionRoleArn,
		Family:                  taskDef.Family,
		Memory:                  taskDef.Memory,
		NetworkMode:             taskDef.NetworkMode,
		PlacementConstraints:    taskDef.PlacementConstraints,
		RequiresCompatibilities: taskDef.RequiresCompatibilities,
		TaskRoleArn:             taskDef.TaskRoleArn,
		Volumes:                 taskDef.Volumes,
	}
	registerOut, err := es.client.RegisterTaskDefinition(registerInput)
	if err != nil {
		return fmt.Errorf(awsApisErrorFmt, err)
	}
	if es.verbose {
		fmt.Printf("%q new task definition registered with configuration from %q\n", *registerOut.TaskDefinition.TaskDefinitionArn, taskARN)
	}
	updateInput.TaskDefinition = registerOut.TaskDefinition.TaskDefinitionArn
	_, err = es.client.UpdateService(updateInput)
	if err != nil {
		return fmt.Errorf(awsApisErrorFmt, err)
	}
	return nil
}
ServiceRollback updates a service to use a specific task version. If task is
INACTIVE a new one is created with the old configuration.
package aws
import (
	"fmt"
	"net/http"
	"os"
	"strconv"
	"strings"
	"time"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/awserr"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/ecs"
)
const awsApisErrorFmt = "error on AWS request: %s"
type ServiceInfo struct {
	ARN     string
	TaskARN string
}
type ECSService struct {
	verbose bool
	client  *ecs.ECS
}
func (es *ECSService) ServicePreviousVersion(serviceName, clusterName string) (string, error) {
	taskARN, err := es.getCurrentTask(serviceName, clusterName)
	if err != nil {
		return "", fmt.Errorf(awsApisErrorFmt, err)
	}
	tt := strings.Split(taskARN, ":")
	currentVersionStr := tt[len(tt)-1]
	currentVersion, err := strconv.Atoi(currentVersionStr)
	if err != nil {
		return "", err
	}
	previousVersion := currentVersion - 1
	if previousVersion <= 0 {
		return "", fmt.Errorf("impossible to rollback to version %d", previousVersion)
	}
	previousVersionStr := strconv.Itoa(previousVersion)
	return strings.Join(append(tt[:len(tt)-1], previousVersionStr), ":"), nil
}