Everyone likes a deal. The months-long sell-off that led to the current bear market has resulted in many stocks trading at valuations that would be considered cheap in a normal market environment.

However, just because a stock is down doesn't necessarily mean it's a buy. As Warren Buffett famously said, "Only when the tide goes out do you discover who's been swimming naked." Put another way, some companies' stocks are trading at a discount for a reason.

Handled properly, though, a bear market does present savvy long-term investors with generational buying opportunities, as long as they pick strong businesses that have what it takes to keep growing. Let's take a look at two comparatively cheap tech stocks that I think are worth buying now and holding for the long run.

1. Amazon

With a price-to-sales (P/S) multiple of 2.2, you'd have to go back to 2016 to find a time that Amazon (AMZN -1.65%) was trading this cheaply. While that alone isn't a reason to buy, there are a few other reasons that Amazon is worth buying now.

Amazon reported its Q1 2022 earnings recently and revenue was up only 7.3% to $116 billion. While that's a very low year-over-year growth rate for the company, it's also coming off a Q1 2021 where revenue grew 44%. Over the last two years, revenue has increased 54%, which is strong two-year growth.

More important for long-term investors is the rapid growth of Amazon Web Services (AWS), which was up 37% year over year in Q1 and 34% annually over the last two years. AWS now accounts for 16% of Amazon's overall revenue, up from 13% in the year-ago quarter. 

Amazon is already the leader in cloud infrastructure, but the total market was estimated to be $380 billion in 2021. Amazon had $62 billion in AWS revenue in 2021, showing the vast market still available to capture.

2. Apple

It may be difficult to believe that one of the largest companies in the world could be considered cheap, but that's where we find ourselves with Apple (AAPL 0.52%). With a price-to-earnings (P/E) ratio of 21.5, Apple stock is actually below the S&P 500's P/E of 24.1. 

For a company trading below the market's average valuation, it's putting up above-average results. Apple's revenue in Q2 of fiscal 2022 (ended March 26) was $97 billion (a Q2 record), and it was up 9% year over year. All but one of its product categories saw growth, and the company generated over $25 billion in free cash flow.

Apple is using this cash to reward shareholders. In addition to its dividend, Apple has been buying back stock and has reduced its shares outstanding by 22% over the past five years.

While most investors know Apple because of its products, the company's services segment has quietly become its second-largest revenue generator after the iPhone. The Services segment, which consists of products like iCloud, Apple Music, and other subscriptions, now accounts for more than 20% of total revenue, up from 19% in the year-ago quarter. 

Services revenue is also high margin, which has helped gross margin improve from 42.5% to 43.8% over the past year. As investors, this helps instill confidence that the profitability and cash generation is here to stay.

Why are these a buy now?

It could be argued that Amazon and Apple are so big and mature as businesses that their best days of price appreciation are behind them. There may have been a stronger case for that when valuations were near all-time highs. At today's prices, I think there are still plenty of upsides for investors from here.

Additionally, with inflation at 40-year highs and uncertainty about the economy in the near term, companies that are cash flow positive are great anchors in a portfolio. Neither of these companies will need to access the debt markets as interest rates rise, and both have the track record and market positioning to weather any economic storm

There may be higher-growth tech stocks out there, but few will also provide the downside protection as these two will. That's why I think they're both stocks to buy right now.