“Despite continued inflationary pressures in fuel, energy, and transportation costs, we’re making progress on costs,” said CEO Andy Jazzy.

Updated at 4:49 pm EST

Amazon Inc  (AMZN) – Get Amazon.com Inc. Report posted a second consecutive quarterly loss Thursday,  but blew past Street sales forecasts and booked solid gains from its market-leading cloud division, sending shares sharply higher in after-hours trading.

Amazon said its second quarter loss was pegged at $2 billion, or 20 cents per share, down from a profit of 76 cents per share over the same period last year and notably short of the Street consensus forecast of 13 cents per share profit. Amazon’s stake in Rivian cost the group around $3.9 billion, which it included in non-operating income expenses. 

Revenues rose 7.2% from last year to $121.2 billion, firmly ahead of analysts’ estimates of a $119.08 billion tally. Amazon Web Services contributed $19.74 billion, rising 33% from last year. Ad sales were also higher, rising 4.3% to $8.76 billion. Online store sales, however, fell 4.3% to $50.885 billion.

Walmart’s  (WMT) – Get Walmart Inc. Report profit warning from earlier this week, linked in part to higher-than-expected inventory levels and ongoing inflation pressures that have cut into profit margins, had set the stage for a weaker reading from Amazon.

However, with the bulk of its sales filtering through from third-party sellers, Amazon did not suffer from the same inventory bloat, and its cash-generating web services division helped offset the online sales decline.

“Despite continued inflationary pressures in fuel, energy, and transportation costs, we’re making progress on the more controllable costs we referenced last quarter, particularly improving the productivity of our fulfillment network,” said CEO Andy Jassy. 

“We’re also seeing revenue accelerate as we continue to make Prime even better for members, both investing in faster shipping speeds, and adding unique benefits such as free delivery from Grubhub for a year, exclusive access to NFL Thursday Night Football games starting September 15, and releasing the highly anticipated series The Lord of the Rings: The Rings of Power on September 2,” he added.  

Amazon shares were marked 12.2% higher in after-hours trading immediately following the earnings release to indicate a Friday opening bell price of $137.15 each. 

Amazon completed its planned 20-for-1 stock split in early June, taking the per share price closer in line with mega-cap tech peers such as Apple  (AAPL) – Get Apple Inc. Report, Google parent Alphabet  (GOOGL) – Get Alphabet Inc. Report and Meta Platforms  (META) – Get Meta Platforms Inc. Report.

Looking into the current quarter, Amazon said it sees operating income of between zero and $3.5 billion, on revenues in the range of $125 billion to $130 billion, compared to the Refinitiv forecast of around $126.5 billion.