One of retailers' biggest enemies is rising inflation. And that's one of the key elements that hurt e-commerce giant Amazon (AMZN 3.20%) last year. It did this in two ways.

First, it meant higher costs for everything from running a warehouse to shipping goods. Second, customers had less money to spend on Amazon.com and on the company's cloud-computing services.

As a result, Amazon reported a rare annual loss. And the stock spent the year in the doldrums.

But things have turned around for Amazon. Its latest earnings report looked brighter than those of the past few quarters, and the stock has climbed more than 40% this year. So you may be wondering: Is it too late to buy this supercharged stock? Let's find out.

Doubling the fulfillment network

First, let's take a quick look into the recent past. As mentioned above, rising inflation has weighed on Amazon. But other factors presented challenges, too.

After soaring sales in the early pandemic days, Amazon quickly doubled its fulfillment network. The problem was it eventually found itself with too much capacity. Finally, a stock investment in Rivian Automotive left Amazon with a billion-dollar pre-tax valuation loss last year.

As all of this unfolded, Amazon set to work on a recovery plan, and that included improving its cost structure. This is important because it's helping Amazon manage now, during tough times, and should also help the company excel later, during better economic times.

As part of this, Amazon announced the elimination of 27,000 jobs. The company also revamped its U.S. fulfillment network, shifting to a regional model from a national model. Now, instead of shipping a package from one part of the country to another, a center closer to the destination usually will handle the fulfillment. This should cut down on costs and delivery time.

Amazon also has reduced investments in certain areas while reinforcing investments in others most likely to spur growth. For example, last year, Amazon increased investment by $10 billion in technology to support its cloud-computing services business, Amazon Web Services (AWS). Though that business is seeing a slowdown, too, it generally drives Amazon's overall profit.

Speaking of AWS, Amazon's strategy here may surprise you, but it's actually a great long-term decision. AWS customers' budgets are suffering these days, so they don't have as much to spend on cloud services. AWS is directing them to its lowest-cost solutions, which is resulting in declining operating income at the business right now.

But this is the right move because it's keeping AWS customers loyal. Once their budgets improve, it's likely they'll stick with AWS, and move back to the higher-priced services they went for before.

A boost to earnings and investor sentiment

All of these efforts are helping Amazon's earnings and investor sentiment. In the first-quarter earnings report, Amazon greatly reduced its outflow of cash. The company reported an outflow of about $3 billion for the trailing 12 months, compared with an outflow of more than $18 billion in the year-earlier period.

Even through the toughest times, Amazon's net sales increased. So people and businesses continue to flock to the company. Amazon leads in two industries growing in the double digits: e-commerce and cloud computing. It should benefit from this over the coming years.

Things look pretty bright for Amazon today and in the future. But let's get back to our question: Is it too late to buy the stock?

Not if you're a long-term investor. Amazon is trading for about 2 times sales. In recent years, it's traded for more than double that.

Right now, Amazon is just at the beginning of its recovery. There's still a lot more to come. I also expect e-commerce and cloud-computing growth to take off once the economic situation improves -- and share performance could follow. All of that means now is a great time to buy Amazon and hold for the long haul.