You've probably had just about enough of the bear market by now. For many if not most investors, it's weighed on their portfolios. And it's hurt the performance of even the strongest of companies. But that doesn't mean you should forget about investing. In fact, the best thing to do right now is invest.

So, what kind of company can help you shake the bear market blues? Answer: a company that has a long track record of earnings and share-price performance. And ideally, you can get this stock for a bargain. Amazon (AMZN -1.64%) fits the bill. Let's take a closer look at why this stock is a buy right now.

A solid track record

Amazon has grown revenue and profit over time -- into the billions of dollars. And the share price has followed. It's climbed more than 160% over the past five years.

But this e-commerce and cloud computing giant hasn't been immune to the troubles plaguing many companies these days. Higher inflation and supply chain problems have weighed on the company's financial performance.

And there have also been issues particular to Amazon. For example, Amazon doubled its fulfillment network in less than two years to keep up with demand during parts of the pandemic. But earlier this year, the company found itself with too much capacity.

The good news is Amazon is making progress in addressing some of these recent challenges. And the business that's been a key profit driver -- Amazon Web Services (AWS) -- is growing in leaps and bounds.

Managing tougher times

Let's take a look at how Amazon is managing these tougher days. In the first quarter, Amazon reported $6 billion in incremental costs. The company pledged to reduce those costs -- and it did. In the second-quarter earnings report on July 28, Amazon said its incremental costs totaled $4 billion.

The company also made better use of its fulfillment network, and improved staffing levels and delivery speed. All of this helped spur demand. If we exclude the impact of foreign currencies, revenue rose 10% in Q2 to more than $121 billion, which surpassed the company's forecast.

Q2 showed Amazon successfully managing these tough times -- not getting stuck in them. (Any troubles Amazon is facing mainly concern the company's e-commerce business.)

If we look at AWS, the cloud computing business, the picture looks even brighter. The difficult economic environment hasn't hurt AWS. In fact, this business reported a 36% gain in operating income and a 33% increase in net sales. AWS is the global leader in the cloud computing market. It holds a 33% share, according to Synergy Research Group.

AWS driving growth

Importantly, AWS continues to gain new contracts. For example, in Q2, Delta Air Lines chose AWS for the revamp of its digital business. And AWS is expanding its infrastructure. It plans to open 24 more availability zones across eight regions. Amazon CFO Brian Olsavsky said during the earnings call that the adoption of cloud services still is in the early stages. This means AWS can drive much more growth at Amazon in the years to come.

And the great news for investors is shares of this innovative company are on sale right now. They're trading for 65 times trailing-12-month earnings. Two years ago, they traded for about 125, and at that time, the company's revenue was lower than it is today.

AMZN PE Ratio Chart

AMZN PE Ratio data by YCharts.

So, what happens if you buy Amazon shares right now? I don't expect an immediate recovery in earnings or share performance. But Amazon has shown in just one quarter it could make the changes needed to face today's headwinds.

I'm optimistic the company can continue along this path. Amazon's track record shows it has delivered gains over the long term. It looks like the company can do that again. And that's exactly why this is a stock you'll want to snap up during the bear market.