Amazon (AMZN -0.67%) and Nvidia (NVDA -0.27%) have collaborated for over a decade. The semiconductor company is the primary supplier of graphics processing units (GPUs) for the cloud platform Amazon Web Services (AWS), with Nvidia's chips also powering robots used in Amazon warehouses worldwide. 

These companies are major players in high-growth markets like cloud computing and artificial intelligence (AI), making them a powerful duo worth a stock investment. However, if you only have room for one in your portfolio, you'll need to know which is the better buy.

Let's take a closer look and find out whether Amazon's or Nvidia's stock is more likely to provide larger gains. 

Expect Amazon's dominance to continue

Despite growing positions in a wide range of markets from consumer robotics to grocery, and even space satellites, it's Amazon's e-commerce and cloud businesses that are most likely to affect its future success. As these markets have positive long-term outlooks, the company's stock could surge in the coming years.

Amazon splits its revenue between three segments: North American, international, and AWS. The first two are primarily fueled by the company's online retail website, while the third is focused entirely on its cloud earnings. The company's dependence on e-commerce sales caused its stock to plunge 50% in 2022, as an economic downturn led to reductions in consumer spending. However, the $4 trillion e-commerce market won't be down forever. It's projected to expand at a compound annual growth rate (CAGR) of 11.5% through 2027 (per Statista).

Despite last year's hurdles, the challenging year proved the strength of Amazon's diversified business model. While its e-commerce segments reported $10.6 billion in operating losses, AWS kept the company profitable with its $22.8 billion in operating income. 

Amazon is leading the way in multiple areas of tech, with its dominance likely to offer substantial earnings boosts in the coming years. As its shares are still down 35% year over year, the company's stock is a screaming buy next to its projected growth.

Nvidia's AI prospects ensure its longevity

In addition to a lucrative partnership with Amazon, Nvidia has rallied investors this year by powering OpenAI's advanced chatbot ChatGPT with its GPUs. Nvidia's growing role in AI has boosted its stock by roughly 90% in 2023 alone, with investors expecting demand for the company's chips to soar as the sector continues to expand.

The assumption has been supported by research from TrendForce, which revealed that ChatGPT utilized 20,000 GPUs in 2020 and projects that figure to soon rise to 30,000 as the platform prepares for commercialization. Additionally, the success of ChatGPT has prompted numerous other companies to develop competing services, which could also turn to Nvidia for GPU power. 

The company's success until this point mainly stemmed from its consumer PC component business, supplying its hardware to gamers worldwide. However, the past year has seen Nvidia's biggest earning business become AI, with its data center revenue rising 41% year over year in fiscal 2022.

According to Grand View Research, the AI market hit a value of $137 billion in 2022 and is expected to grow at a CAGR of 37% through 2030. Meanwhile, Nvidia's opportunity to sell its chips to the entire industry gives it massive potential in the market's future.

Is Amazon or Nvidia the better buy?

Amazon and Nvidia are both attractive long-term investments thanks to their dominant roles in several expanding markets. However, Nvidia's meteoric stock rise this year has made it slightly too expensive for now, with Amazon offering the better value. 

Nvidia's average 12-month price target of $282 accounts for about a 2% rise in its stock. The marginal increase suggests much of Nvidia's AI growth potential over the next year is already baked into its price.

Alternatively, Amazon's average 12-month price target of $137 forecasts stock growth of 35%. Considering that the company's stock is currently down by about that much on the year, it stands to reason that easing inflation and improvements in e-commerce could allow Amazon shares to hit that price.

As a result, Amazon's weaker position is a buying opportunity for investors, with its stock being the better buy over Nvidia right now.