They could do it because they had the resources thanks to their core business and, more importantly, they could retain the engineering talent in a world where rockstars couldn't just quit and raise VC megabucks to pursue "Uber for Cats" or some adtech play.
So it has turned out that AMZN is an anomaly, judged by its P/E ratio as you point out, in that investors will let it bleed for a long time and still value it highly.
There are a few companies like that, that can afford to fail and that the market will have patience on a fairly long time horizon. In those places you can get a little taste of what it was like to work at a government-funded blue-sky research lab with no pressure to productize in a commercial timeframe.