Use Spot Instances with GameLift - Amazon GameLift
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China.

Use Spot Instances with GameLift

When setting up your EC2 fleet hosting resources, you have the option of using Spot Instances, On-Demand Instances, or a combination. Learn more about how GameLift uses Spot Instances in On-Demand Instances versus Spot Instances. If you choose to use Spot fleets, you'll need to make a few adjustments to your game integration.

Are you using FlexMatch for matchmaking? You can add Spot fleets to your existing game session queues for matchmaking placements.

To set up game and hosting resources for Spot fleets:
  1. Design a game session queue with a "Spot-optimized" configuration. Managing game session placement with a queue is always a best practice, and it's required when using Spot Instances. For this step, you need to identify which Regions/locations the queue will place game sessions into, and select the right combination of instance types (hardware) for your game servers. This information tells you the types of fleets you'll need to set up. For help designing a queue that optimizes Spot availability and resiliency, see Best practices for queues with Spot fleets.

  2. Create the fleets for your Spot-optimized queue. Based on your queue design, create fleets to deploy your game servers to your desired locations and instance types. Spot fleets and On-Demand fleets can have identical configurations other than the fleet type designation. See Create a managed fleet for help creating and configuring new fleets.


    We recommend that you include the fleet type (Spot or On-Demand) in the fleet name. This will make it easy to identify Spot or On-Demand fleets in a long list of fleet names, such as when adding fleets to a queue.

  3. Create your game session queue. After you've set up the fleets based on your Spot-optimized queue design, you can create the queue. Add the fleet destinations, configure the game session placement process, and define placement priorities. See Create a game session queue for help creating and configuring the new queue.

  4. Enable your game client or client service to request new game sessions using the Spot-optimized queue. If you're not already doing so, update your game client code to request new game sessions using a queue for game session placement. This approach enables the use of FleetIQ to avoid resources with a high chance of interruption and select the best available location based on your defined priorities (such as player latency. hosting cost, and geographical location). Queues also provide fallback hosting resources in the unlikely event that a preferred location is not available. For help implementing game session placements in your game client, see Create game sessions.

  5. Enable your game server to handle a Spot interruption. Spot Instances can be interrupted with two minutes' notification when Amazon needs the capacity back. You'll want your game server to handle an interruption gracefully, if it happens, and minimize the player impact. When Amazon is about to reclaim a Spot Instance, it sends termination notification up to two minutes before, which GameLift passes on to all affected server processes. This is done by invoking the Server SDK callback function onProcessTerminate(). Implementing this callback function is always a best practice, but it is particularly important when using Spot Instances. The implementation of this callback can take action to either gracefully end the game sessions or find a way to move the game sessions and players to a new placement. See Respond to a server process shutdown notification for help implementing onProcessTerminate().


    Amazon makes every effort to provide the notification as soon as an instance is chosen for termination, but there is the possibility that the Spot Instance will be terminated before the warning arrives. Your game server should be prepared to handle unexpected interruptions.

  6. Evaluate the performance of your Spot fleets and queues. Once the new queue is actively placing new game sessions, use GameLift metrics to evaluate performance. Key metrics include:

    • Interruption rate – Track the number and frequency of Spot-related interruptions for instances and game sessions in a Spot fleet. These fleet metrics (InstanceInterruptions and GameSessionInterruptions) can be viewed in the GameLift console or by using Amazon CloudWatch (see GameLift metrics for fleets). If you aggregate fleet metrics in a metrics group, you can also view interruptions by instance type and operating system in CloudWatch. Game sessions that were terminated for Spot-related reasons have a status of "TERMINATED" and a status reason of "INTERRUPTED".

    • Queue effectiveness – Track metrics for your queues, including placement success rates, average wait time, and queue depth to verify that the use of Spot fleets has no impact on queue performance. Queue metrics can be viewed in the GameLift console or by using Amazon CloudWatch.

    • Fleet utilization – Monitor usage rates for your fleets, including data on instances, game sessions and player sessions. Usage for your On-Demand fleets can be an indicator that FleetIQ is choosing to avoid risky placements into your Spot fleets and falling back to the On-Demand fleets. Fleet utilization metrics can be viewed in the GameLift console or by using Amazon CloudWatch.