Probably would run just fine on a <= 4 euro/month virtual machine too.
Of course it doesn't quite scale to zero like APIGW,lambda,etc. but on the other hand you can be fairly confident to not pay more if your pet project suddenly lands on the front page of HN.
Keep in mind that the "<= 4 euro/month virtual machine" has maybe 256MB of RAM available and running anything beyond nginx + a web server which needs to be cycled every few days due to memory fragmentation can become challenging. I've tried this many times, but it's just not worth the extra hassle. And I want a vpn, monitoring and database even on the toy project server as a minimum in reality.
Maybe 5+ years ago. These days ~4€/month gets you 2GB of RAM, SSD storage and plenty of bandwidth.
Hetzner has such a VPS offering (2GB RAM/20GB nvme SSD/20TB bandwidth), netcup has one for ~3€, contabo has 8GB/50GB nvme/32TB for 6€/month and there are plenty of smaller companies around the world offering similar deals (usually somewhat less included bandwidth outside europe though).
A stardust instance on scaleway comes to less than 2 EUR per month and it has 1G of RAM and runs a toy project or even a small personal infra just fine :)
EDIT: Personally I pay 9-10 EUR per month to Scaleway for a 2G RAM and 2 CPU VPS, private docker repo and S3-compatible storage which holds data and some backups, which run both my personal services and some toy projects when needed. I am not affiliated with them in any way
Contabo has €5 VPS with 4 cores, 8 GB RAM and 200GB SSD. The one I have runs multiple Valhaim servers that are constanly hammering the CPU, some .NET webs etc. and it's fine.
Their monthly cost is something between 0 and a few cents.
Stuff like Hertzner is fine, but if you know your way around AWS you realize have massive cost savings. Prob the same for Azure.
Finally, in many places 40 EUR for a pet project is actually a lot of money.