Amazon's (AMZN -0.01%) efforts to reduce costs in the retail business, including optimizing inventory at its fulfillment centers, is starting to pay huge dividends on the bottom line. The business generated an impressive $50 billion in free cash flow over the trailing-12-month period, a massive turnaround from negative $3 billion in the same period a year ago.

Amazon's growing free cash flow is already paving the way for more aggressive capital investments in Amazon Web Services (AWS) -- the company's highly profitable cloud-services business. This could have positive implications on the stock's returns over the next several years.

Are investors underestimating Amazon's cloud opportunity?

Amazon's cloud business is starting to see accelerating growth again as companies adopt artificial intelligence (AI) services. Over the last four quarters, Amazon Web Services (AWS) generated $29 billion of operating profit on $94 billion of revenue.

On the first-quarter earnings call in April, CEO Andy Jassy said there were "unbelievable growth opportunities in front of us." Jassy explained that most of the world's spending on information technology is still on legacy, on-premise servers that companies manage themselves. That leaves a gigantic opportunity for cloud-computing providers like AWS.

The increasing adoption of chat-based AI assistants, or generative AI, is providing a strong incentive for these companies to move IT spending from on-premise to the cloud. In Q1, revenue from AWS grew 17% year over year, accelerating from 13% in 2023's Q4.

At its current rate of growth, AWS revenue could double again in the next five years; given that it already generates most of Amazon's operating profit, growth in AWS will move the needle for the share price.

However, AWS can't continue to grow without more data-center capacity. That's why Amazon's $50 billion in free cash flow will be valuable as Amazon tries to protect its lead in the cloud-services market.

Amazon spent $14 billion in capital expenditures in Q1, primarily to expand its AWS infrastructure and generative AI efforts, and management expects it to increase from there. Most of its capital spending this year will go to support AWS infrastructure and generative AI efforts.

Why buy Amazon stock

While Amazon's capital-spending plan could pressure profits within the AWS segment this year, Amazon has a history of realizing high returns on its investments.

For example, despite building a transportation network the size of UPS during the pandemic, and tripling its capital expenditures to over $60 billion in the process, Amazon's net income is now at record highs. Its retail operation is now focused on bringing down costs of delivering goods to customers, including increasing the number units shipped per box, which could bring even more upside to the bottom line and grow its free cash flow over the next several years.

AMZN Chart
AMZN data by YCharts.

Amazon's market cap (share price times the total shares outstanding) is now close to $2 trillion.

However, AWS alone could be worth almost half of that, or $940 billion, applying a price-to-sales (P/S) multiple of 10 to its annual revenue of $94 billion. That is an average valuation for a fast-growing software business. A few years ago, Redburn analyst Alex Haissl estimated AWS was on a path to reach a $3 trillion value. If that estimate is accurate, it would mean Amazon's shares are undervalued by a good margin.

Amazon doesn't spend money unless it sees a clear path to generating returns, so investors should expect AWS to become more profitable and grow Amazon's free cash flow.

Analysts project Amazon's earnings per share to grow at an annualized rate of 23% over the next several years, which could also be used as a reasonable estimate for free-cash-flow growth. That's more than enough growth to double the share price within the next five years.