President Donald Trump welcomes James Mattis as they pose for a photo before their meeting at Trump International Golf Club, in Bedminster Township, New Jersey.

Early in the process market leader Amazon was seen as the favorite, then President Trump said in July that he was looking into the contract after companies protested the bidding process.

The Joint Enterprise Defense Infrastructure, or JEDI, contract was awarded to Microsoft late Friday evening , sending shares of Microsoft stock up more than 3%.

An upcoming book on James Mattis' tenure as secretary of Defense claims President Donald Trump told Mattis to "screw Amazon " out of a $10 billion cloud contract for the Pentagon.

In the summer of 2018, President Trump called Mattis and directed him to "screw Amazon" out of a chance to bid on the JEDI contract, according to the forthcoming book "Holding The Line: Inside Trump's Pentagon with Secretary Mattis." The account was written by Guy Snodgrass, who served as a speechwriter for Mattis.

"Relaying the story to us during Small Group, Mattis said, 'We're not going to do that. This will be done by the book, both legally and ethically,'" Snodgrass writes. CNBC has reviewed the relevant passages of the book.

The Department of Defense and the White House could not be immediately reached for comment. Neither Amazon nor Microsoft were immediately available for comment on the president's alleged order.

The contract is capped at $10 billion over the next ten years. If it ends up being worth that much, it would likely be a bigger deal to Microsoft than it would have been to Amazon. Microsoft does not disclose Azure revenue in dollar figures but it's widely believed to have a smaller share of the market than Amazon, which received $9 billion in revenue from AWS in the third quarter.

"We're surprised about this conclusion," an AWS spokesperson told CNBC in an email on Friday, after the contract was awarded to Microsoft. "AWS is the clear leader in cloud computing, and a detailed assessment purely on the comparative offerings clearly lead to a different conclusion. We remain deeply committed to continuing to innovate for the new digital battlefield where security, efficiency, resiliency, and scalability of resources can be the difference between success and failure."