I’m not sure that’s entirely true.
Most of their money comes from retail, either the site, subscriptions, or the seller services they provide. AWS, while massive, isn’t what’s keeping them afloat.
You’re entirely correct though that competition with Amazon is difficult because of those additional sources of revenue. Having additional stable sources of income gives them the ability to accept lower margins in retail with less risk.
The way they make money selling things with no profit or at a loss is to ensure that someone else is always paying the difference. “Free shipping” with a paid subscription means that rather than providing shipping for a loss, they just need to do it for less than the subscription. Turns out “guy with a van” can deliver a lot of packages for quite cheap. So many that he’ll be out delivering from 3am to 9pm, and for $5 they’ll drop your package off first and call it overnight.
In some cases they can get the seller to pay for shipping as a promotional incentive, since Amazons conditioned people to look for free shipping as a precondition to considering a product.
Only give away for free what you got someone else to pay for.
What do you think profit is? It seems like you’re conflicting profit with income.