Amazon (AMZN 6.19%) stock has seen some big swings over the last couple of years. Since the e-commerce and cloud-infrastructure services leader hit an all-time valuation high in July 2021, macroeconomic trends including high levels of inflation and rising interest rates spurred a dramatic pullback for the company's share price. Even after rallying 43% across 2023's trading, Amazon stock remains down roughly 36% from its peak.

With its online retail and cloud services businesses still looking strong and its digital ads unit evolving into a significant performance driver, the tech giant is worth investing in while it still trades at a significant discount compared to its previous high. And with the company likely on track to see powerful benefits from the rise of artificial intelligence (AI) technologies, Amazon has the makings of a growth stock that's worth holding for the ultra-long term. 

Amazon is showing it can be flexible

Amazon's first-quarter results arrived with better-than-expected sales and earnings performance. The company showed that it can effectively manage costs amid the less favorable operating backdrop brought on by macroeconomic headwinds. 

Amazon grew sales 9% year over year in the first quarter to reach $17.4 billion. With operating income of approximately $4.77 billion in the quarter, the company recorded an operating income margin of roughly 3.7%. The Amazon Web Services (AWS) segment contributed $5.12 billion to the operating income pool in the period, which, along with an $898 million contribution from Amazon's North American geographic segment, was enough to offset the operating loss generated by the company's international segment.

Thanks to continued growth for AWS and cost-cutting initiatives, Amazon was able to grow operating income 30% year over year last quarter. The company is demonstrating flexibility and navigating unfavorable macro conditions efficiently.

AWS is a powerhouse with untapped growth potential

Growth and margins for AWS are being constrained by macroeconomic pressures, but eventual improvements for economic conditions and other catalysts have the potential to push the cloud unit back to stronger momentum. In particular, CEO Andy Jassy sees the rise of artificial intelligence and machine learning applications creating a big increase in computing demand, and the cloud giant appears to be in a good position to benefit.

In April, the company announced Amazon Bedrock -- a new platform integrated into AWS that makes it easier for customers to build, deploy, and scale generative AI applications. It also recently debuted CodeWhisperer -- a generative AI tool that allows users to input simple requests and receive the code needed to run that kind of application.

Amazon is providing features that can help AWS customers drive superior productivity and efficiency, and the company likely remains in the early stages of rolling out and benefiting from artificial intelligence technologies. 

E-commerce is still a massive opportunity for Amazon

Amazon's online retail unit has powerful warehousing and distribution advantages. The company's logistics network is unparalleled in most of the markets in which it operates, and it will likely continue to become stronger from here on out.

With the rise of AI, robotics, and other automation technologies, Amazon's scale and resource advantages are on track to become even more pronounced. Crucially, these trends have the potential to transform the profitability picture for its e-commerce business. 

Last quarter, Amazon's North American segment posted an operating profit margin of just 1.2%, and its international segment recorded a roughly $1.25 billion operating loss. Online retail is a low-margin business, but increased automation has the potential to make the company's e-commerce operations significantly more profitable. Given Amazon's massive sales base, improvements in e-commerce margins stand to have a big impact on the company's bottom line. 

Amazon is shaking up the digital ads industry

Amazon's fast-growing advertising business also continues to hold a lot of promise. Revenue for advertising services climbed 23% year over year in Q1 to reach $9.5 billion despite some powerful headwinds shaping the broader digital ads industry. To put that performance in perspective, Alphabet's market-leading Google ads business fell just short of its revenue from last year's first quarter, and second-place player Meta Platforms' ad revenue climbed roughly 4% year over year.

Amazon already ranks as the third-largest digital ads player in the U.S., and it's rapidly gaining market share. The company is showing that it can leverage foundations created by its e-commerce business and strengths in machine learning to advance other growth drivers, and it looks like there's still plenty of upside in the advertising business. 

Amazon has the makings of a great long-term investment

While the company is facing some headwinds and near-term trading could be volatile, there's a good chance that Amazon can bounce back and go on to reach new valuation highs within the next few years. The tech giant has powerful competitive strengths, and it should be able to capitalize on growth opportunities in its core business categories and score wins with AI and other emerging trends.

For investors seeking great growth stocks, Amazon stands out as a smart buy-and-hold play right now.