Amazon (AMZN -1.27%) stock has had a fantastic 2023, up nearly 65% so far this year. However, that comes after a terrible 2022 during which the stock lost 50% of its value. Even after the recent rebound, Amazon shares remain 16% below where they ended 2021 -- and 25% below their all-time high set in mid-2021.

I would argue that Amazon is just getting started -- and its third-quarter results provide good evidence. As such, the stock still looks like an outstanding buy with upside much higher than its previous all-time high. Here's why.

Efficiency improvements were on display in Q3

While Amazon is best known for its e-commerce business, that's not the reason to invest in it. Although that business is the most prominent and largest part of Amazon, it has posted poor growth for multiple quarters in a row. Last quarter was no exception as e-commerce revenue grew 7% year over year -- and that was the fastest growth rate since Q3 2022.

The real reason to invest in Amazon is its various other services, which are higher-margin and are growing much faster. Third-party seller services, advertising, and Amazon Web Services (AWS) are becoming more integral parts of Amazon.

However, AWS posted another disappointing quarter, only growing 12% year over year. While AWS is still first in cloud infrastructure market share, top rivals Microsoft Azure and Alphabet's Google Cloud posted much better quarters, growing 29% and 22%, respectively. The slowdown for AWS was caused by customers optimizing their cloud spending to reduce costs, a common trend in 2023.

Amazon management stated in the latest conference call that new deals are starting to pick up. Additionally, AWS is seeing strong demand for its large language model artificial intelligence (AI) technology, further bolstered by its $4 billion deal with Anthropic.

Another trend has been CEO Andy Jassy's push toward making Amazon a more efficient business. He has laid off employees, trimmed spending, and cut certain money-losing programs. While his work is far from finished, the results have been astounding since he took over in Q3 2021.

AMZN Operating Margin (Quarterly) Chart

AMZN Operating Margin (Quarterly) data by YCharts.

The latest quarter's 7.8% margin is within spitting distance of Amazon's all-time-high quarterly operating margin of 8.2% set in Q2 2021, right before founder Jeff Bezos left his role as CEO. This is a testament to Jassy's leadership and vision, and it excites me about the future with him at the helm.

The stock is both cheap and expensive

Despite all of this, the stock still seems cheap, at least by one valuation measure. There are many ways to value Amazon stock, but the two most applicable are the price-to-sales ratio and forward price-to-earnings ratio.

Amazon's earnings have been up and down over the past few years, so using sales is a good way to compare its current valuation to its historical state.

AMZN PS Ratio Chart

AMZN PS Ratio data by YCharts.

From this perspective, Amazon is valued at around the same level as in 2015 and 2016, which is quite cheap considering the transformation the business has undergone.

As Amazon's earnings picture improves, the price-to-earnings  ratio becomes more meaningful. Because that transition is ongoing, it would be better to use Amazon's forward price-to-earnings ratio, which considers analysts' projections.

AMZN PE Ratio (Forward) Chart

AMZN PE Ratio (Forward) data by YCharts.

From this standpoint, Amazon stock is quite expensive. But with its improving earnings picture, this ratio should come down over time.

While the valuation conclusion of Amazon's stock is a wash, the long-term investment picture for Amazon is still bright. I think we haven't scratched the surface of what Amazon can be, and Jassy's leadership and vision to become the most efficient version of Amazon will make it a market-crushing stock over the next five years.