A few years ago, Amazon (AMZN -1.77%) wowed investors with its earnings increases and top positions in the high-growth industries of e-commerce and cloud computing. The company is still a leader in these two big markets. But Amazon has slipped up in the earnings department.

That's mainly due to today's tough economy. As a result, Amazon shares have dropped more than 35% over the past year.

I've got some good news for you, though: Amazon's troubles won't last forever -- and the company has what it takes to excel over the long term. All of this means it's a great idea to buy this monster stock before it pops. Let's find out more.

Temporary problems

Let's talk about why Amazon's problems are temporary. In 2022 Amazon reported its first annual loss in eight years. That's as higher inflation hurt the company in two ways.

Amazon's costs climbed -- everything from running a warehouse to shipping goods. And Amazon's customers, also hurt by rising inflation, found themselves with less money to spend.

At the same time, Amazon recorded a pre-tax valuation loss linked to its stock investment in Rivian Automotive. The company also struggled with excess capacity across its fulfillment network -- Amazon had quickly doubled the network after high demand during the earlier stages of the pandemic.

All of the above issues, external or internal, are not ones likely to linger over time. And Amazon is showing it has the strength to manage during this difficult period. The company is improving its cost structure -- and this includes plans to eliminate 27,000 jobs this year.

Amazon also reduced spending by $10 billion last year in areas including fulfillment and transportation to better match supply to demand. But this doesn't mean Amazon is cutting everything. The company also is investing in an area likely to strongly rebound and lead growth over time. I'm talking about its cloud computing business, Amazon Web Services (AWS).

Amazon increased investment by $10 billion last year in technology infrastructure to support its crown jewel of a business. It's important to remember that, even if AWS also is facing a slowdown today, it's a key growth element for the company. The business generally has made up most of Amazon's total operating income.

Setting itself up for a win

Today, AWS customers are watching their budgets -- and AWS is serving them with less expensive data storage options. This is great because AWS' efforts are keeping customers on board. And when the economic environment improves, these customers likely will return to usual spending levels. So, it's clear that AWS is setting itself up for a long-term win.

Now let's turn to the e-commerce business. It's struggled more than AWS. After all, AWS managed to still report double-digit sales growth in the last quarter.

But even though inflationary pressures are hurting e-commerce now, I'm still optimistic about this business over time. Here's why. Amazon continues to grow its Prime subscription service. And if you pay the annual membership fee, it's likely you'll try to get the most out of it by doing a lot of your shopping on Amazon.

The company has seen positive trends in Prime. For example, The Lord of the Rings: The Rings of Power last year drove more worldwide Prime signups during its launch than any other Prime video offering. Amazon said adding to Prime video content is proving to be worth the investment -- driving member engagement and new signups.

All of this means that once economic troubles ease, Amazon's earnings should improve. That's great news for the stock price over the long haul. But when will the stock take off? It could happen at any point as investors start to plan ahead for better times.

Right now, though, the one good thing about seeing this stock in the doldrums is the fact that you can scoop it up at a low price. Amazon is trading around its lowest in relation to sales since 2015. And that makes today a good moment to get in on this top long-term stock -- before it pops.