Strong cloud demand driven partly by artificial intelligence contrasts with slowing online retail and advertising growth, intensifying scrutiny of Amazon’s investments.