Amazon shares swung higher after the retail giant posted its fifth-straight period of profitability.