SAN FRANCISCO (Reuters) - The tech industry maxim that "no one ever got fired for buying IBM" is a testament to how Big Blue has been the gold standard in computing services for decades.

But IBM faces an unlikely challenger in Amazon.com Inc, the e-commerce retail giant that is becoming a force in the booming business of cloud computing, even winning backing from America's top spy agency.

After years of being dismissed as a supplier of online computer services to startups and small businesses, Amazon Web Services (AWS) beat out International Business Machines this year to snag a $600 million contract with the Central Intelligence Agency.

IBM has successfully appealed its loss in the contest, stalling it for now. But the episode highlights how Amazon is evolving from an online retailer into a competitive provider of information technology and services to big companies, and government bodies.

That has helped push Amazon shares to a new record ahead of the company's second-quarter results due on Thursday. Amazon doesn't break out AWS results, but Wall Street believes it is expanding faster than the retail business and is more profitable.

"AWS is one of the main spokes of the bull case on Amazon shares," argues Ron Josey, an analyst at JMP Securities. "Software and IT investors are aware of and are trying to size AWS, and what the impact could be on their sector."

IBM is entrenched in corporations across the globe; and with one of the industry's biggest research budgets, is likely to remain so for some time. But it and other players like Oracle are taking note of AWS as cloud computing takes off.

Public cloud computing, which AWS pioneered in 2006, lets companies rent computing power, storage and other services from data centers shared with other customers - typically cheaper and more flexible than maintaining their own.

Amazon has begun to build a portfolio of significant clients, including Samsung, Pfizer, the Public Broadcasting Service and NASA, the U.S. space agency.

That unexpected threat is rippling through the sector. After two quarters of falling sales, Oracle announced partnerships in June with former foes Microsoft and Salesforce.com, a response in part to AWS's expansion.

"AWS is having a really meaningful impact on IT and the big incumbent companies like IBM are reacting to that now," said Colby Synesael, an analyst at Cowen & Co, who covers RackspaceHosting, one of Amazon's main rivals in the cloud.

FROM BOOKSTORE TO TECH

Amazon began life as an online bookseller, but in past years has expanded into everything from tablet computers to video. Critics say it is spending heavily with little regard for the bottom line.

But its stock hit a record $309.39 on July 16 and is up more than 22 percent this year. In contrast, Oracle is down 4 percent in 2013. IBM, which reported a fifth straight quarterly sales fall on Wednesday, is up 1 percent. (For a chart: http://link.reuters.com/nah79t)

AWS slashed prices on one of its popular services, EC2, this month and Rackspace shares promptly slid, leaving them down more than 45 percent so far this year.

AWS generates at least $2 billion a year in revenue now from a total pie of more than $60 billion, according to analysts who expect that to quintuple to more than $10 billion in coming years, partly driven by higher government cloud spending.

The tussle with IBM over the CIA contract has helped burnish Amazon's credentials, increasing Wall Street's confidence in the ability of AWS to compete with the big boys of enterprise IT.

Five companies vied for the contract - AWS, IBM, Microsoft, AT&T and another unidentified firm, according to a report on the bidding by the U.S. Government Accountability Office.

When AWS won, IBM protested, triggering the report by the GAO. The agency recommended in June that the CIA re-do some parts of its contract negotiations, giving IBM another chance.

But the GAO also stated that AWS's offering was superior.

"In every technical criterion Amazon out-scored IBM, one of the most sophisticated and capable IT companies in the world," said Carlos Kirjner, an analyst at Bernstein Research.

The CIA had "grave" concerns, according to the GAO report, about IBM's ability to provide "auto-scaling," a feature that automatically adds or removes computing power in response to applications use.

"Auto-scaling is very complex and there are not many cloud providers that can do it well, but Amazonis great at it," said Kyle Hilgendorf, a cloud computing analyst at Gartner. "I don't think anyone thinks IBM has a better cloud service."

IBM spokesman Clint Roswell said there were "inaccuracies" in the government's assessment of its CIA proposal.

"IBM remains committed to providing enterprise-level secure and robust cloud solutions and looks forward to a renewed opportunity to show our capabilities to fulfill the requirements of this important agency," he added.

An Amazon spokeswoman declined to comment on the CIA contract. A CIA spokesman also declined to comment.

IBM bought SoftLayer Technologies, a rival to AWS, for $2 billion in June. That could help it when the CIA comes calling again, said Bill Moran at Ptak Associates.

"They do not need any other issue like 'auto-scaling' to bedevil them the next time around," he added.

(Editing by Edwin Chan, Edward Tobin and Tim Dobbyn)