Stock market declines plagued 2022, with numerous companies suffering losses as they faced macroeconomic headwinds. Despite its leading market share in multiple industries, Amazon's (AMZN -1.95%) stock was not left unscathed, falling 50% over the 12 months.

However, the company has made an impressive comeback in 2023. Shares of Amazon skyrocketed about 83% year to date as solid growth in its e-commerce earnings and a rapidly expanding position in artificial intelligence (AI) has made Wall Street bullish again.

Amazon's meteoric rise might suggest the company won't have much more to offer in the new year. However, despite the bull run, the stock remains down 18% from its high in 2021. Meanwhile, various cost-cutting moves have bolstered the company's profitability, and dominating roles in two lucrative markets suggest it is nowhere near hitting its ceiling.

Here's why Amazon's stock remains an attractive option ahead of 2024.

Heading into 2024 in better financial health than it started this year

Amazon started 2023 at a disadvantage, reporting more than $10 billion in operating losses between its two retail segments in the previous fiscal year and a sunken stock price. As a result, it immediately got to work, with CEO Andy Jassy announcing on Jan. 5 a plan to lay off more than 18,000 employees.

The decision came after other cost-cutting measures, such as closing or canceling construction on dozens of warehouses, putting a freeze on hiring, and shuttering its telehealth brand Amazon Care.

The restructuring has been a massive success, with Amazon's North America segment posting operating income exceeding $4 billion in the third quarter of 2023. The segment significantly improved after suffering $412 million in losses in the year-ago period.

AMZN Free Cash Flow Chart

Data by YCharts

Moreover, this chart shows Amazon's free cash flow has soared 427% to $17 billion year to date, significantly outperforming all other companies in what's considered the Big Five of tech.

Amazon is heading into the new year on considerably better financial footing than at the start of 2023. With lower expenses after cost cuts, more cash reserves, and improving economic conditions, Amazon is an exciting buy before 2024.

Amazon stock has plenty of room left to run

Amazon dominates two crucial markets: e-commerce and cloud computing. Both sectors are expanding quickly, and Amazon is well positioned to see significant gains from their growth long into the future.

The online retail industry alone is worth $3 trillion and is projected to expand at a compound annual growth rate (CAGR) of 10% until at least 2028 (per Statista). Meanwhile, Amazon has become a king in e-commerce, holding a leading 38% market share in the U.S. Comparatively, Walmart has the second-largest share with 6%.

That's all before considering the best reason to invest in the company -- its cloud business, Amazon Web Services (AWS). The platform accounts for 32% of the industry, more than Microsoft's Azure or Alphabet's Google Cloud.

Its dominant role in the sector helped Amazon carve out a lucrative role in AI, an industry expected to grow at a CAGR of 37% through 2030. Over the last year, AWS has worked to meet the rising demand for AI cloud services by introducing a range of new tools to its platform. Programs like Bedrock, CodeWhisperer, and HealthScribe are all generative applications that help businesses boost efficiency by integrating AI into their workflows.

AMZN EPS Estimates for Current Fiscal Year Chart

Data by YCharts

And it's not just about market growth potential. According to this chart, Amazon's earnings could exceed $4 per share by fiscal 2025. Multiplying that figure by the company's forward price-to-earnings ratio of 58 yields a stock price of $271, projecting growth of 76% within the next two years.

Alongside significant growth in its free cash flow this year, Amazon's stock is a no-brainer buy for 2024.