The Nasdaq Composite index has climbed about 118% over the last five years despite the COVID-19 pandemic and an economic downturn in 2022. The figure illustrates how lucrative investing in certain companies and holding even amid poor market conditions can be.

Consequently, it's not a bad idea to invest in some of the Nasdaq Composite's most prominent players with plans to hold over many years. As the world's second and sixth most valuable companies, Apple (AAPL -0.82%) and Amazon (AMZN -0.09%) are two attractive options.

These companies dominate their respective industries and have created many millionaires over the years, with Apple's stock up 319% since 2019 and Amazon's up 96%. Meanwhile, Apple and Amazon have some exciting developments in the pipeline that could deliver major gains in the coming years.

So, here are two magnificent stocks that have created millionaires and will continue to make more.

1. Amazon

One of the most attractive aspects of Amazon is its thoroughly diverse business model. The company is best known as a king of e-commerce, with its leading 38% market share in the industry. Amazon's dominance in online retail is demonstrated by Walmart's second-largest market share in e-commerce, responsible for just 6% of the sector.

Amazon's retail business remains a lucrative venture, with revenue in its North America and International segments rising 12% year over year and 10% in the first quarter of 2024. Meanwhile, retail operating income achieved a combined $6 billion, significantly improving on the negative $349 million it posted in the year-ago quarter.

However, Amazon is a lot more than e-commerce. The company is home to the world's largest cloud platform, Amazon Web Services (AWS), which reported sales growth of 17% year over year in Q1 2024 (its largest rise in a year). AWS' operating income rose 84% to more than $9 billion during the quarter, with the cloud service responsible for 62% of Amazon's total operating income despite earning the lowest portion of revenue between its three main segments.

In addition to stellar retail and cloud growth, Q1 2024 suggested that the company could have a lucrative future in digital advertising -- a market predominantly dominated by Alphabet and Meta Platforms. The quarter saw revenue from advertising services soar 24%, with much of that growth thanks to the introduction of ads on its Prime Video streaming service.

Amazon's stock trades at about 40 times its forward earnings, indicating that it's not exactly a bargain. However, the company's stock has already risen 20% year to date. Alongside significant growth potential in multiple markets, Amazon's stock is likely worth its premium price tag and could make you a millionaire with the right investment.

2. Apple

Apple has a long history of providing loyal investors with consistent and significant gains. However, repeated hits to its business and concerns over product sales have seen its stock decline 1% since the start of 2024. The company's long-term relevancy has been questioned as product sales dipped and crucial markets like China increasingly prefer domestic offerings over Apple's.

Yet, Apple is making moves to boost its product business with the help of artificial intelligence (AI). Meanwhile, a rapidly expanding services business is gradually allowing the company to depend less on product sales.

Shares in Apple have popped 16% in the last month, almost entirely thanks to its expanding efforts in AI. The company rallied investors in early May when it debuted its newest iPad Air. The tablet is the first device to use Apple's most powerful chip yet, the M4, which is said to vastly expand the company's AI capabilities.

Additionally, Apple plans to revamp its Mac lineup and aspects of its smartphones to better cater to the rising demand for AI services.

Despite recent headwinds, Apple remains a behemoth in consumer tech. Billions of consumers continue to choose its products over rival devices, giving the company ample opportunity to tout its AI products.

In addition to a solid outlook in AI, Apple's digital services division is booming. In the second quarter of 2024 (ended March 2024), the segment posted revenue growth of 14% year over year, significantly outperforming all other segments. The trajectory of services is promising for Apple's future as it allows the company to lean less on its products' business over time, fortifying it against macroeconomic headwinds.

With a price-to-earnings ratio of 29, there might be better-valued options than Apple. However, the figure is significantly lower than Amazon's 40 and Microsoft's 36, potentially making Apple one of the best-valued AI stocks. In addition to a potent position in tech, Apple is worth considering right now and one that could make you a millionaire.