Costco needs their customers to love their products
in aggregate, but not any one product in particular. They're good about quality, so I don't really have to care about brands. If I want detergent or paper towels or whatever, I just pick whatever looks good. If they pull one in favor of another, I don't care. If you want to buy specific brands on any given trip, Costco isn't for you, but if you just want something decent and don't care who made it, it works out well. You don't have to love the specific brands, just the stuff they carry in general.
I'm sure Amazon could cause a lot of trouble for Costco if they can match their prices or come close, but I don't see that happening. I basically buy three categories of products at Costco: frozen food, fruit, and non-perishable bulk items like paper towels or toilet paper. I can't see Amazon ever coming close on the first two, simply because the inherent costs of delivering perishable items to the house are too high. They can pull off Prime because they're delivering items that have no problem being in transit for two days, but I can't see how they could deliver e.g. strawberries for a reasonable price ever. I'd love to be wrong, but I don't see it happening.