So Amazon can, but Walmart can't

If Walmart opened a store and sold items at below cost until their local competitors disappeared, Walmart would be breaking the law. How does Amazon get away with it? The shipping for a battery I bought from them had to cost more than the battery. It weighed forty pounds and I had it within two days included with Prime.