Amazon (AMZN -0.58%) disappointed investors last year. Rising inflation and the general economic environment hurt earnings -- and the company even reported its first annual net loss in almost a decade. As for stock performance, Amazon finished the year in the doldrums with nearly a 50% decline.

Since then, the e-commerce and cloud computing giant has cut costs, improved productivity, and reported progress along the road to recovery. Meanwhile, investors are returning to the stock, as shares have gained about 25% so far this year.

Is Amazon stock still a buy at these levels? Let's find out.

Inflation and e-commerce

First, a look at Amazon's path so far -- from last year's troubles to today's situation. Higher inflation dealt a big blow to Amazon's e-commerce business on two levels. First, the company faced greater costs for everything from running a factory to delivering packages. And second, Amazon's customers found themselves with less money to spend.

At the same time, the company's rapid buildout of its fulfillment network led to excess capacity in such an environment. The company had doubled its fulfillment network earlier in the pandemic due to high demand. Now, with demand falling, that move weighed on Amazon.

The company's cloud computing business -- Amazon Web Services (AWS) -- continued growing sales and operating income through most of last year. But this year, AWS' operating income fell in the double digits. Amazon said that while customers were sticking with AWS, they were opting for lower-priced data-storage solutions. They, too, have been feeling the impact of rising inflation.

Amazon has taken big steps to limit the pressure on earnings and prepare for better days ahead. The company first said it would improve its cost structure -- a great move to weather the storm and make itself stronger for the future.

A new fulfillment model

Recently, Amazon announced it would cut 27,000 jobs. The company shifted investment to focus on high-growth areas, like technology infrastructure, and even changed the way the fulfillment network operates. Amazon said that in the U.S., it's shifting fulfillment to a regional model from a national one, so regional facilities mainly will be responsible for order fulfillment within their area. This should cut costs and speed up Amazon's already fast deliveries.

All of these efforts are starting to bear fruit. Amazon said in the first-quarter earnings call that it saw more growth in stores revenue and unit-sales revenue than in fulfillment and outbound shipping costs. The company also continued to improve productivity and found itself with the right level of labor to handle demand.

As a result, Amazon's operating cash flow rose 38% to more than $54 billion for the trailing 12 months. Free cash flow also improved to an outflow of $3.3 billion, compared to an outflow of more than $18 billion a year ago.

At the same time, Amazon is supporting its AWS customers by directing them to its least expensive data storage options. This is the right long-term move because it will keep them loyal to AWS -- and when their buying power returns, AWS should benefit.

Is the stock a buy?

Now let's get back to our question: Is it too late to buy Amazon shares after the gains so far this year? Today, the stock is trading for about 2x sales. That's around the lowest level by this measure since 2016.

At the same time, Amazon remains a leader in two high-growth businesses: e-commerce and cloud computing. And today's economic woes haven't changed long-term prospects for Amazon in those areas. Overall revenue continues to climb -- and customers still flock to Amazon. The company is improving its cost structure and seeing results.

Amazon's share gains show us that momentum -- and faith in the company -- may be returning. That's positive. But the increase doesn't fully reflect the company's potential. And that's why, at today's level, it's still a great investment for long-term investors.