Amazon, a company known for spending like a drunken sailor, appears to have sobered up. At least for now.

James Martin/CNET

The world's largest online retailer on Thursday reported unexpectedly strong sales and earnings in the first quarter, blowing out analysts' projections and driving shares up more than 12 percent after hours. Big gains in its Amazon Web Services cloud-computing business helped the company report its fourth-straight profitable quarter and its best-ever quarterly profit.

This was not business as usual.

Amazon typically posts razor-thin (or nonexistent) earnings despite skyrocketing revenue. That's because CEO Jeff Bezos consistently makes huge investments in things like new distribution centers, consumer electronics, original TV programming, grocery deliveries -- and much more.

None of those investment projects will go away anytime soon. But the retailer may finally be making good on Wall Street's expectations that it will, someday, become a fantastically profitable company.

"I think we may have hit a point where it's going to be hard for them to spend enough to hide all this profitability," said Scot Wingo, executive chairman of e-commerce consultant ChannelAdvisor.

Even as operating expenses surged 25 percent during the quarter, revenue was even stronger. Sales reached $29.1 billion, up 28 percent, while Amazon swung to a profit of $513 million, from a loss of $57 million the year earlier. To put that figure in perspective, Amazon posted a profit of $596 million for all of 2015.

Amazon Web Services, which rents out computer server space to other companies, was a major contributor to the earnings boost. Operating income from the division reached $604 million, up from $195 million a year ago.

"AWS just continues to be a steamroller," Wingo said.

But fans of Amazon's Prime membership club shouldn't feel like the company will ignore them for the cloud anytime soon. During a conference call with analysts, Amazon finance chief Brian Olsavsky emphasized the importance of investing in Prime, which offers free, two-day shipping for $99 a year. Prime has an estimated 55 million to 60 million members worldwide and grew by 51 percent last year.

"We think there's a lot of room to grow, not only in international countries but also in the US," he said. "We plan on continuing to build the benefits of the Prime program, from music to video to two-day shipping to same-day shipping to Prime Now, so I don't see that dissipating."

Amazon is taking a "long-term approach" to building Prime Now, its free, two-hour delivery service that's available only in certain cities, Amazon executive Phil Hardin said, noting the Prime-only service's logistical difficulty and expense.

Amazon continues to test different ideas with grocery deliveries, Olsavsky said, including its Prime Pantry service and Prime Now, as it looks for the best approach. The company has a grocery service called AmazonFresh in a handful of cities, but has been slow to grow the program.

The company this month started allowing customers to buy Prime on a monthly basis, instead of only annually, which could help Amazon reach new customers with the program.

For the current quarter, Amazon predicted stronger-than-expected sales of up to $30.5 billion and another period of robust operating profit, reaching up to $975 million.