Amazon is the latest tech giant looking to cut costs while investing in AI.