Skip to content

Repository files navigation

Twilio EC2 Manager

This allows managing an EC2 instance via Twilio SMS

Set up

Requirements

Pre-requisites

  1. Get a Minecraft Server running on an EC2 instance
  2. Setup a Lambda function to receive SMS from Twilio

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.

Lambda Environment Variables

Make sure to add the following environment variables to your Lambda function:

KeyDescription
ADMIN_NUMBERSA comma delimited list of administrator phone numbers (e.g. +12125552368,+12125551234)
TWILIO_ACCOUNT_SIDYour primary Twilio account identifier - find this in the Console.
TWILIO_AUTH_TOKENUsed to authenticate - just like the above, you'll find this here.
EC2_INSTANCE_IDThe ID of the EC2 Instance you created above. You can find it here.
EC2_REGIONThe region your EC2 instance is running in (e.g. us-east-1b)
EC2_SECURITY_GROUP_IDThe ID of the security group that is assigned to the EC2 Instance (e.g. sg-1234567ab89cd0987)
TWILIO_NUMBERthe Twilio phone number you setup to receive SMS (e.g. +12125552368, also found in your Twilio Console)
MINECRAFT_HOSTThe server domain or IP that points to your Minecraft Server (e.g. minecraft.example.com)
MINECRAFT_PORTe.g. 25565
REQUEST_URLThe API Gateway endpoint you setup for the Lambda function and added as the SMS incoming webhook (e.g. https://1somehash23.execute-api.us-east-1.amazonaws.com/prod/message)

Lambda permissions

You will have to add the following actions to the permissions for your Lambda function:

ActionDescription
ec2:AuthorizeSecurityGroupIngressAllows adding new IPs to the server whitelist
ec2:DescribeInstanceStatusAllows checking the status of the instance
ec2:DescribeSecurityGroupsAllows looking for existing IPs in the server whitelist
ec2:RevokeSecurityGroupIngressAllows removing a whitelisted IP from the server
ec2:StartInstancesAllows starting the instance
ec2:StopInstancesAllows stopping the instance
logs:CreateLogStreamAllows capturing output to logs
logs:PutLogEventsAllows saving log events

Package the twilio-aws-minecraft Lambda script

This will create a packaged Lambda script with all required libraries in .zip file that you can upload to replace the existing Lambda script you created in the previous step.

git clone https://github.com/codenamev/twilio-aws-minecraft.git \
cd twilio-aws-minecraft \
zip -r twilio_function.zip ./

Once you've saved the newly uploaded Lambda and deployed, you can test out your new EC2 manager by sending a command via SMS to your new Twilio EC2 Manager!

About

Control a minecraft server in AWS via Twilio SMS

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages