Skip to content

First time configuration

Danny Thomas edited this page Nov 6, 2016 · 10 revisions

The goal is to take the base ec2gaming AMI and create a reusable image. This configuration differs from the original blog post, in that the goal is to keep the AMI immutable from session to session (call it an institituional bias ;)

These steps assume that you already have:

  • Homebrew and Homebrew Cask (but feel free to install the required software any way you like)
  • An Amazon AWS account, and have generated credentials from the AWS Console

From a terminal:

  • Clone this repository to a convenient location and put it on the PATH

    • Even if you're not familiar with git, it's useful to be able to pull to update
    • I use ~/.ec2gaming via my dotfiles
  • Install required components using Homebrew:

    brew install awscli coreutils jq
    brew cask install steam tunnelblick
    
  • Install Microsoft Remote Desktop from the App Store

  • Run aws configure to configure your AWS credentials and region

  • Create a ec2gaming.auth file in the ec2gaming location (it's .gitignored) with two lines, the administrator username and the password you plan to use to login to the instance. It's used for later configuration and needs to be available before you proceed to the next step:

    administrator
    <new password>
    
  • Run ec2gaming start to bootstrap an instance

Windows configuration

Once the instance is running, a RDP session will be opened automatically:

  • Login using the administrator account with the password rRmbgYum8g and change the password
  • Run Windows Update

Note that EBS is super-slow at startup as blocks come off the snapshot, so expect the instance to be sluggish as it warms up. It only affects file operations on C:\ and won't affect gaming performance later.

OpenVPN configuration

Edit C:\Program Files\OpenVPN\config\server.ovpn and add cipher none to the end of the file. We're using the VPN for the tunnel, not security, and we don't want the overhead of encryption.

Steam configuration

  • Steam will run and update automatically
  • Login and save your password
  • Go to Settings -> In-Home Streaming -> Advanced Host Options and enable 'Hardware Encoding' and 'Prioritize network traffic'
  • Install and run several of the games you intend to play to Z:\. This performs first-time installation, avoiding the redistributable installation overhead. Delete local files once you're done
  • Exit Steam from the system tray, otherwise Steam will forget your password when the instance next starts

Ephemeral storage

The Z:\ is SSD instance storage, that's destroyed when the instance is stopped, but is the ideal place for installing games and data for your gaming session thanks to it's high performance.

The Steam remote install feature assumes the default Stream library, even if a second library is available and set to default. So, to install games to the emphemeral storage on Z:\ remotely, we create a junction on instance startup. Unfortunately, you can't install games larger than the freespace on C: with this approach, but in that case you can use RDP/VNC to install the game.

Steam Cloud will also do a decent job of saving, but it's good to have coverage for games that don't cloud save, or if your instance terminates and Steam doesn't have a chance to perform the cloud sync. So, we also want to configure a periodic sync to S3 to save Documents from Z:\Documents.

  • Install the 64-bit AWS CLI from https://aws.amazon.com/cli/
  • Copy ec2gaming.bat to C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup. This file creates the junction, performs an initial one-way S3 sync, and schedules a task that runs every minute to keep the directory in sync
  • Right-click the Documents folder from the file explorer, and set the location to Z:\Documents

Windows automatic login

Use Autologin to set the instance to automatically login, so Steam starts automatically and it's not necessary to RDP into the instance to start gaming:

https://technet.microsoft.com/en-us/sysinternals/autologon.aspx

Install TightVNC

There are several advantages to using VNC over RDP:

  • You don't need to use the logout shortcut to preserve the console session, you just close the VNC viewer
  • It turns out to be really difficult persist the password for an RDP session to allow automatic login using an rdp file
  • The NVIDIA control panel won't work via a RDP session, and it can be useful to have it available
  • Some games (such as Civilization 6) can't change the resolution above 1024x768 by default, and you need to set the Windows resolution via VNC instead (detailed in the next step)

TightVNC appears best choice, both UltraVNC and Open RealVNC were super flaky, so:

  • Install TightVNC from http://www.tightvnc.com/download.php
  • Configure the password to match your administrator password. Note that it seems like setting the password during initial setup doesn't always work ("Server is not configured properly"), so you might need to go to the TightVNC tray icon, unset and reset the passwords to get a connection

Configure Display Driver

The GRID K520 is a Virtual GPU which has support for a wide range of resolutions, but is notably missing a configuration for effective resolutions on retina displays (such as 1440x900 on a 15" MacBook Pro) which are usually the best resolutions for gaming on a Retina display to get the right UI scale, etc. The driver also identifies a large number of refresh rates supported, which makes selecting resolutions in games tedious, and it's not possible to use the NVIDIA Control Panel to add custom resolutions, I'm assuming because of the virtual nature of the display.

Thanks to this great page, I created NV_Modes settings for the most common 16:9 and 16:10 resolutions:

Driver 373.06 is the latest driver version that has the K520 included in the device list, later versions are missing DEV_118A completely:

{*}S 1024x640x16,32 1280x720x16,32 1280x800x16,32 1440x900x16,32 1680x1050x16,32 1920x1080x16,32 1920x1200x16,32 2880x1800x16,32=1;
  • Restart Windows and attach the VPN (ec2gaming vpnup) and then a VNC session (ec2gaming vnc)
  • Right-click the desktop, select Screen resolution and select the highest available resolution

Image cleanup

Before creating an AMI, Amazon recommends deleting temporary files, defragmenting your hard drive, and zeroing out free space to reduce start times. Reducing the size of your snapshot could also keep you in the free tier if you're in your first AWS year, and keeping free space high means you won't run into the remote install free space limitation mentioned above.

This step is pretty time consuming and you can come back and do this at any time, so it's a good idea to wait until you're confident your image is in a good baseline state before you do this step.

Due to the amount of change, there's a good chance that the snapshot command will time out while waiting for the AMI:

Waiting for AMI to be created...

Waiter ImageAvailable failed: Max attempts exceeded
AMI never finished being created!

That won't stop the AMI from being created, simply watch the snapshot progress and AMI process from the AWS Console (EC2 > ELASTIC BLOCK STORE > Snapshots and EC2 > IMAGES > AMIs).

Free Space

Defragment

  • Optimize C:\ with the defragmenter tool.

Zero free space

Final steps

  • Run ec2gaming snapshot to snapshot the EBS volume and create your AMI
  • Run ec2gaming terminate to terminate the instance

Steam client configuration

On your Mac, go to Steam Home-Streaming settings and:

  • Set the client options to 'Beautiful'
  • Under Advanced Client Options:
    • Limit bandwidth to 30MBit/s; I've found that the automatic setting is far too conservative when remote streaming
    • Ensure that 'Enable hardware decoding' is enabled
    • Optionally limit the resolution

Periodic maintenance

Because we treat the AMI as immutable, you'll want to periodically update Steam, run Windows Update etc. and re-snapshot and replace your AMI using the ec2gaming snapshot command.