This is an AWS CDK stack for deploying a Factorio game server. It is by no means complete, but is currently in an acceptable state.
This stack has been deployed and worked beutifully multiple times, sometimes adapted for different games, serving up to 6 people for hundreds of hours without issue.
I am not against the reasonable and responsible use of AI as a tool for software development, but I am against the lazy, naive, and irresponsible copy-paste of whatever an AI or AI based tool spits out without engineer supervision and validation.
If I continue to work on this project, I will likely use AI at some point as a tool. At which point I will update the first sentence of this disclosure to reflect its use.
This SetUp is likely incomplete. I don't play videogames anymore, so this hasn't been used in production for a while.
- In the web console, create an EC2 keypair called
factorio-server(or call it whatever you want, and change the keypair name inlib/factorio_cdk_stack-stack.ts) - Change the allowed IP for SSH connections from
REDACTEDto your IP. Or open it to any IP, but that caries more risk. - Deploy as normal using cdk deploy
- SSH into the running server using the keypair, and from there install SteamCMD and the factorio server, or whatever else you want to run.
- In the web console, fetch the HTTP endpoints for start, stop, and getStatus from API Gateway or Lambda.
- If you ever want to delete everthing and start from scratch, keep in mind you'll need to manually disable deletion protection and delete or rename the EBS volume for the EC2 instance.
- Streamline setting home IP for SSH/RDP access. Currently IP is hardcoded (redacted in this repo) and in the future should be set dynamically via environment variable, or alternative methods of access should be explored, such as EC2 Instance Connect Endpoint.
- Support multiple game servers, such that the status endpoint gets the status of all configured servers, and the start/stop endpoints take a path or parameter specifying the server to start/stop.
- Automate individual server setup. This is tricky because every game server handles things very differently and requires different setup, and sometimes different OSs (not to mention game updates often break configs and scripts). It would be nice to fetch at least some config from somewhere for each type of server, in a consistent and predictable way.
The cdk.json file tells the CDK Toolkit how to execute your app.
npm run buildcompile typescript to jsnpm run watchwatch for changes and compilenpm run testperform the jest unit testsnpx cdk deploydeploy this stack to your default AWS account/regionnpx cdk diffcompare deployed stack with current statenpx cdk synthemits the synthesized CloudFormation template