doctorray117 / minecraft-ondemand

Templates to deploy a serverless Minecraft Server on demand in AWS
Apache License 2.0
1.71k stars 118 forks source link

Lambda watchdog #22

Closed binarythinktank closed 2 years ago

binarythinktank commented 2 years ago

Hi This is a fun project :)

I have 3 questions

  1. Could the Watchdog not run in a Lambda? triggered every 10 minutes or so by EventBridge schedule that is created by the error handling lambda (and deleted again when the container is terminated)? This should further optimise cost and make it more serverless.

  2. This is not a scaling solution, right? it is 1 container that needs to be big enough for the expected number of users.

  3. if the container is launched after a hit on the domain name, at some point you will get a lot of false positives from bots and such, right? is there a (serverless) way to make sure it's a Minecraft client asking for the link before launching anything?

thanks!

binarythinktank commented 2 years ago

i suppose for 3, api gateway could be used to launch the container, requires an extra step and is not as elegant as recognising a genuine Minecraft request though :/

binarythinktank commented 2 years ago

i had a thought. what if, instead of route53 writing an error log, it fails over to an api-gateway endpoint. API gateway can check for required headers that a Minecraft client would include, if they are missing it just errors the request without invoking anything. if the headers are present it will kick off the lambda launcher. its an extra component, but more cost-effective because no lambda or container launched unnecessarily. might also be slightly less latency than an error log.

doctorray117 commented 2 years ago

The issue with the api gateway is that it won't listen on the minecraft listening port on the front-end, so there'd be no way to trigger it without manually hitting another URL. I'll reply to your other questions soon, still working today :)

binarythinktank commented 2 years ago

ah, right. and port conversion needs non-serverless components in front of it :/

doctorray117 commented 2 years ago

As far as the other questions, the watchdog container does not incur any additional cost as it runs within the same task as the server container. ECS Fargate is priced by the task, and you can have multiple containers running simultaneously as part of it and pay the same cost.

With respect to scaling, this is not going to increase the power levels as users are there, you'd have to preprovision cpu/memory into the task definition and also the minecraft container settings, if you want to take advantage of additional memory. You wouldn't want to run this 24/7 because it would get expensive really fast... the main benefit is that it's basically zero cost when you're not using it.

For the domain, it's unlikely you'd get bot hits unless you're posting a link out there somewhere, as it's not a webpage, and it's a subdomain, not the root domain. While it's not impossible, it would be very unlikely and even then just use a slightly more complex name.

binarythinktank commented 2 years ago

many thanks, those are good points. Going to try and launch it this weekend and play around with it!

doctorray117 commented 2 years ago

Thanks, going to close this issue.

As a aside, a lambda watchdog would be difficult due to needing to obtain information about the running task, as well as scheduling the firing of the lambda overall. And, since running a second container within an ECS task comes at no additional cost, it's simpler to leave the control scripts running alongside the server.