NEW YORK (AP) — Amazon has reported its second-consecutive quarterly loss but its revenue topped Wall Street expectations, sending its stock sharply higher. The Seattle-based e-commerce giant Amazon lost $2 billion, or 20 cents per share, in the three-month period ended June 30, driven by a $3.9 billion write-down of the value of its stock investment in electric vehicle start-up Rivian Automotive. It posted revenue of $121.2 billion, topping Wall Street expectations of $119 billion. The results came as the company attempts to navigate shifting consumer demand and higher costs, while curtailing the glut of warehouses it acquired during the COVID-19 pandemic. Its stock rose 12% in after-hours trading.