Gaming on Amazon’s EC2

Bob Matcuk
17 min readJan 7, 2016

--

As a casual gamer, and a user of a non-Windows machine, I find myself at a crossroads. Do I spend $400 on a cheap gaming rig? I’d only be able to play games at lower graphics settings, and it’s likely that I’ll need to upgrade the system yearly just to stay on-par with minimum requirements. Or do I spend $2k on a high end gaming rig? It’ll last a lot longer without needing upgrades, and I’d be able to play on higher settings, but I don’t play games enough to justify the cost.

Then an idea occurs: Amazon rents out some powerful instances. Some of them, such as the g2.2xlarge, even have high-end video cards. Is gaming possible on these instances? The short answer: yes. The long answer: depends on your internet connection.

Gaming is absolutely possible on an Amazon EC2 instance and this guide will walk you through setting up an instance of your own. The g2.2xlarge instance, with 8 vCPU, 15 GB of RAM, and a graphics card roughly equivalent to a GeForce GTX 970, is easily able to play most any game on max, or near max, graphics settings. The only limitation is your internet connection’s ability to keep up with the streaming and the additional latency that playing remotely will add. So, it might not be the best choice for something fast-paced (such as a FPS), but you’d be surprised at how well it does work. It even has the added benefit of letting you play Windows games on Mac or Linux!

How Does it Work?

An instance is started on EC2 and streaming is accomplished via Steam’s In-Home Streaming capabilities over a VPN. As the name suggests, this feature is meant to be used locally to stream a game from your computer to, for example, your TV, tablet, or other low power device. For that reason, it’s not optimized to limit its bandwidth usage, so you’ll need a good, solid internet connection. And before you say, “I want to play a non-Steam game,” I should note that you can, in fact, play non-Steam games over Steam’s In-Home Streaming.

How Much Does it Cost?

This is a harder question to answer; it depends on the current prices. In order to keep the cost as low as possible, we’ll use “spot pricing” for the instance. Spot pricing allows you to bid on unused EC2 resources at significantly reduced rates. However, as demand for spot instances fluctuate, so does the price. As of the time of writing, spot prices for a g2.2xlarge instance are around $0.12/hr in my closest region, but that price can fluctuate considerably. By way of comparison, the current “on-demand” price for my region at time of writing is $0.819/hr. On-demand instances are guaranteed instances whose prices don’t fluctuate unless Amazon decides to change them — which happens rarely.

You’ll also need to use some disk space while the instance is running. When you spin up an instance on EC2, you base the instance on an “Amazon Machine Image”, or AMI. In our case, the AMI has a preconfigured Windows install. When the instance spins up, the AMI is copied to a general purpose “Elastic Block Store”, or EBS storage. When you terminate the instance, the EBS storage is deleted. Think of it like the hard drive for your instance. The price for this storage may vary by region, and may change over time, but for my closest region at time of writing, it is $0.12/GB/month. Of course, our instance is only going to be spun up for a few hours here and there, so divide that by 720 (the number of hours in 30 days) and that gives you something like $0.00017/GB/hr. If your instance has 100GB drive, you’re looking at $0.017/hr. Long story short: this storage is cheap and might add a penny or two to your hourly charges.

But that’s not the only storage you’re going to use. Once you’ve got everything setup, you’ll need to create your own AMIs so you won’t need to set it all up again the next time you want to play. This process creates what are called “snapshots” on EBS, and these snapshots will persist indefinitely.

Pricing snapshots is difficult. The current price for my closest region at time of writing is $0.105/GB/month. Again: this may vary. But here’s where things get difficult: if I have a 100GB snapshot, you might think it would cost me 100GB * $0.105/GB/month = $10.50/month. However, that’s not entirely true. First, the snapshot only stores actual data; ie, you don’t pay for empty disk space. Second, the snapshot only stores the “difference” between your base AMI and the AMI you created. So, if I create an instance based on the Amazon-provided Windows Server 2012 R2 AMI with a 100GB drive, Windows will report that nearly 20GB of that drive is already full because of Windows itself. However, if I created an AMI/snapshot of that instance right away, my snapshot would be practically zero: it’s not going to store any of the Windows files, because they didn’t change compared to the base AMI. And it’s not going to store the 80GB+ of empty space. My snapshot will be “100GB”, but my cost would be almost nothing. Long story short: if you follow my guide, you’ll end up with one base AMI, plus an AMI for each game you want to play. You should count on each AMI costing you, maybe, $2–4/month depending on the size of the game.

Finally, there’s data transfer / bandwidth. You’ll mostly end up paying for “out” data, ie, data that is leaving from your VM to the outside world. This would be the audio and video that your game is streaming to you. The cost on my closest region at time of writing is $0.09/GB and may vary. It’s hard to say how much data transfer you’ll be using, but, if I had to guess based on my own usage, it might be as high as 3GB/hr. That’s $0.27/hr. There are some other bandwidth charges you might see on your bill, but it’ll be a penny here, penny there. Maybe a couple pennies a month.

So, tl;dr: $0.12/hr for the instance, maybe $0.02/hr for EBS, plus $0.27/hr for bandwidth = $0.41/hr, plus a monthly cost of maybe $4/month/game for AMIs. If you play games roughly 20hrs/wk, that’s $8.20/wk * 4wks/month = $32.80/month + $4/month for an AMI = $36.80/month. You could play for almost 11 months before EC2 would become more costly than building a low-end, $400 gaming rig, and around 4.5 years before it became more costly than building a $2000 high-end gaming rig.

Of course, it all depends on the price of the spot instance. If spot instances in your region tend to run much higher, your hourly cost will be higher and you might decide it isn’t worth it. Amazon provides a chart of spot pricing history if you’d like to do some research. However, you’ll need to create an AWS account and login to get to the chart.

Setting Up an Instance

Ok, let’s get into the details. Most of setup is installing drivers and support applications (such as the VPN).

First, create an Amazon Web Services (AWS) account if you don’t have one already and login to the Management Console. Your gaming VM will definitely not qualify for the “free tier”, so you’ll need to enter your billing information (click your name in the top right corner and select “Billing & Cost Management, then click “Payment Methods” on the left).

Next, in the top right corner of the Management Console, between your name and “Support”, select the region that is closest to you. You can use a service like CloudPing to determine the best option… the lower the ping, the better your gaming experience will be.

Now we’re going to create a Spot Request. On the left hand side, click “Spot Requests”, and then click the “Request Spot Instances” button. You must base your instance on an existing Amazon Machine Image (AMI). Scroll down until you find “Microsoft Windows Server 2012 R2 Base” and click the “Select” button.

The AMI for your instance.

Next, you’ll select the instance type. From the first “Filter by” dropdown select “GPU Instances”. That will give you two options: g2.2xlarge and g2.8xlarge. g2.2xlarge is ample for playing games. Select the checkbox on the left for g2.2xlarge and then click “Next: Configure Instance Details”.

Selecting your g2.2xlarge instance type.

On the next screen, say you want 1 instance (the default) and click the “Request Spot Instances” checkbox. This will show you the “availability zones” and the current prices. It will also ask you for your maximum price. Typically, I set my maximum price close to the on-demand price. Keep in mind that if the price should rise above your maximum price while you’re playing, your instance will be terminated. However, you only pay the current price. So if I set my maximum for $0.80/hr, but the current price is $0.12/hr, I only pay $0.12/hr. You’ll also want to select the “Subnet” that matches the cheapest availability zone (us-west-1c in my screenshot below)! If none of the availability zones are cheaper than the on-demand price, uncheck the “Request Spot Instances” checkbox. You’ll be charged the on-demand price. Then click “Next: Add Storage”.

Configuring the instance.

By default, there will be a Root volume of 30GB and an Instance Store volume. Delete the Instance Store by clicking the X on the far right. If you plan on creating a “generic” AMI that can be used to build multiple gaming VMs (which I recommend), leave the root size at 30GB. Otherwise, increase the root volume size so that it is large enough for the game(s) you wish to install plus Windows. Click “Next: Tag Spot Request”.

Remove the instance store.

On this screen, you can create “tags” for this spot request. These tags are entirely for your own information and don’t matter… the “name” tag, specifically, will appear in the AWS Management Console as the name of your spot request, so type whatever you want in the “value” and click “Next: Configure Security Group”.

This doesn’t really matter.

For the security group, we’re going to open up everything to make our lives easier. You may want to revisit this later, but, for now… select the dropdown under “Type” and select “All traffic”. Enter a “security group name”. You can reuse this security group next time you want to launch a gaming VM by selecting the “select an existing security group” radio button, and then selecting your security group that you created in this step, so make the name meaningful. Then click “Review and Launch”.

Double check everything on this screen and then click “Launch”. It will then ask you for a key pair. This is used to encrypt/decrypt the default password for the Administrator account. If you’ve never used this before, select “Create a new key pair” from the dropdown and give it a name. Then click “Download Key Pair” and “Request Spot Instance”. Keep this file!! You’ll need it to get the password to your instance! If you have used this before, select “Choose an existing key pair”, select your key pair from the dropdown, and click “Request Spot Instance”.

Creating your key pair.

Now you need to wait. It can take five to fifteen minutes or more to create your spot instance. Once the “status” changes to fulfilled, click “Instances” on the left. Find your instance in the list, right click on it, and select “Get Windows Password”. You may get a message that you need to wait for Windows to finish booting… try again in a minute, if you do. You’ll need to upload the key pair that you downloaded in the previous step to get your machine’s information. Click “Decrypt Password”.

Upload your key pair.
Your machine’s info.

Install Drivers

Now you’ll need to connect to your machine via Remote Desktop. For Windows users, this is a pre-installed application. Mac users can find it in the app store. Linux users will need to find a program that can do RDP. In Remote Desktop, enter the address, username, and password. Also make sure to check the “Connect to admin session” option! You may find that option on another tab (the Mac app, for example, has it on the “Session” tab). Then connect. You may see a black screen for some time, just be patient.

Once you’re logged into your instance, the first thing you’ll want to do is set your password. Click “Start”, “Administrative Tools”, “Computer Management”, expand “Local Users and Groups”, click “Users”, right click “Administrator”, “Set Password”, “Proceed”, type and retype your new password and click “Ok”.

The next thing you’ll want to do is disable “IE Enhanced Security”. Open “Server Manager”, click “Local Server” on the left, and then click “On” next to “IE Enhanced Security” and disable it for Administrators (and, optionally, regular users).

Disable IE Enhanced Security

Because I can’t stand IE and Microsoft’s idea of “security through annoyance”, the next thing I’d do is download Chrome. Once Chrome is installed, fire it up and download and install the NVidia Grid K520 drivers. Do not reboot at this time! We’re going to install some other stuff first so we only need to reboot once.

Once the NVidia drivers are installed, we’ll need to disable the “Basic Display” drivers, otherwise the system will keep trying to use them. Click Start, Control Panel, and type “Device Manager” in the search box in the upper right, then click on “Device Manager”. Under Display Adapters, you’ll find “Microsoft Basic Display Adapter”. Right click and “Disable”, then right click again and “Uninstall”. That won’t actually uninstall it though! We’ll need to run some stuff on the command line to make sure it never comes back. Click Start, “Windows Powershell”, and run the following commands. The first two will set permissions on the file so that you can delete it with the last command. The second command will ask “are you sure?” Answer with a “Y”.

takeown /f C:\Windows\System32\Drivers\BasicDisplay.syscacls C:\Windows\System32\Drivers\BasicDisplay.sys /G Administrator:Fdel C:\Windows\System32\Drivers\BasicDisplay.sysexit

Next, download and install the Razer Surround drivers. You’ll need these to get sound in your games. After all, servers don’t normally need to make sound, so sound is disabled by default. After the drivers install, a box will pop up asking you to login… just exit out of that. It’s not necessary to get sound working.

Just exit out of this… it’s not necessary.

You’ll also need to enable sound. Click “Start”, “Administrative Tools”, and double click “Services”. Find “Windows Audio” in the list, double click and select “Automatic” from the “Startup Type” dropdown. Then click Apply and Ok. Do the same thing for “Windows Audio Endpoint Builder”.

Install Some Additional Software

Now we’ll need to install a VPN. I like ZeroTier because it makes it easy to get up and running. Once you’ve installed the ZeroTier client in your VM, run it and make note of the 10 character code that appears in the bottom left corner. Create an account on ZeroTier Central. Once you are logged in, click “Networks” at the top right, enter a name (such as “Gaming VM”) in the box and click “New Network”. Next, under IPv4, select “ZeroTier Managed” and click on one of the IP addresses under “Easy”… doesn’t really matter which; I selected the first option: “10.147.17.*”. At the bottom of the screen is “Members”. Type that 10 character code from the ZeroTier client and click “Add Device”. That will add a row to the Members table. Under “Name/Description”, type something like “Gaming VM”. Install the client on your local machine and add that 10 character code as a member as well. Name it as you see fit. Then click “Save” at the bottom of the screen. We’ll come back to this later.

The final piece of software we need is Steam, both in the VM and locally. Create an account if you don’t already have one. You’ll need to login to the same account both on the VM and your local machine. Once Steam is installed on your VM, click “Steam” in the upper left and select “Settings”. Select “In-Home Streaming” and make sure “Enable streaming” is checked. Then click “Advanced Host Options” and ensure “Enable hardware encoding” is enabled.

Enable hardware encoding

Likewise, on your local machine, go into the settings and make sure “Enable hardware decoding” is enabled under “Advanced Client Options”.

Hardware decoding.

One final thing we’ll need is a way to log out of the RDP session without locking the screen. Right click on the desktop and select “New”, “Shortcut” and type the following in the box:

C:\Windows\System32\tscon.exe %sessionname% /dest:console

Give the shortcut a name like “Close Without Locking”.

Now we can reboot. Start, Power Options (power icon in the top right), Reboot. After a minute or so, you can login to make sure everything looks good. In particular, check that the NVidia card appears in device manager, but the Basic Display does not (it’ll say something like “VGA Compatible Device” with a yellow exclamation warning next to it). Also make sure sound is enabled (the speaker icon will appear in the system tray).

Create a Generic AMI

At this point, if you’re going to create a “generic” AMI that you could use later to create more gaming VMs, this would be the time to do that. Otherwise, skip down to “Installing a Game”. In the AWS Management Console, click on “Instances” on the left, right click your instance, and select “Image”, “Create Image”. Give it a name such as “Base Gaming VM” and click “Create Image”.

Creating an AMI.

This process can take some time and, while it’s running, you can actually kill the instance so you aren’t paying for it. Right click on the instance and select “Instance State”, “Terminate”. You can track the progress of your AMI by clicking “AMIs” along the left side. AMIs also create a snapshot, so you can view the progress of that by clicking “Snapshots” along the left.

Once the AMI is done (it will show “available” under status), we’re going to start up a new VM. Go to “Spot Requests” again and create a new request. This time we’re going to select our AMI by clicking “My AMIs” on the left and selecting the AMI you just created.

Base Gaming VM

Set it up as before: g2.2xlarge instance, cheapest availability zone. When you get to storage, increase the size of the root device by the size of the game you want to install. For example, I’m going to install SWToR which requires a good 40GB, so I’m going to increase my root device from 30GB to 70GB (editors note: I actually ended up needed to go to 80GB).

Space for SWToR

Continue through the spot request wizard… tag it with some name, use the security group you created last time (“select an existing security group”), launch, and use the key pair you created before.

Once the VM is running, connect to it with Remote Desktop. The address of the VM will be different. You can get the address by clicking on the instance in the AWS Management Console and then copying the “Public DNS” that appears at the top of the instance information at the bottom of the screen. Remember that you set your password, so make sure to change that in your connection options, too. And make sure the “admin session” is still checked. If it doesn’t connect, that’s probably because Windows is still booting. Wait a minute or two and try again.

Once connected, you’ll need to expand the partition to include the new space. Click Start, “Control Panel”, and type “Disk Management” in the search box in the top right. Click on “Create and format hard disk partitions” in the search results. In this window, right click on the “C:” drive and select “Extend Volume”. Make sure “Select the amount of space in MB” is equal to the “Maximum available space in MB” and click Next. It will only take a second to extend the partition.

Extending the partition.

Installing a Game

Next, we’ll need to install a game. I’ll leave the details of that up to you. Once the game is installed, you’ll need to add it to Steam as a Non-Steam Game so that it can be streamed. In Steam, click “Add a Game” in the bottom left, and “Add a Non-Steam Game”. Select the game you installed and click “Add Selected Programs”.

Once that’s all setup and the game is fully installed/downloaded, you should create a new AMI. In the AWS Management Console, right click on the instance and select “Image”, “Create Image”. Give it an “Image Name”, maybe based on the game you installed, for example.

Playing Your Game

From this point on, when you want to play the game, you’ll need to create a new spot instance using this AMI as your image. Of course, you already have a running instance right now, so you can skip this next paragraph… but, for future reference, this is how you’d start up a new instance:

To start a VM with this AMI, start a new spot request as before, but click on “My AMIs” on the left and select this AMI as your base image. Set all the other options as we did before and launch the request. Once the request has been fulfilled, connect to the instance with Remote Desktop and follow along:

First thing we’ll need to do is connect to the VPN. Go to ZeroTier Central, login, and click “Networks” on the top right. The network you created earlier will have a 16 character ID. Copy/paste this ID into the ZeroTier client on both the VM and locally and click “Join”. After a second, the status will say “Ok” on both ends and you’re now connected.

Now we can quit the Remote Desktop session. Double click the “close without locking” shortcut you created on your desktop. This will kill your Remote Desktop session with an error, leaving the desktop unlocked remotely. This is important! If the screen is locked, games won’t start!

Open Steam locally and you should find the game listed in your “Library”. Click the “Stream” button and you should be all set! When you’re done playing, remember to terminate your instance so you’ll no longer be charged for it. Shutting down Windows should terminate the instance, but, if you want to be sure, right click on it in the AWS Management Console and select “Instance State”, “Terminate”.

Some More Notes

If you’re playing an online game, the game will likely patch itself every now and again. When this happens, you’ll probably want to create a new AMI after the patching is done. Otherwise, every time you start an instance, you’ll need to wait for it to patch again. Give the new AMI a name based on today’s date (such as “Game Name 01/07/2016”) so it’s easy to differentiate. After you create the new AMI, you can delete the old AMI and the associated “snapshot”. To find the associated snapshot, click on the AMI in the AWS Management Console. In the bottom panel, scroll to the bottom and look at the “Block Devices”. It will say something like “/dev/sda1=snap-12345678:30:true:gp2”. The “snap-12345678” part is the snapshot ID. Delete the AMI by right clicking and selecting “Deregister”, then go to “Snapshots”, right click the snapshot with that ID and select “Delete”.

Troubleshooting

Sometimes a game might throw an error and crash. You might not be able to see that error via streaming. You might be able to start the game in a Remote Desktop session… the game will play horribly, but if you can reproduce the issue that way, you might get a better idea what the error is.

Also, check that you haven’t run out of disk space… that can cause weird errors. If you have, just create a new instance with a larger root volume, and then resize the volume as per the instructions above at the end of the “Create a Generic AMI” section.

Good luck!

--

--