/**
  * Disassociates and releases the currently assigned ip from elastic ip and creates and assign new elastic ip to the active instance.
  * @param null $instanceId
  *
  * @throws \Exception
  */
 public function refreshIp($instanceId = null)
 {
     if ($instanceId == null) {
         $instanceId = $this->getActiveInstanceId();
         if ($instanceId == null) {
             throw new \Exception("Active instance not found to assign ip");
         }
     }
     $currentIp = $this->getIp($instanceId);
     try {
         $this->disAssociateElasticIP($currentIp);
     } catch (\Exception $ex) {
         echo $ex->getCode() . " : " . $ex->getMessage() . "\n";
     }
     $newAddress = $this->ec2Client->allocateAddress();
     $newIp = $newAddress['PublicIp'];
     $this->associateElasticIP($instanceId, $newIp);
     $this->releaseElasticIp($currentIp);
 }