A way to control access to a Minecraft server hosted on an EC2 instance via SMS.
This all came about when my kids wanted to play Minecraft with their friends. While Realms seemed like a decent choice, I wanted something with more control and a way to allow other parents to easily add their kid(s) and start/stop the server.
An administrator sends an SMS to a Twilio number with a command (e.g.
status). Twilio then sends an incoming SMS web request to an Amazon API Gateway endpoint. This endpoint hands off the Twilio event and request data to an AWS Lambda function which validates and processes the command to perform one of the following:
startup – Starts the EC2 instance.
shutdown – Stops the EC2 instance.
whitelist add 184.108.40.206 as beetlejuice – Allows a new user to connect to the Minecraft Server.
whitelist remove 220.127.116.11 – Dis-allows an existing user from connecting to the Minecraft Server.
status – Check the status to see if the instance is running.
- setting up a Minecraft Server on an EC2 instance. I hope to update this at some point with a slimmer set of instructions that I now use, but this got me where I needed.
- Set up a Lambda to receive Twilio events
With the above in place, you should have a working Minecraft Server running in EC2, and a simple Lambda setup with the API Gateway to receive events from Twilio.
Make sure to add the following environment variables to your Lambda function:
|ADMIN_NUMBERS||A comma delimited list of administrator phone numbers (e.g.
|TWILIO_ACCOUNT_SID||Your primary Twilio account identifier - find this in the Console.|
|TWILIO_AUTH_TOKEN||Used to authenticate - just like the above, you'll find this here.|
|EC2_INSTANCE_ID||The ID of the EC2 Instance you created above. You can find it here.|
|EC2_REGION||The region your EC2 instance is running in (e.g.
|EC2_SECURITY_GROUP_ID||The ID of the security group that is assigned to the EC2 Instance (e.g.
|TWILIO_NUMBER||the Twilio phone number you setup to receive SMS (e.g.
|MINECRAFT_HOST||The server domain or IP that points to your Minecraft Server (e.g.
|REQUEST_URL||The API Gateway endpoint you setup for the Lambda function and added as the SMS incoming webhook (e.g.
You will have to add the following actions to the permissions for your Lambda function:
||Allows adding new IPs to the server whitelist|
||Allows checking the status of the instance|
||Allows looking for existing IPs in the server whitelist|
||Allows removing a whitelisted IP from the server|
||Allows starting the instance|
||Allows stopping the instance|
||Allows capturing output to logs|
||Allows saving log events|
Next, you'll want to checkout my twilio-aws-minecraft repo:
git clone https://github.com/codenamev/twilio-aws-minecraft.git \ cd twilio-aws-minecraft \ zip -r twilio_function.zip ./
That will create a packaged lambda script with all required libraries in .zip form that you can upload to replace the existing Lambda script you created in the previous step.
Once you've saved the newly uploaded Lambda and deployed, you can test out your new EC2 manager via SMS!
Somessues I faced:
- Lambda IPs for EC2 whitelist
- Minecraft Forge and minecraft.service setup issues
- Instance startup not starting minecraft.service
- Configuring OPs