The e-commerce giant has been cutting costs while pouring resources into building data centers to compete in the race to dominate artificial intelligence.