Walmart and Microsoft are joining forces in the fight against Amazon.

Under a five-year deal announced Tuesday, Walmart will boost its use of Microsoft's cloud services and work with the tech firm on artificial intelligence and machine learning projects.

The agreement will help both companies take on Amazon.

Walmart (WMT) has been pushing aggressively to transform its digital operations in order to compete with online rivals.

And cloud computing is one of the few areas where Microsoft (MSFT) competes with Amazon (AMZN). While it's best known as an online retailer, Amazon also has a cloud service that racked up over $5 billion in sales in the first quarter.

Announced during the Amazon Prime Day sale, the deal will see Walmart shift a significant portion of walmart.com and samsclub.com to Azure, Microsoft's cloud business.

"Walmart was never going to partner with Amazon for obvious reasons and Microsoft is the second largest provider of cloud solutions in the world," said Dusan Milosavljevic, an analyst at Berenberg bank.

Walmart will also get access to artificial intelligence technology that could reduce energy consumption in its stores and machine learning expertise that would improve its delivery systems.

Related: Why Prime Day is important to Amazon

Last month, Walmart announced a new personal shopping service that lets customers order items via a text message with speedy delivery. It also launched new apps for back-to-school shopping.

Microsoft has been trying to convince retailers about the power of data and technology, working on everything from inventory to transport to online shopping.

Related: Could Ocado become the Microsoft of retail?

It has partnered with Macy's (M) to build a new "virtual shopping assistant" and with Mars Drinks to create smart vending machines. It's working with department store chain Marks & Spencer (MAKSY) in the United Kingdom.