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.
Topics
Create a custom location
To get started hosting games on your compute resources, create a custom location describing where your compute resides.
Create a fleet
Use either the Amazon GameLift console
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.
Register your compute
To register your compute resource in the fleet that you created, use the register-compute
with the fleet-id
fleet-id
returned in the previous step or fleet ARN found in the details page of your fleet in
the console. Replace the
, and
compute-name
with the IP address of your
compute resource.ip-address
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-idarn:aws:gamelift:us-east-1:111122223333:fleet/fleet-cebb4da2-52a8-4c27-9b85-587f945c6445
\ --ip-address10.1.2.3
\ --locationcustom-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
-
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
andget-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 thecompute-name
with the name of the compute you created using theregister-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-nameHardwareAnywhere
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" }
-
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); -
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
-
Add logic to your game server so that your server process responds to the
onStartGameSession()
message withActivateGameSession()
. 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(); }
-
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
\ --nameGameSession1
\ --maximum-player-session-count2
\ --locationcustom-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 theGameSession
object from the previous step with game properties, game sessions data, matchmaker data, and more about the game session. -
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);
-
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.