Amazon (AMZN 3.43%) had its share of tough times last year. The e-commerce giant swung to its first annual loss in a decade as rising inflation chipped away at profit. The company faced higher costs -- and so did its customers, meaning they had less to spend on Amazon.com.

Considering this and the general economic gloom, Amazon's shares suffered. The stock lost nearly 50% last year. But Amazon has taken measures to turn things around. And the stock has even rebounded, advancing more than 50% so far this year. Now, you may be wondering if Amazon can keep up the pace and what its second half may look like. Well, it might be a spectacular one. Let's find out why.

A brighter outlook than expected

First, it's important to look at the economic environment. Yes, it remains complicated. But the outlook might be a bit brighter than expected. Earlier in the year, the Federal Reserve modeled for a mild recession later in 2023. But more recently, the Fed changed course, saying a recession probably isn't in the cards. And officials didn't raise interest rates in June. All of this is positive news for households -- and, in turn, for companies like Amazon.

Less pressure on consumers' wallets and companies' budgets means it may be easier for them to spend on general merchandise and cloud computing services offered by Amazon. And that could help Amazon's earnings and share price.

Against this better-than-expected economic backdrop, Amazon may also benefit from the various moves it's made over the past year. Faced with rising inflation, the company decided to improve its cost structure. Amazon announced 27,000 job cuts this year. The company also shifted investment into its highest-growth areas, such as technology infrastructure to support its cloud computing business. Amazon Web Services (AWS) generally has been Amazon's profit driver, so focusing investment here is a smart move.

Amazon also has been working to streamline its fulfillment network after a rapid buildup left it with excess capacity. One big move was the shift to a regional model in the U.S. from a national one. This cuts down on delivery times and costs -- a winning deal for customers and for Amazon.

These efforts already have started to bear fruit. For example, in the most recent quarter, Amazon's operating income climbed and the company greatly decreased its outflow of cash. In fact, return on invested capital has already started to rebound. This is important because it signals Amazon is benefiting from its investments. I would expect to progressively see more of these trends in the second half of the year.

AMZN Return on Invested Capital Chart

AMZN Return on Invested Capital data by YCharts

The power of Prime Day

Finally, Amazon's Prime Day event -- right at the start of the third quarter -- could give revenue a solid boost. The company reached a new Prime Day record, with spending of $12.7 billion in the U.S. alone, according to Adobe Analytics. That's an increase of more than 6% year over year.

Prime Day was the country's biggest day of online spending so far this year, Adobe data show. Amazon itself doesn't report Prime Day sales figures. But it's clear this shopping event is set to lift the company's revenue figure for the quarter -- and the full year.

So, what does this mean for investors? Amazon shares have climbed quite a bit this year. And some worry they've gone too far too fast. It's impossible to predict whether they'll continue at this pace or pull back. But, considering Amazon's track record and future prospects, it's clear the shares have room to run over the long term.

And, considering the points above, the company could deliver a spectacular second half from an earnings perspective. That doesn't mean Amazon's profit will soar to new highs. That will take time. But I would expect significant improvement through the second half of the year.

All of this means now is a great time to buy or hold Amazon shares -- and keep them in your portfolio for the long term. There's reason to believe that the second half of this year could be just the beginning of a new chapter of growth.