Amazon lost big in after-hours and pre-market trading, after posting its first quarterly loss in many years.