def primary_deployment(cluster)
      # Try to describe the existing service.
      description = begin
        Ecs.describe_services(cluster.name, [@name])
      rescue => e
        puts "Error: #{e}"
        nil
      end

      missing_service_warning = <<-STR
Can't find an existing service '#{name}'.  You'll probably need to
register one manually using the AWS console and set up any load balancers
you might need.
      STR

      if description.nil?
        puts missing_service_warning
        return nil
      end

      unless service = description.fetch("services")[0]
        puts missing_service_warning
        return nil
      end

      # Find the primary deployment.
      deployment = service.fetch("deployments").find do |d|
        d["status"] == "PRIMARY"
      end
      return nil if deployment.nil?

      # Extract a task definition `name:revision`.
      arn = deployment.fetch("taskDefinition")
      arn.split('/').last
    end
def primary_deployment(cluster)
      # Try to describe the existing service.
      description = begin
        Ecs.describe_services(cluster.name, [@name])
      rescue => e
        puts "Error: #{e}"
        nil
      end

      missing_service_warning = <<-STR
Can't find an existing service '#{name}'.  You'll probably need to
register one manually using the AWS console and set up any load balancers
you might need.
      STR

      if description.nil?
        puts missing_service_warning
        return nil
      end

      unless service = description.fetch("services")[0]
        puts missing_service_warning
        return nil
      end

      # Find the primary deployment.
      deployment = service.fetch("deployments").find do |d|
        d["status"] == "PRIMARY"
      end
      return nil if deployment.nil?

      # Extract a task definition `name:revision`.
      arn = deployment.fetch("taskDefinition")
      arn.split('/').last
    end
Get the existing "PRIMARY" deployment for the ECS service
 corresponding to this task definition, and return it in
 `name:revision` format.  Returns `nil` if it can't find a primary
 deployment.