The COVID-19 pandemic led to a boom in cloud computing as hybrid workstyles meant more companies had to take their businesses online. Meanwhile, recent advances in artificial intelligence (AI) have the potential to significantly enhance cloud services. As a result, companies in both markets have become compelling investments thanks to their long-term prospects.

Advanced Micro Devices (AMD 1.36%) and Amazon (AMZN 1.49%) each have solid positions in cloud computing and AI, making their stocks great options in which to invest in these burgeoning markets. However, if you only have room for one in your portfolio, you'll need to know which is the better buy.

So, let's consider whether you're better off with AMD or Amazon's stock.

Advanced Micro Devices: Home to powerful hardware

AMD's stock plunged 55% in 2022 as PC market declines meant reduced sales of its consumer graphics processing units (GPUs) and processors. As a result, in fiscal 2022, the company's PC-centered client segment reported a 10% year-over-year decline in revenue of $6.2 billion. 

However, AMD has proven the strength of its business by finding more lucrative and less consumer-reliant applications for its products. For example, in the same year, its data-centers segment had revenue rise 64% to $6 billion. The growth was largely fueled by cloud development. AMD's GPUs and processors power data centers worldwide, which host cloud platforms such as Amazon Web Services (AWS), Microsoft's Azure, and Alphabet's Google Cloud. 

Additionally, AMD's hardware has the power to run and develop AI software, which could mean substantial gains over the long term. According to Grand View Research, the AI market was valued at roughly $137 billion in 2022 and is projected to expand at a compound annual growth rate (CAGR) of 37.3% through 2030.

Meanwhile, research from TrendForce shows AI program ChatGPT will likely increase its demand for GPUs from 20,000 to 30,000 as it prepares for commercialization. Nvidia is currently the main supplier of GPUs for ChatGPT. However, with countless competing services under development, the likelihood of other companies turning to AMD for GPU power is high.

Amazon: A cloud computing king

While AMD offers an opportunity to invest in the hardware side of the cloud and AI markets, Amazon is an excellent option in which to invest in its software thanks to its cloud platform Amazon Web Services (AWS). The Amazon service held a leading 34% market share in the cloud industry as of the third quarter of 2022, with Microsoft's Azure second at 21%.

The cloud market is expected to grow at a CAGR of 14.1% through 2030, valued at $484 billion in 2022. As the market's leader, Amazon has significantly profited from cloud growth. In 2022, AWS revenue climbed 29% to $80 billion. The segment also accounted for all of Amazon's profits for the year, earning $22.8 billion in operating income.

Moreover, the rise of AI could significantly boost the number of AWS users because of its dominating position in cloud computing. The platform already offers a variety of AI services, such as data extraction, chatbot builder tools, speech recognition, and more. With the rising likelihood of more businesses leaning on AI services, Amazon is well positioned to profit from the market's development.

AMD and Amazon both have attractive long-term outlooks thanks to their participation in two high-growth markets. However, AMD's role as a hardware supplier means it can provide its wares to any company across the AI and cloud markets, strengthening its prospects with the ability to diversify. Meanwhile, Amazon is in direct competition with tech giants like Microsoft and Alphabet, with no guarantees that it will come out on top. As a result, AMD's stock is the more reliable and better buy for the long haul.