Create a Amazon GameLift Anywhere fleet - Amazon GameLift

Create a Amazon GameLift Anywhere fleet

Use Amazon GameLift to integrate hardware from your environment into your Amazon GameLift game hosting. Amazon GameLift Anywhere registers your hardware with Amazon GameLift in an Anywhere fleet. You can integrate Anywhere and managed EC2 fleets in matchmaker and game session queues to manage matchmaking and game placement.

For more information about testing your game servers with Amazon GameLift Anywhere, see Test your integration using Amazon GameLift Anywhere fleets.

To get started, Development support with Amazon GameLift version 5 or greater and review the following important concepts for using a Amazon GameLift Anywhere fleet.

Custom locations

Amazon GameLift Anywhere fleets use custom locations to represent the physical locations of your infrastructure.

Device registration

For a Amazon GameLift Anywhere fleet to communicate with your compute resources, first register your device. You can complete device registration from the Amazon GameLift AWS SDK using the RegisterCompute operation. This operation uses the IP address of the device to associate it with a fleet location and communicate with Amazon GameLift.

Authentication tokens

When you initialize a game server on your compute, the Amazon GameLift Server SDK uses an auth token to authenticate your game server to Amazon GameLift. You can re-use the same auth token for all game servers on the same compute, up to the auth token expiration time. To retrieve the auth token, call the get-compute-auth-token AWS Command Line Interface (AWS CLI) command. Pass the token to each game server as needed.

Game sessions

Each game session on a compute uses the same authentication token created while registering the compute to a fleet location.

The following diagram shows a game session queue that uses FlexMatch matchmaking and multiple fleets. The fleets include an EC2 fleet with C5 instances, an Anywhere fleet with a development laptop, and an Anywhere fleet with a customer-hosted server rack.


            A diagram of a game session queue that uses an managed EC2 fleet and two
                Anywhere fleets.

Create a custom location

To get started hosting games on your compute resources, create a custom location describing where your compute resides.

Console
To create a custom location
  1. Open the Amazon GameLift console.

  2. In the navigation pane, under Hosting, choose Locations.

  3. On the Locations page, choose Create location.

  4. In the Create location dialog box, do the following:

    1. Enter a Location name. This labels the location of your hardware that Amazon GameLift uses to run your games in Anywhere fleets. Amazon GameLift appends the name of your custom location with custom-.

    2. (Optional) Add tags as key-value pairs to your custom location. Choose Add new tag for each tag that you want to add.

    3. Choose Create.

AWS CLI

Create a custom location using the create-location command. The location-name labels the location of your hardware that Amazon GameLift uses to run your games in Anywhere fleets. When creating your custom location, the location name must start with custom-.

aws gamelift create-location \ --location-name custom-location-1

Output

{ "Location": { "LocationName": "custom-location-1", "LocationArn": "arn:aws:gamelift:us-east-1:111122223333:location/custom-location-1" } }

Create a fleet

Use either the Amazon GameLift console or the AWS CLI to create an Anywhere fleet.

After you create a new Anywhere fleet, the fleet's status moves from NEW to ACTIVE. When it reaches ACTIVE status, the fleet is ready to host game sessions. For help with fleet creation issues, see Debug Amazon GameLift fleet issues.

Console
To create an Anywhere fleet
  1. Open the Amazon GameLift console.

  2. In the navigation pane, under Hosting, choose Fleets.

  3. On the Fleets page, choose Create fleet.

  4. On the Compute type step, choose Anywhere, and then choose Next.

  5. On the Fleet details step, define the details, and then choose Next.

  6. On the Custom locations step, select the custom location that you created, and then choose Next. Amazon GameLift automatically selects the home AWS Region as the Region that you're creating the fleet in. You can use the home Region to access and use your resources.

  7. Complete the remaining fleet creation steps, and then choose Submit to create your Anywhere fleet.

AWS CLI

Create an Anywhere fleet using the create-fleet command. Include your custom location in locations. Amazon GameLift creates the fleet in your home Region and in the custom locations that you provide. In the following example, replace FleetName and custom-location-1 with your own information. The variable custom-location-1 is the name of the location created in the Create a custom location step.

aws gamelift create-fleet \ --name FleetName \ --compute-type ANYWHERE \ --locations "Location=custom-location-1"

Example output

{ "FleetAttributes": { "FleetId": "fleet-cebb4da2-52a8-4c27-9b85-587f945c6445", "FleetArn": "arn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445", "Name": "HardwareAnywhere", "CreationTime": "2023-02-23T17:57:42.293000+00:00", "Status": "ACTIVE", "MetricGroups": [ "default" ], "CertificateConfiguration": { "CertificateType": "DISABLED" }, "ComputeType": "ANYWHERE" } }

Register your compute

To register your compute resource in the fleet that you created, use the register-compute command. Replace the fleet-id with the fleet-id returned in the previous step or fleet ARN found in the details page of your fleet in the console. Replace the compute-name, and ip-address with the IP address of your compute resource.

Note

Amazon GameLift recommends calling both the register-compute and get-compute-auth-token commands from a script or process manager separate from your game server.

aws gamelift register-compute \ --compute-name HardwareAnywhere \ --fleet-id arn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445 \ --ip-address 10.1.2.3 \ --location custom-location-1

Example output

{ "Compute": { "FleetId": "fleet-cebb4da2-52a8-4c27-9b85-587f945c6445", "FleetArn": "arn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445", "ComputeName": "HardwareAnywhere", "ComputeArn": "arn:aws:gamelift:us-east-1:111122223333:compute/HardwareAnywhere", "IpAddress": "10.1.2.3", "ComputeStatus": "Active", "Location": "custom-location-1", "CreationTime": "2023-02-23T18:09:26.727000+00:00", "GameLiftServiceSdkEndpoint": "wss://us-east-1.api.amazongamelift.com" } }

Run a server process

  1. Get the authentication token for your compute resource from the fleet that you created.

    Your game server uses the authentication token to authenticate with Amazon GameLift. Each authentication token has an expiration token. To continue using the compute resource to host your game server, retrieve a new authentication token before the expiration.

    Note

    Amazon GameLift recommends calling both the register-compute and get-compute-auth-token commands from a script or process manager separate from your game server.

    In the following example, replace the fleet-id with the ARN or fleet ID of the fleet created in the previous steps. Replace the compute-name with the name of the compute you created using the register-compute command in a previous step.

    aws gamelift get-compute-auth-token \ --fleet-id arn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445 \ --compute-name HardwareAnywhere

    Example output:

    { "FleetId": "fleet-cebb4da2-52a8-4c27-9b85-587f945c6445", "FleetArn": "arn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445", "ComputeName": "HardwareAnywhere", "ComputeArn": "arn:aws:gamelift:us-east-1:111122223333:compute/HardwareAnywhere", "AuthToken": "0c728041-3e84-4aaa-b927-a0fb202684c0", "ExpirationTimestamp": "2023-02-23T18:47:54+00:00" }
  2. Run an instance of your game server executable.

    To run your game server, initialize your game server by calling InitSDK() and passing it your server parameters. For more information about server parameters, see ServerParameters.

    Server SDK input:

    //Define the server parameters ServerParameters serverParameters = new ServerParameters( webSocketUrl=wss://us-east-1.api.amazongamelift.com, processId=PID1234, hostId=HardwareAnywhere, fleetId=arn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445, authToken=0c728041-3e84-4aaa-b927-a0fb202684c0); //InitSDK establishes a connection with GameLift's websocket server for communication. var initSDKOutcome = GameLiftServerAPI.InitSDK(serverParameters);
  3. After the server process is ready to host a game session, call ProcessReady() from your game server to Amazon GameLift. For more information about process parameters, see ProcessParameters

    // Set parameters and call ProcessReady var processParams = new ProcessParameters( this.OnStartGameSession, this.OnProcessTerminate, this.OnHealthCheck, this.OnUpdateGameSession, port=1024, new LogParameters(new List<string>() // Examples of log and error files written by the game server { "C:\\game\\logs", "C:\\game\\error" }) ); var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParams);

Create game sessions

  1. Add logic to your game server so that your server process responds to the onStartGameSession() message with ActivateGameSession(). This operation has no parameters, but it sends an acknowledgement to Amazon GameLift that your server received and accepted the create game session message.

    void OnStartGameSession(GameSession gameSession) { // game-specific tasks when starting a new game session, such as loading map // When ready to receive players var activateGameSessionOutcome = GameLiftServerAPI.ActivateGameSession(); }
  2. From your game client backend service, start your game session using the start-matchmaking, start-game-session-placement, or create-game-session command.

    aws gamelift create-game-session \ --fleet-id arn:aws:gamelift:us-east-1:682428703967:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445 \ --name GameSession1 \ --maximum-player-session-count 2 \ --location custom-location-1

    Example output:

    GameSession { FleetId = arn:aws:gamelift:us-east-1:682428703967:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445, GameSessionId = 4444-4444, Name = GameSession1, Location = custom-location-1, IpAddress = 10.2.3.4, Port = 1024, ... }

    Amazon GameLift sends an onStartGameSession() message to your registered server process. The message contains the GameSession object from the previous step with game properties, game sessions data, matchmaker data, and more about the game session.

  3. When the game session is complete, end the game server process.

    Server SDK input:

    var processEndingOutcome = GameLiftServerAPI.ProcessEnding(); if (processReadyOutcome.Success) Environment.Exit(0); // otherwise, exit with error code Environment.Exit(errorCode);
  4. Start another game server process by calling ProcessReady(processParams).

Migrate to managed EC2

After you've developed your game server and you're ready to prepare for production, you can have Amazon GameLift manage your hardware. To migrate to a managed EC2 fleet, upload your build to Amazon GameLift and create a managed EC2 fleet. For more information about uploading your build and setting up a fleet, see Upload a custom server build to Amazon GameLift and Create a Amazon GameLift managed fleet.