Amazon (AMZN -1.64%) and its investors didn't have the best 2022. The stock lost nearly 50%, and the company reported its first annual loss in almost a decade.

Higher inflation and a rapid ramp-up of its fulfillment network were costly for the company. And investors started to wonder just how long this e-commerce giant's earnings and share price would remain in the doldrums.

Fast forward to today, and Amazon's luck seems to have changed. The stock has soared more than 40% so far this year. And earnings are showing signs of improvement.

But this isn't exactly "luck." Amazon has made efforts to turn things around -- and investors have taken notice.

Now you may be thinking of the company's future potential: Should you buy, sell, or hold this popular stock? Let's find out.

The impact of rising inflation

First, let's look at the recent past, and that means Amazon's troubled times. Rising inflation has hurt the company in two big ways. It weighed on Amazon's costs and left consumers with less money to spend on Amazon.com. It also left businesses with smaller budgets to spend on Amazon Web Services' (AWS) cloud computing offerings.

Another problem? After enormous demand during the early days of the pandemic, Amazon quickly doubled its fulfillment network. But in more recent times, it hasn't been able to use all that capacity. As a result, the company's free cash flow turned to a significant outflow, and the company, as mentioned above, shifted to a loss.

But Amazon took action right away to tackle these headwinds. It immediately worked on its cost structure and announced 27,000 job cuts for this year. It also reduced spending in certain areas and increased investment in high-growth areas such as technology infrastructure to support AWS.

Even though AWS' operating income shifted to a decline over the past couple of quarters, revenue continues to grow. And AWS is generally Amazon's biggest profit driver. 

Speaking of AWS, Amazon also is directing those customers to its least expensive data storage options. This means less income for Amazon in the near term -- but it's a smart long-term strategy. The effort should keep AWS customers happy and ready to increase their spending on cloud services once the economic situation improves.

A big change to the fulfillment model

I also like the efforts Amazon is making concerning its fulfillment operations in the U.S. The company has switched to a regional model from a national model. This is positive for two reasons.

First, by transporting items shorter distances, Amazon will save money and time. That's great for earnings and efficiency. Second, the new process will make package delivery faster. This should please customers -- and could encourage people to stick with their Prime memberships.

What's really exciting is that some of these efforts already are bearing fruit. In the most recent earnings report, operating income increased 29% to $4.8 billion. The company reported net income of more than $3 billion, recovering from a net loss in the year-earlier period. And Amazon's outflow of cash, at about $3 billion for the trailing 12 months, improved from more than $18 billion a year ago.

So let's get back to our question: Should you buy, sell, or hold Amazon stock? The shares have climbed quite a bit so far this year, and that may limit further near-term gains.

Near term versus long term

The key words here are "near term." Yes, in the second half of the year, Amazon may not climb as much as it did in the first. But I'm still in favor of buying or holding this stock because Amazon has great potential over the long term.

And despite recent gains, the stock hasn't become too expensive. Amazon's shares still trade for only 2x sales. This is much lower than their level by this measure just a few years ago.

AMZN PS Ratio Chart

AMZN P/S Ratio, data by YCharts.

The stock looks reasonably priced, especially considering that Amazon's efforts today are starting to show results. But this is just the beginning.

Thanks to Amazon's leadership in e-commerce and cloud computing -- two fast-growing markets -- it's set to benefit as the economy recovers. And it has made cost-structure improvements that could boost earnings over the long run.

As an investor, I don't want to miss out on that. That's why I don't plan on selling my Amazon shares any time soon.