US stocks close higher in whipsaw session as Amazon gives big boost to tech shares