A server is always going to be cheaper to buy
If and only if you are loading it above a certain break even point.
Cloud is cheap when you have a trickle of requests. It is also cheap when scaling your system initially before you understand the user demands and scaling requirements.
Once you know your load and if it is high enough to justify a dedicated server you are likely to find a dedicated server more cost effective. The same goes for various use cases requiring Nx servers.