Skip to content

Instantly share code, notes, and snippets.

@igilham
Created March 18, 2017 09:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igilham/d6637e73b8d74da3aa4aae61ed1dc843 to your computer and use it in GitHub Desktop.
Save igilham/d6637e73b8d74da3aa4aae61ed1dc843 to your computer and use it in GitHub Desktop.
CloudFormation Template to build a gaming rig. From https://serverlesscode.com/post/gaming-on-a-budget-cloudformation/
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation deploys a Windows machine used for Steam",
"Parameters": {
"AWSAMI": {
"Description": "Choose the AMI ID for your Steam machine. This should be a Windows Server 2012 R2 instance and the ID will look like ami-XXXXXXXX",
"Type": "AWS::EC2::Image::Id"
},
"AWSSubnet": {
"Description": "Choose a subnet for the Steam instance.",
"Type": "AWS::EC2::Subnet::Id"
},
"EC2KeyPair": {
"Description": "Choose a Key Pair for this instance. If you do not have one, go make one in the EC2 section and it will appear here.",
"Type": "AWS::EC2::KeyPair::KeyName"
},
"NewUsername": {
"Description": "Type in your new username.",
"Type": "String"
},
"NewUsernamePassword": {
"Description": "Type in the password for your new username.",
"Type": "String",
"NoEcho": "true"
},
"PublicIPAddress": {
"Description": "What is your public IP address? Go to www.whatismyip.com to find out, then type the numbers in here and type /32 at the end.",
"Type": "String",
"Default": "0.0.0.0/32",
"AllowedPattern": "(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})/(\\d{1,2})"
},
"VpcId": {
"Type": "AWS::EC2::VPC::Id",
"Description": "VpcId of your Virtual Private Cloud. You probably just have one default VPC. Choose it here.",
"ConstraintDescription": "Must be the VPC Id of an existing Virtual Private Cloud."
}
},
"Resources": {
"SecurityGroupSteam": {
"Type": "AWS::EC2::SecurityGroup",
"Properties": {
"GroupDescription": "Security Group that allows access to VPN connections and Remote Desktop from your location.",
"VpcId": {
"Ref": "VpcId"
},
"SecurityGroupIngress": [
{
"IpProtocol": "udp",
"FromPort": "1194",
"ToPort": "1194",
"CidrIp": "0.0.0.0/0"
},
{
"IpProtocol": "tcp",
"FromPort": "3389",
"ToPort": "3389",
"CidrIp": {
"Ref": "PublicIPAddress"
}
}
]
}
},
"SteamMachine": {
"Type": "AWS::EC2::Instance",
"DependsOn": "SecurityGroupSteam",
"Metadata": {
"AWS::CloudFormation::Init": {
"config": {
"files": {
"c:\\cfn\\cfn-hup.conf": {
"content": {
"Fn::Join": [
"",
[
"[main]\n",
"stack=",
{
"Ref": "AWS::StackName"
},
"\n",
"region=",
{
"Ref": "AWS::Region"
},
"\n"
]
]
}
},
"C:\\Users\\Public\\Desktop\\DisplayAdapter.bat": {
"content": {
"Fn::Join": [
"",
[
"takeown /f C:\\Windows\\System32\\Drivers\\BasicDisplay.sys",
"echo Y | cacls C:\\Windows\\System32\\Drivers\\BasicDisplay.sys /G Administrators:F",
"del C:\\Windows\\System32\\Drivers\\BasicDisplay.sys"
]
]
}
},
"C:\\Users\\Public\\Desktop\\Startup.bat": {
"content": "md Z:\\SteamLibrary"
},
"C:\\Users\\Public\\Desktop\\OpenVPN.bat": {
"content": {
"Fn::Join": [
"",
[
"cd C:\\Program Files\\OpenVPN\\easy-rsa\n",
"init-config\n",
"vars\n",
"clean-all\n",
"build-ca\n",
"build-key-server server\n",
"build-key client\n",
"build-dh\n",
"robocopy keys ../config ca.crt dh1024.pem server.crt server.key"
]
]
}
},
"C:\\Users\\Public\\Desktop\\FileExtensions.bat": {
"content": "reg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced /v HideFileExt /t REG_DWORD /d 0 /f"
},
"C:\\Program Files\\OpenVPN\\server.ovpn": {
"content": {
"Fn::Join": [
"",
[
"local 0.0.0.0\n",
"port 1194\n",
"proto udp\n",
"dev tap\n",
"ca \"C:\\Program Files\\OpenVPN\\config\\ca.crt\"\n",
"cert \"C:\\Program Files\\OpenVPN\\config\\server.crt\"\n",
"key \"C:\\Program Files\\OpenVPN\\config\\server.key\"\n",
"dh \"C:\\Program Files\\OpenVPN\\config\\dh1024.pem\"\n",
"server 10.8.0.0 255.255.255.0\n",
"ifconfig-pool-persist ipp.txt\n",
"client-to-client\n",
"keepalive 10 120\n",
"comp-lzo\n",
"persist-key\n",
"persist-tun\n",
"status openvpn-status.log\n",
"verb 3"
]
]
}
},
"C:\\OpenVPN.exe": {
"source": "https://swupdate.openvpn.org/community/releases/openvpn-install-2.3.10-I602-x86_64.exe"
},
"C:\\Steam.exe": {
"source": "https://steamcdn-a.akamaihd.net/client/installer/SteamSetup.exe"
},
"C:\\RazerZone.exe": {
"source": "http://dl.razerzone.com/drivers/Surround/win/RazerSurroundInstaller_v2.0.29.2.exe"
}
},
"commands": {
"1-Install Steam": {
"command": "C:\\SteamSetup.exe /S"
},
"2-Disable IE Enhanced Security": {
"command": "REG ADD \"HKLM\\SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}\" /v IsInstalled /t REG_DWORD /d 00000000 /f"
},
"3-Disable Windows Firewall": {
"command": "netsh advfirewall set allprofiles state off"
},
"4-Set Windows Audio to Automatic startup": {
"command": "sc config AudioSrv start= auto"
},
"5-Add New User": {
"command": {
"Fn::Join": [
"",
[
"net user ",
{
"Ref": "NewUsername"
},
" ",
{
"Ref": "NewUsername"
},
" /add"
]
]
}
},
"6-Add New User to Administrators": {
"command": {
"Fn::Join": [
"",
[
"net localgroup Administrators ",
{
"Ref": "NewUsername"
},
" /add"
]
]
}
},
"7-Enable Auto Logon Username": {
"command": {
"Fn::Join": [
"",
[
"reg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\" /f /v DefaultUserName /t REG_SZ /d ",
{
"Ref": "NewUsername"
}
]
]
}
},
"8-Enable Auto Logon Password": {
"command": {
"Fn::Join": [
"",
[
"reg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\" /f /v DefaultPassword /t REG_SZ /d ",
{
"Ref": "NewUsernamePassword"
}
]
]
}
},
"9-Enable Auto Logon Final": {
"command": {
"Fn::Join": [
"",
[
"reg add \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\" /f /v AutoAdminLogon /t REG_SZ /d 1"
]
]
}
}
},
"services": {
"windows": {
"cfn-hup": {
"enabled": "true",
"ensureRunning": "true",
"files": [
"c:\\cfn\\cfn-hup.conf",
"c:\\cfn\\hooks.d\\cfn-auto-reloader.conf"
]
}
}
}
}
}
},
"Properties": {
"InstanceInitiatedShutdownBehavior": "stop",
"ImageId": {
"Ref": "AWSAMI"
},
"InstanceType": "t2.large",
"KeyName": {
"Ref": "EC2KeyPair"
},
"Monitoring": "false",
"NetworkInterfaces": [
{
"DeleteOnTermination": "true",
"Description": "Primary network interface",
"DeviceIndex": "0",
"SubnetId": {
"Ref": "AWSSubnet"
},
"GroupSet": [
{
"Ref": "SecurityGroupSteam"
}
]
}
],
"UserData": {
"Fn::Base64": {
"Fn::Join": [
"",
[
"<script>\n",
"\"C:\\Program Files\\Amazon\\cfn-bootstrap\\cfn-init.exe\" -v -s ",
{
"Ref": "AWS::StackId"
},
" -r SteamMachine --region ",
{
"Ref": "AWS::Region"
},
"\n",
"\n",
"\"C:\\Program Files\\Amazon\\cfn-bootstrap\\cfn-signal.exe\" -e %ERRORLEVEL% ",
{
"Fn::Base64": {
"Ref": "SteamMachineWaitHandle"
}
},
"\n",
"</script>"
]
]
}
}
}
},
"SteamMachineWaitHandle": {
"Type": "AWS::CloudFormation::WaitConditionHandle"
},
"SteamMachineWaitCondition": {
"Type": "AWS::CloudFormation::WaitCondition",
"DependsOn": "SteamMachine",
"Properties": {
"Handle": {
"Ref": "SteamMachineWaitHandle"
},
"Timeout": "600"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment