Amazon (AMZN 1.30%) and Tesla (TSLA 1.85%) both brought great returns to investors over the past two years. During that time, Amazon climbed more than 80%, and Tesla soared a mind-boggling 1,160%. The reasons were simple: The pandemic drove more and more shoppers to Amazon, and Tesla, already the electric vehicle (EV) market leader, significantly ramped up deliveries.

Today, long-term prospects continue to look great for both companies. But higher inflation and the general market decline has weighed on Amazon and Tesla shares. Their prices have each lost more than 30%. At these levels, both companies look like a buy. But if you could only buy one, which should you opt for? Let's take a closer look to find out.

The case for Amazon

Amazon is a leader in two major businesses: e-commerce and cloud computing. Right now, inflationary pressures are hurting Amazon's e-commerce operation. Costs of transporting goods have skyrocketed. But the company is working to manage certain costs that it can control. That should help it weather this storm.

Meanwhile, Amazon's Prime membership program should help drive future growth. The company said in its most recent earnings report that members are depending more and more on its platform for shopping and entertainment. 

As for cloud computing, Amazon Web Services (AWS) continues to increase sales and operating income by double digits. At the same time, Amazon is expanding AWS infrastructure across the globe, meaning it is likely to keep on growing. This business generally has represented most of Amazon's total operating income, so it's a key profit driver for the company.

Now let's look at valuation. Amazon is trading at 52 times trailing-12-month earnings. The stock traded at these levels, and higher, prior to the launches of the Prime program and AWS. Considering the revenue that Prime and AWS have generated -- and should continue to generate in the future -- the stock looks cheap today.

The case for Tesla

Higher inflation, supply chain issues, and chip shortages haven't made things easy for Tesla in recent times. Still, the company managed to report record revenue, vehicle deliveries, and operating profit in the first quarter. All of this, and an operating margin of more than 19%. At the same time, Tesla is ramping up production at two new factories: one in Austin, Texas, and another in Berlin.

Tesla's financial picture also looks bright. The company's free cash flow and return on invested capital have been on the rise.

TSLA Free Cash Flow Chart

TSLA free cash flow. Data by YCharts.

Tesla had about $18 billion in cash and equivalents at the end of the first quarter. And total debt fell to less than $1 billion from $1.4 billion at the end of last year. The company aims to increase vehicle deliveries 50% annually on average over a period of years.

Today's headwinds could weigh on earnings on the short term and put the brakes on a share price rebound. Still, at the current level, the stock looks like a bargain, trading at 58 times forward earnings estimates. That's down from more than 90 earlier in the year.

Amazon or Tesla?

Which company is a better buy now? It depends on your comfort with risk. Tesla could have potential for greater gains, but it's a riskier bet than Amazon. First, its shares tend to be more sensitive to news -- good or bad. Also, Tesla depends on one business: EVs. And competition might heat up as other automakers fight for market share. I do believe it has what it takes to dominate over time. But any market share gained by a rival could weigh on investor sentiment for Tesla shares.

Amazon probably won't climb as quickly as Tesla on any potential good news, so gains may be slower. But Amazon's dominance in two big businesses adds a layer of safety to this stock. Even if higher inflation persists and weighs longer than we'd like on e-commerce, AWS could continue to boost revenue. And that could reassure investors.

All of this means that if you're a cautious investor, you might be better off buying Amazon today. But if you have a stronger appetite for risk, you might want to go for Tesla. Once the current headwinds ease, the stock could take off with great speed.