Amazon (AMZN 0.80%) may be one of investors' biggest disappointments of 2022. We'd gotten used to major growth in earnings, free cash flow, and return on invested capital over time. And then, in about a year, many of those key measures plummeted. That's as higher inflation and other economic headwinds hurt Amazon.

Today, Amazon is trading at its lowest in relation to sales since 2015. This looks like a rare buying opportunity for a stock that maintained growth for so long.

So, should you scoop up Amazon stock before it rallies? Or is it a better idea to wait and see? Let's find out.

Amazon's bad year

First, let's talk a little bit about Amazon's bad year. The stock lost nearly 50% in 2022. In the third quarter, Amazon's operating income and operating cash flow declined in the double digits. And Amazon's free cash flow shifted to an outflow of $19.7 billion for the trailing 12 months. That's compared to an inflow of $2.6 billion in the year-earlier period.

The reasons for this are pretty straightforward. Rising inflation is increasing Amazon's costs on everything from shipping goods to maintaining warehouses. It's also weighing on consumers' wallets. Even the cloud computing business -- Amazon Web Services (AWS) -- faces customers with less spending power these days.

The challenge of unfavorable currency exchange rates also is hurting Amazon. This means sales made abroad are worth less when turned into dollars.

Finally, the e-commerce giant overbuilt its fulfillment network during the earlier stages of the pandemic -- and that's increasing costs now.

All of these elements have weighed on margins and earnings. As a result, investors turned away from this once-popular stock.

It's impossible to predict the exact timing of an Amazon rally. But this stock has what it takes to rebound and even soar over time. Here's why.

First, today's economic troubles won't last forever. Economic growth always follows downturns. And bear markets lead to bull markets. History offers us proof. We just have to be patient.

Cash level and cost cuts

Amazon has the strength to make it through today's tough times. The company has about $35 billion in cash and equivalents. At the same time, it's making efforts to cut costs -- and that should help it weather the storm and come out stronger.

Amazon is improving its cost structure. And the company recently increased the number of job cuts planned to 18,000 from 10,000.

Considering Amazon's future prospects, the next reason to be confident is Amazon's leadership in two high-growth markets: e-commerce and cloud computing.

E-commerce may be difficult today. But the market still is expected to register double-digit growth this decade. Amazon, with its Prime subscription service, is in the perfect position to benefit. Prime members are spending more and more on Amazon -- and since they pay a membership fee for Prime, it's in their best interests to favor shopping there.

Cloud computing may represent an even bigger opportunity. That's because Amazon doesn't have to wait for recovery here. AWS still is reporting double-digit revenue and operating income growth -- in spite of today's economic situation.

And even if that growth does slow this year, it's likely to pick up again -- and fast -- once the economy strengthens. Like the e-commerce market, cloud computing is expected to grow in the double digits this decade.

Long-term prospects

Let's get back to our question: Should you buy Amazon before it rallies? My answer is a big "yes." As I mentioned, it's impossible to time the market and guess exactly when Amazon will recover. Since the stock looks cheap now and long-term prospects are bright, it's a great idea to jump in.

Sure, it's possible the shares will slip further. But if you plan on holding Amazon for at least five years, fluctuations now shouldn't greatly impact your returns. Amazon has already brought great gains to investors over time. And this top e-commerce company has what it takes to deliver a repeat performance to those who are willing to stick with it for the long term.