Shares of retail and cloud computing behemoth Amazon (AMZN 0.01%) rallied 44.4% in 2024, according to data from S&P Global Market Intelligence.

Like most of the "Magnificent Seven," Amazon had a great 2024 as investors piled into large-cap technology stocks participating in the artificial intelligence (AI) revolution.

But Amazon had also entered the year with some big questions hanging over it, as investors wondered whether it had fallen behind rivals in the AI race. Yet over the course of the year, Amazon put many of those concerns to rest.

Amazon ups its AI game

Coming into 2024, some thought Amazon was caught late to the AI game. After all, cloud rival Microsoft invested early in OpenAI, the company behind ChatGPT, which appeared to give Microsoft the early lead in AI cloud workloads.

But did anyone think Amazon, of all companies, would take this lying down? Since 2023, Amazon has gotten to work on its own AI cloud services.

First, leveraging its size as the largest cloud provider heading into the AI revolution, Amazon rolled out its Bedrock cloud services in mid-2023. Amazon Bedrock offers a variety of competing third-party large language models for developers, giving perhaps the most diversified AI tool portfolio of any cloud provider.

Additionally, in late 2023, Amazon invested in OpenAI rival Anthropic, which is run by OpenAI's ex-vice president of research, Dario Amodei, and is available on Bedrock. Amazon then followed up that initial investment with two more investments in Anthropic in 2024. Amazon's latest investment in November amounted to $4 billion, bringing its total investment in Anthropic to $8 billion.

In conjunction with that investment, Anthropic agreed to use AWS as its primary cloud provider and training partner, while also committing to use Amazon's Trainium and Inferentia chips to train and run its future AI models.

The collaboration appeared to both validate Anthropic as a key player in the AI races and a serious OpenAI competitor, while also validating Amazon's in-house chips as worthy tools against the current AI training standard of expensive Nvidia GPUs.

Hands type on a keyboard with letters AI above them.

Image source: Getty Images.

But it wasn't just press releases and investments that drove Amazon higher; positive financial results did, too. AWS revenue growth accelerated 19% in the third quarter, up from 12% a year earlier. And perhaps just as important, the segment's operating margin expanded from 30.3% to 38.1% over that same period.

Not to be outdone or forgotten, Amazon's e-commerce segment also picked up the pace and expanded margins, too. Amazon's North America and International e-commerce empires continued their solid growth in the high-single-digits and low-double-digits, respectively. Meanwhile, North America e-commerce operating margins expanded by a full percentage point, from 4.9% to 5.9%, while the International business expanded margins from -0.3% to a positive 3.6% margin over the past year.

Amazon spent the past couple of years cutting costs and transitioning to a regional delivery system in its e-commerce business, and this year's rapid margin expansion appears to show those efforts paying off.

Amazon is a stock to own, not trade

Amazon has demonstrated resilience in the face of several bear markets and recessions over its corporate life. After a difficult post-pandemic slowdown, the past year's improvements show Amazon's management culture to be as smart and resilient as it's ever been, even following the 2021 retirement of founder Jeff Bezos.

While the stock can't be considered cheap at 35 times this year's earnings expectations, Amazon has always appeared expensive to many, as it has long prioritized long-term thinking over short-term profits. That being said, the company's ability to expand profit margins this year after the rapid rise in interest rates since 2022 speaks volumes about Amazon's dynamism.

With this commitment to both innovation and long-term returns on investments, Amazon remains a solid core holding for any investor with a longer-term investment horizon beyond five years.