Investor expectations were low heading into Amazon's (AMZN -2.41%) second-quarter earnings report Thursday afternoon. After all, the tech stock had already lost 27% this year coming into its quarterly update. The pandemic tailwinds it once enjoyed have faded, and the broader tech sell-off has weighed on it.

However, Amazon's latest earnings report was a reminder of why the e-commerce stock has been one of the biggest winners in the market over the last generation. In a tough environment, Amazon beat both analyst expectations and its own guidance, driving the stock up 13% after hours on Thursday.

Revenue increased 7%, or 10% in constant currency, to $121.2 billion, ahead of the Wall Street consensus at $119.1 billion and the company's own guidance of $116 billion to $121 billion. Operating income of $3.3 billion was down from $7.7 billion in the quarter a year ago, as shopping habits have shifted away from e-commerce. Still, that figure topped the company's guidance of negative $1 billion to $3 billion in operating income.

Its GAAP per-share loss of $0.20 includes a non-cash pretax valuation loss of $3.9 billion on its investment in electric-vehicle maker Rivian, so a comparison with the analyst consensus of a $0.13 per-share profit isn't relevant.

Growth where it matters

Single-digit revenue growth is uncharacteristic for Amazon, which has put up quarterly revenue growth of 20% or more for most of its history. The company best known to consumers for its dominance in e-commerce lost money in both of its online retail segments in the quarter.

In North American e-commerce, which includes the company's highly profitable advertising business, net sales increased 10% to $74.4 billion. But it posted an operating loss of $627 million, which compared to a profit of $3.1 billion in the quarter a year ago.

In the international segment, where the company has long struggled to turn a profit, revenue fell 12% (or 1% in constant currency) to $27.1 billion. Amazon lost $1.8 billion outside North America, down from a $362 million profit in Q2 2021.

The reason why Amazon stock popped double digits on the report was the surging growth in its cloud infrastructure business, Amazon Web Services (AWS). Revenue at AWS rose 33% to $19.7 billion, and operating income jumped 36% to $5.7 billion, giving it a run rate of nearly $25 billion in operating income this year, based on its first-half total of $12.2 billion in operating profits.

That means that AWS on its own generates more profit than almost any other U.S. company, and at this point, it's the only source of meaningful profit for Amazon. That's why the cloud division's operating income is the most important number for investors to watch. 

What Amazon's results means for investors

Though the struggles in the e-commerce business may attract headlines, what really matters to investors is the performance of AWS, which has been the company's primary profit center for years. As long as AWS continues to grow at a strong rate, Amazon stock should move higher over the long term.

The good news for investors is that the current headwinds in the e-commerce business should eventually end. Like a lot of its peers in the tech sector, Amazon overexpanded during the pandemic, adding too much capacity and hiring too many warehouse workers, which helps explain its more than $2 billion in losses in e-commerce in the quarter.

In fact, the company's total employee count declined sequentially by 99,000 in the quarter to 1.52 billion, a sign it chose not to replace some of the warehouse workers who quit in the April to June period. CFO Brian Olsavsky said on the earnings call that the company expected to grow into its excess capacity in the second half of the year, which will improve profitability.

In addition to the upside in e-commerce, Amazon's third-quarter guidance indicates that revenue growth is already reaccelerating. For the current quarter, management called for 13% to 17% revenue growth (or 17% to 21% growth in currency-neutral terms) to $125 billion to $130 billion, which compares to analyst estimates of $126.4 billion. On the bottom line, it sees operating income of $0 to $3.5 billion in the third quarter, below the $4.9 in operating income it made in Q3 2021.

After a successful Prime Day earlier this month and with the holiday quarter to look forward to, Amazon's stiffest headwinds in e-commerce are likely behind it. That tailwind, combined with strong growth in AWS, means that the stock has probably bottomed out from the sell-off. For Amazon investors, the second half of the year should be much more rewarding than the first half.