Parsec AWS Automation Scripts & Guide
Info | Value |
---|---|
Created by | Keith Vassallo |
Acknowledgements | /u/rom-ok /u/dolanders @Cookie-Monster-Coder @rhigueras @srichter The Parsec Team |
Related Reading | Parsec AWS Guide |
Check out a video version of this guide at: https://www.youtube.com/watch?v=gE20QLY6gAI
Table of Contents
Aims
Setting up the Server
Installing Parsec
Creating the Automation Script
Creating the Start Script
Putting it All Together
Aims
The aims of this guide are as follows:
- Roll your own cloud gaming server.
- Be able to install any game you want, regardless of which store it's available on, and even if it's not in any store.
- Do it as cheaply as possible.
- Automate it such that when you're done gaming, you just need to shutdown the server.
Setting up the Server
We'll begin by following the Parsec AWS guide.
- If you haven't already, create a Parsec Account and download the Parsec Client
- If you haven't already, create an AWS Account.
- Optionally, create a Razer Account.
- Download Microsoft Remote Desktop Client for Windows or for macOS or something like Remmina for Linux.
- Login to the AWS Console using your root account.
- Go to Services > EC2.
- Click on Running Instances.
- Choose a region closest to you (from the top right).
- Click Launch Instance. Select Windows Server 2019 Base.
- From the next screen, choose the g4dn.xlarge instance type.
-
Click Next: Configure Instance Details.
-
Leave all options unchanged, and move on to Next: Add Storage. From here, you will need to choose how big you want your disk to be. I chose 512GB, since it's roomy and I typically don't leave all my games installed at once. Of course, you can choose any size you want here, but bear in mind you are charged per GB. Choose General Purpose SSD (gp2) as the storage type and make sure you turn OFF the Delete on Termination checkbox. This ensures our volume isn't destroyed when we shutdown our machine. We'll be creating a script to handle that part for us.
- Move on to Next: Add Tags. This is Very Important so don't skip it. You'll want to create a tag called Name - with a capital N. For the value, choose a name for your gaming server. Make sure that the checkboxes for both Instances and Volumes are checked.
- Move on to Next: Configure Security Group. Leave the default option to create a new security group, and give it an easy-to-remember name, such as Your_Instance_Name_Here-Sg.
- Now click Review and Launch and click Launch. You'll be asked to create a key pair. Click Create a new key pair and give the key a name.
-
Download the key and keep it somewhere safe. I strongly recommend you create a folder on your system to keep all documents related to your gaming rig. From now on, I'll refer to this as That Folder.
-
Finally, click Launch Instances. Now, you'll get a message that your instance was launched successfully.
-
Our instance has launched! To confirm, click View Instances and then click Instances. You'll see the instance is starting or has already started.
- Now we'll connect to the instance. With your instance selected, click Connect, then switch to the RDP client tab, click Download Remote Desktop File and add it to That Folder. Next, click Get Password. If you get a warning about the password not being available yet, close the window and click Connect again after a few minutes. Browse to the location of your key file (it should be in That Folder). This will display the key contents in the window.
- Click Decrypt Password. You will be shown the username (Administrator) and your password. Save these somewhere safe, I suggest in That Folder at first, but eventually move these to a proper password manager.
Installing Parsec
We'll now install Parsec via their awesome script, which will also install other stuff to make our life easier, as well as update the GPU drivers.
-
Double-click on the RDP file you downloaded earlier, this will open a connection in Microsoft RDP Client, with the username already filled in. Simply paste the password and click Connect. You will connect to the desktop of the instance.
-
Now click Start and type PowerShell, click on Windows PowerShell. Now we need to get the Parsec setup script. Head on over to the Parsec Cloud Preparation Tool GitHub and copy the script given:
- Now, back in your RDP session, paste the script in PowerShell. This will extract a compress file. Press Enter to continue the process.
- You will be asked whether to configure automatic Windows login. Type Y to accept this. You will be asked for your username and password, which you placed earlier in That Folder. 4.1. If this dialog did not work, you can turn on automatic logon in Windows by following instruction from this page
-
The script will now install a bunch of stuff, including DirectX 11, Chrome, Parsec and 7zip. Depending on the script version, AWS, Microsoft and the alignment of the moon, you may sometimes get errors from the script. These will probably show that one or more downloads failed, typically for Direct X and the XBox Game controller driver. If you do get this error, you can download Direct X from here and the XBox contoller driver from here.
5.1 If gamepad still doesn't work you may need to install driver manually by following [this instructions] (ViGEm/ViGEmBus#153).
-
When Parsec is installed, you'll see the Parsec client - go ahead and login. The login won't work at first, but you'll receive an e-mail asking you to confirm your location. Click on Approve your new location once you get the email, then login to Parsec on your gaming server.
-
Eventually you'll see a pop-up for Razer Synapse - asking you to login. You don't need to login - we just need this installed. Go ahead and close it. Note: On Windows Server 2016 you may need to login and/or close the app for the script to continue..
- The Parsec script will now continue with the GPU updater tool. You'll be prompted to provide an Access Key and Secret. To do this, copy the link that is shown in the prompt, and paste it in your browser, or just click here.
- Now click on Access keys (access ID and secret access key) and click Create New Access Key. Click Download Key File and add this to That Folder. Then click Show Access Key - this will show the access key and secret access key. Copy the first one and paste it in the PowerShell window, pressing Enter. Then copy the secret key and also paste it in PowerShell, followed by Enter. You'll be asked whether to save the access key - type y. Answer the next two questions with y.
- If this step fails, you may need to apply fix for GPUUpdaterTool.ps1 as suggested here
-
When the driver is installed, you'll be advised whether or not you need to reboot.
-
If you rebooted, use the steps outlined in step 1 to re-connect to your system via RDP.
-
At this point you should configure Parsec (double-click the Parsec icon on your desktop). I used the following settings:
- Host Settings
- If you're on macOS, change Resolution to match the resolution of your personal system. You can find this out by clicking Apple > About this Mac > Displays. If you don't do this, connecting via Parsec will fail to change the resolution of the server to match your system. Windows/Linux users don't need to do this.
- Increase the Bandwidth Limit to 50 Mbps.
- Give the host an easy to remember name.
- Client Settings - not really required, but Β―_(γ)_/Β―
- Change Resolution to match your setting from above.
- Set H.265 (HEVC) to On.
- At this point, the Parsec client on your system should show the server as available.
-
Optionally, double-click on the Setup Auto Shutdown icon on your desktop. This will shutdown your system after a number of minutes if its idle, just in case you forget to do it yourself. When prompted, I set it to 45 minutes.
-
Optionally, doublick-click on the Setup One Hour Warning icon on your desktop. This will warn you when you have been connected for an hour, so you can better manage your billing.
-
Now, disconnect from your server (i.e. close the RDP window), and connect to the server via Parsec instead. You're now ready to game! If you're not interested in the automation stuff, you can now skip to the Gaming section.
Creating the Automation Script
This section is optional - however it might be something you look into. This basically configures the following:
- When you're done gaming, you just shutdown the server.
- The script is called automatically when the server is terminated. It:
- Takes a snapshot of the volume.
- Creates an AMI of from the snapshot.
- Deletes the volume
- Deletes old snapshots and AMIs.
The reason we do this is because keeping a snapshot is cheaper than keeping a volume. We also have an AMI so we can easily re-launch the instance later and continue where we left off. I've also created a script to do this automatically, which is described in the next section.
-
Shutdown your rig (Start > Shutdown) then from the AWS console, go to Services > Lambda.
-
Click Create Function and give it a name. In my case I called it SnapAndDelete - but any name will do. For the Runtime, choose Python 3.8. Then click Create Function.
- You'll see a code editor where you can create your function. Grab the function code from here, and paste it in the code editor.
- Now, you'll want to change the three variables.
GAMING_INSTANCE_NAME = 'GamingRig' # Replace this with the name of your server
GAMING_INSTANCE_REGION = 'eu-west-3' # Replace this with the region your server is in
GAMING_INSTANCE_SIZE_GB = 512 # Replace this with the size of your disk
- The function will typically only run for a few seconds, however there is an exception. Snapshots in AWS are built incrementally, which is why they're so fast - except the first time we create a snapshot there's nothing to base on, so the entire 512GB volume needs to be snapshotted, which takes a while. It will also take a while to take a snapshot after installing a large game. So, we'll increase our function execution time limit. Scroll down to Basic Settings and click Edit, then set the Timeout to 15 minutes. Click Save when you're done.
- Click Deploy to save the function. Next, we need to give our function permission to manage our EC2 resources. To do this, click on Permissions from the top, and click on the role that AWS automatically created for your function.
- Now click Attach Policies, search for EC2 and choose the AmazonEC2FullAccess policy. Click Attach Policy
- At this point, you should really test that the function works. From the EC2 console, Terminate the instance (Instance State > Terminate). Then, back in Lambda, click Test > Create Test Event and give the event a name. Then click Test to see whether the function works. If it does, you should see output similar to the following (note that this will take a while):
- Next, we need to tell AWS to run this function every time our instance is terminated. Go to Services > Amazon EventBridge, then click Create rule. Fill in the form as follows:
- Name: Any name.
- Description: Any description.
- Define Pattern: Event Pattern.
- Event matching pattern: Pre-defined pattern by service.
- Service provider: AWS.
- Service Name: EC2.
- Event Type: EC2 Instance State-change Notification.
- Specific state(s): Checked, and choose terminated from the list of states.
- Now from Select targets, and from the Function drop-down, choose the Lambda function we created earlier. Note that the function checks instance tags when doing its thing, so it won't mess around with your other instances/volumes/snapshots/AMIs.
- At this point, shutdown your gaming rig, then from the EC2 console choose Actions > Terminate. This will terminate the instance and the Lamda function should kick in, which will create the initial snapshot of the machine. You can monitor it from the Snapshots section of the EC2 console. Note that this initial snapshot will take a while to complete, but following this snapshots shouldn't take that long - it depends on how many changes you've made to the machine whilst using it.
Creating the Start Script
This section is also optional. Here we create a script that will automatically launch a gaming instance using spot pricing for us, without having to login to the AWS Console.
-
Go to Services > EC2 > Launch Templates. Click Create Launch Template.
-
Now, you need configure the template with the following settings:
- Launch template name: Set any name here.
- Template version description: 1
- AMI: Don't include in launch template.
- Instance Type: g4dn.xlarge (or whatever size you chose).
- Key pair (login): Choose the key you created when creating the instance.
- Under Storage (volumes) click Add new volume with the following settings:
- Size (GiB): 512 (or whatever size you're using).
- Device name: /dev/sda1 - you need to choose Specify a custom value... to be able to do this.
- Volume type: General purpose SSD (gp2)
- Delete on termination: No
- Encrypted: No
- Under Resource tags, click Add Tag and create a tag with the Key set to Name and the Value set to the name of your gaming server (GamingRig in my case). Make sure that both Instances and Volumes are selected under Resource Types. Now click Add Tag again, and create a tag with the Key set to SnapAndDelete and the Value set to True - again making sure that both Tag instances and Tag volumes are enabled. Note that tag keys and values are CASE SENSITIVE.
- Expand Advanced details, then:
- Request Spot Instances: Checked.
- Click Customize then click Set your maximum price (per instance/hour) and set your price to some value greater than the instance average. You can see current average prices here - make sure you choose your region. For example, the average in eu-west-3 is $0.37, so I set it to $0.40.
- Shutdown behavior: Terminate.
- Termination protection: Disable.
- Detailed CloudWatch monitoring: Disable.
-
Phew! Finally, we can click Create launch template, followed by View launch template.
-
Now, you need to get the start script for your system. If you're using macOS or Linux, you need start_server.sh. If you're using Windows, you need start_server.ps1. Add this script to That Folder.
-
Open the file you downloaded, and change the following if on Linux/macOS:
GAMING_INSTANCE_NAME = "GamingRig" # Replace this with the name of your server
LAUNCH_TEMPLATE = "lt-123434abcd" # Replace this with the launch template ID
Or the following if on Windows:
$GAMING_INSTANCE_NAME = "GamingRig" # Replace this with the name of your server
$LAUNCH_TEMPLATE = "lt-123434abcd" # Replace this with the launch template ID
To get your launch template ID easily, click on the launch template ID from the AWS Console:
Now click the copy icon next to the launch template ID.
- If you're using Linux or macOS, you need to make the file executable. To do this, open a terminal (on macOS just search for Terminal from Spotlight or Applications > Utilities, on Linux - you should know how to do that already). Then, type:
cd /path/to/ThatFolder
chmod +x start_script.sh
Obviously replace the /path/to/ part with the path to That Folder.
-
For the start script to work, you need to have the AWS CLI installed. If not, you can can install it on Windows from Here, or macOS from Here or Linux from Here.
-
If you've just installed the AWS CLI you then need to configure it. Open a terminal on Linux or macOS, or open Command Prompt or PowerShell on Windows. Then type aws configure. You will be asked questions, answer as follows:
- AWS Access Key ID: The access key you used in step 9 of the Installing Parsec section.
- AWS Secret Access Key: The secret key from the same step. Note that you should have stored these in That Folder.
- Default region name: The region where you set up your gaming server.
- Default output format: json.
Putting it All Together
We're done! We can now take our server out for a spin, which will also let me explain exactly how to use this thing.
- OK, so you're in the mood to kill some demons. The first thing you do is open a terminal on Linux/macOS or PowerShell on Windows. You then run the start script using ./start_script.sh on Linux/macOS, or start_script.ps1 on Windows.
- When the instance is run, you will be shown the instance details. Press q to hide these.
- At this point, open the Parsec client and just wait for your server to boot up. Following this you can connect to your server and game away.
- Once you're done gaming, all you need to do is shutdown the server.
- At this point, you can go ahead with your life. However, since this is the first time, let's use the AWS Console to see what's happening behind the scenes. After shutting down your server, from Services > EC2 > Instances we can see our instance is shutting down. After a short while it will change to the Terminated state.
- If you go to Snapshots, you'll see that our script starts creating a snapshot.
- After the snapshot is ready, going to the Volumes section shows that the volume has been deleted.
- In the Images section, you'll see the brand new AMI, ready for your next gaming session.
Gaming
I installed Steam and Doom Eternal to gave it a shot.