SearchGameSessions - GameLift Service

SearchGameSessions

Retrieves all active game sessions that match a set of search criteria and sorts them into a specified order.

This operation is not designed to be continually called to track game session status. This practice can cause you to exceed your API limit, which results in errors. Instead, you must configure configure an Amazon Simple Notification Service (SNS) topic to receive notifications from FlexMatch or queues. Continuously polling game session status with DescribeGameSessions should only be used for games in development with low game session usage.

When searching for game sessions, you specify exactly where you want to search and provide a search filter expression, a sort expression, or both. A search request can search only one fleet, but it can search all of a fleet's locations.

This operation can be used in the following ways:

  • To search all game sessions that are currently running on all locations in a fleet, provide a fleet or alias ID. This approach returns game sessions in the fleet's home Region and all remote locations that fit the search criteria.

  • To search all game sessions that are currently running on a specific fleet location, provide a fleet or alias ID and a location name. For location, you can specify a fleet's home Region or any remote location.

Use the pagination parameters to retrieve results as a set of sequential pages.

If successful, a GameSession object is returned for each game session that matches the request. Search finds game sessions that are in ACTIVE status only. To retrieve information on game sessions in other statuses, use DescribeGameSessions .

You can search or sort by the following game session attributes:

  • gameSessionId -- A unique identifier for the game session. You can use either a GameSessionId or GameSessionArn value.

  • gameSessionName -- Name assigned to a game session. This value is set when requesting a new game session with CreateGameSession or updating with UpdateGameSession . Game session names do not need to be unique to a game session.

  • gameSessionProperties -- Custom data defined in a game session's GameProperty parameter. GameProperty values are stored as key:value pairs; the filter expression must indicate the key and a string to search the data values for. For example, to search for game sessions with custom data containing the key:value pair "gameMode:brawl", specify the following: gameSessionProperties.gameMode = "brawl". All custom data values are searched as strings.

  • maximumSessions -- Maximum number of player sessions allowed for a game session. This value is set when requesting a new game session with CreateGameSession or updating with UpdateGameSession .

  • creationTimeMillis -- Value indicating when a game session was created. It is expressed in Unix time as milliseconds.

  • playerSessionCount -- Number of players currently connected to a game session. This value changes rapidly as players join the session or drop out.

  • hasAvailablePlayerSessions -- Boolean value indicating whether a game session has reached its maximum number of players. It is highly recommended that all search requests include this filter attribute to optimize search performance and return only sessions that players can join.

Note

Returned values for playerSessionCount and hasAvailablePlayerSessions change quickly as players join sessions and others drop out. Results should be considered a snapshot in time. Be sure to refresh search results often, and handle sessions that fill up before a player can join.

Related actions

CreateGameSession | DescribeGameSessions | DescribeGameSessionDetails | SearchGameSessions | UpdateGameSession | GetGameSessionLogUrl | StartGameSessionPlacement | DescribeGameSessionPlacement | StopGameSessionPlacement | All APIs by task

Request Syntax

{ "AliasId": "string", "FilterExpression": "string", "FleetId": "string", "Limit": number, "Location": "string", "NextToken": "string", "SortExpression": "string" }

Request Parameters

For information about the parameters that are common to all actions, see Common Parameters.

The request accepts the following data in JSON format.

Note

In the following list, the required parameters are described first.

AliasId

A unique identifier for the alias associated with the fleet to search for active game sessions. You can use either the alias ID or ARN value. Each request must reference either a fleet ID or alias ID, but not both.

Type: String

Pattern: ^alias-\S+|^arn:.*:alias\/alias-\S+

Required: No

FilterExpression

String containing the search criteria for the session search. If no filter expression is included, the request returns results for all game sessions in the fleet that are in ACTIVE status.

A filter expression can contain one or multiple conditions. Each condition consists of the following:

  • Operand -- Name of a game session attribute. Valid values are gameSessionName, gameSessionId, gameSessionProperties, maximumSessions, creationTimeMillis, playerSessionCount, hasAvailablePlayerSessions.

  • Comparator -- Valid comparators are: =, <>, <, >, <=, >=.

  • Value -- Value to be searched for. Values may be numbers, boolean values (true/false) or strings depending on the operand. String values are case sensitive and must be enclosed in single quotes. Special characters must be escaped. Boolean and string values can only be used with the comparators = and <>. For example, the following filter expression searches on gameSessionName: "FilterExpression": "gameSessionName = 'Matt\\'s Awesome Game 1'".

To chain multiple conditions in a single expression, use the logical keywords AND, OR, and NOT and parentheses as needed. For example: x AND y AND NOT z, NOT (x OR y).

Session search evaluates conditions from left to right using the following precedence rules:

  1. =, <>, <, >, <=, >=

  2. Parentheses

  3. NOT

  4. AND

  5. OR

For example, this filter expression retrieves game sessions hosting at least ten players that have an open player slot: "maximumSessions>=10 AND hasAvailablePlayerSessions=true".

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

FleetId

A unique identifier for the fleet to search for active game sessions. You can use either the fleet ID or ARN value. Each request must reference either a fleet ID or alias ID, but not both.

Type: String

Pattern: ^fleet-\S+|^arn:.*:fleet\/fleet-\S+

Required: No

Limit

The maximum number of results to return. Use this parameter with NextToken to get results as a set of sequential pages. The maximum number of results returned is 20, even if this value is not set or is set higher than 20.

Type: Integer

Valid Range: Minimum value of 1.

Required: No

Location

A fleet location to search for game sessions. You can specify a fleet's home Region or a remote location. Use the AWS Region code format, such as us-west-2.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 64.

Pattern: ^[a-z]+(-([a-z]+|\d))*

Required: No

NextToken

A token that indicates the start of the next sequential page of results. Use the token that is returned with a previous call to this operation. To start at the beginning of the result set, do not specify a value.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

SortExpression

Instructions on how to sort the search results. If no sort expression is included, the request returns results in random order. A sort expression consists of the following elements:

  • Operand -- Name of a game session attribute. Valid values are gameSessionName, gameSessionId, gameSessionProperties, maximumSessions, creationTimeMillis, playerSessionCount, hasAvailablePlayerSessions.

  • Order -- Valid sort orders are ASC (ascending) and DESC (descending).

For example, this sort expression returns the oldest active sessions first: "SortExpression": "creationTimeMillis ASC". Results with a null value for the sort operand are returned at the end of the list.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Required: No

Response Syntax

{ "GameSessions": [ { "CreationTime": number, "CreatorId": "string", "CurrentPlayerSessionCount": number, "DnsName": "string", "FleetArn": "string", "FleetId": "string", "GameProperties": [ { "Key": "string", "Value": "string" } ], "GameSessionData": "string", "GameSessionId": "string", "IpAddress": "string", "Location": "string", "MatchmakerData": "string", "MaximumPlayerSessionCount": number, "Name": "string", "PlayerSessionCreationPolicy": "string", "Port": number, "Status": "string", "StatusReason": "string", "TerminationTime": number } ], "NextToken": "string" }

Response Elements

If the action is successful, the service sends back an HTTP 200 response.

The following data is returned in JSON format by the service.

GameSessions

A collection of objects containing game session properties for each session that matches the request.

Type: Array of GameSession objects

NextToken

A token that indicates where to resume retrieving results on the next call to this operation. If no token is returned, these results represent the end of the list.

Type: String

Length Constraints: Minimum length of 1. Maximum length of 1024.

Errors

For information about the errors that are common to all actions, see Common Errors.

InternalServiceException

The service encountered an unrecoverable internal failure while processing the request. Clients can retry such requests immediately or after a waiting period.

HTTP Status Code: 500

InvalidRequestException

One or more parameter values in the request are invalid. Correct the invalid parameter values before retrying.

HTTP Status Code: 400

NotFoundException

A service resource associated with the request could not be found. Clients should not retry such requests.

HTTP Status Code: 400

TerminalRoutingStrategyException

The service is unable to resolve the routing for a particular alias because it has a terminal RoutingStrategy associated with it. The message returned in this exception is the message defined in the routing strategy itself. Such requests should only be retried if the routing strategy for the specified alias is modified.

HTTP Status Code: 400

UnauthorizedException

The client failed authentication. Clients should not retry such requests.

HTTP Status Code: 400

Examples

Search game sessions

In this example, we want to find all game sessions that have at least two players already connected. We also want to filter out active game sessions that are not accepting new players.

This example illustrates a search that includes all of the fleet's locations. The results include a matching game session in the fleet's home Region (us-west-2) and another in a remote location (ca-central-1).

HTTP requests are authenticated using an AWS Signature Version 4 signature in the Authorization header field.

Sample Request

{"AliasId": "MOG-base", "FilterExpression": "playerSessionCount>=2 AND hasAvailablePlayerSessions=true", "Limit": 2 } CLI syntax: aws gamelift search-game-sessions --alias-id "MOG-base" --filter-expression "playerSessionCount>=2 AND hasAvailablePlayerSessions=true" --limit 2

Sample Response

{ "GameSessions": [ { "CreationTime": 1469498468.057, "CurrentPlayerSessionCount": 5, "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "GameProperties": [ {"Key": "difficulty","Value": "Easy"}, {"Key": "gameMap","Value": "Snowfall"}, {"Key": "gameMode","Value": "Explore"} ], "GameSessionId": "gsess-4444dddd-55ee-66ff-77aa-8888bbbb99cc", "IpAddress": "192.0.2.0", "MaximumPlayerSessionCount": 10, "Name": "Matt's Awesome Game win123", "Port": "8080", "Status": "ACTIVE", "Location": "us-west-2" }, { "CreationTime": 1469498497.792, "CurrentPlayerSessionCount": 3, "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "GameProperties": [ {"Key": "difficulty","Value": "Insane"}, {"Key": "gameMap","Value": "Dystopia"}, {"Key": "gameMode","Value": "FFA"} ], "GameSessionId": "gsess-7777dddd-55ee-66ff-44aa-8888bbbb99cc", "IpAddress": "192.0.2.0", "MaximumPlayerSessionCount": 10, "Name": "Matt's Awesome Game win456", "Port": "8080", "Status": "ACTIVE", "Location": "ca-central-1" } ] }

Search and sort game sessions

In this example, we want to find all game sessions that allow 20 or more players and are currently accepting new players. We want the results to be sorted so that the newest game sessions are returned first.

This example illustrates a search of a single fleet location. The requested fleet, which resides in us-west-2, also has game sessions in remote locations, including ap-southeast-2. As shown, the results are limited to the requested fleet location.

HTTP requests are authenticated using an AWS Signature Version 4 signature in the Authorization header field.

Sample Request

{ "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "Location": "ap-southeast-2", "FilterExpression": "maximumSessions>=20 AND hasAvailablePlayerSessions=true", "SortExpression": "creationTimeMillis DESC" "Limit": 2 } CLI syntax: aws gamelift search-game-sessions --fleet-id "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa" --location "ap-southeast-2" --filter-expression "maximumSessions=20 AND hasAvailablePlayerSessions=true" --sort-expression "creationTimeMillis DESC"

Sample Response

{ "GameSessions": [ { "CreationTime": 1469498497.792, "CurrentPlayerSessionCount": 3, "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "GameProperties": [ {"Key": "difficulty","Value": "Hard"}, {"Key": "gameMap","Value": "Dystopia"}, {"Key": "gameMode","Value": "Brawl"} ], "GameSessionId": "gsess-7777dddd-55ee-66ff-44aa-8888bbbb99cc", "IpAddress": "192.0.2.0", "MaximumPlayerSessionCount": 20, "Name": "Matt's Awesome Game win456", "Port": "8080", "Status": "ACTIVE", "Location": "ap-southeast-2" }, { "CreationTime": 1469498468.057, "CurrentPlayerSessionCount": , "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "GameProperties": [ {"Key": "difficulty","Value": "Easy"}, {"Key": "gameMap","Value": "Snowfall"}, {"Key": "gameMode","Value": "Explore"} ], "GameSessionId": "gsess-4444dddd-55ee-66ff-77aa-8888bbbb99cc", "IpAddress": "192.0.2.0", "MaximumPlayerSessionCount": 50, "Name": "Matt's Awesome Game win123", "Port": "8080", "Status": "ACTIVE", "Location": "ap-southeast-2" } ] }

Search game sessions by custom game data

This example searches for game sessions based on game map and game mode information, which is stored as custom data in the GameSession object. The game session property GameProperty contains custom data formatted as key:value pairs. In this example, we want to find all game sessions where the game mode is free-for-all (key:value pair "gameMode:Ffa") and set in either of two game maps (key:value pair "gameMap:Suzuka" or "gameMap:Silverstone"). Results are sorted by difficulty levels (key "difficulty", values "Easy", Normal" "Hard" "Insane"). Note: custom data is evaluated as a string, so the sorted results will be listed by the alphabetic order of the difficulty values.

HTTP requests are authenticated using an AWS Signature Version 4 signature in the Authorization header field.

Sample Request

{ "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "Location": "us-west-2", "FilterExpression": "gameSessionProperties.gameMode = 'Ffa' AND gameSessionProperties.gameMap = 'Suzuka' OR gameSessionProperties.gameMap = 'Silverstone'", "SortExpression": "gameSessionProperties.difficulty ASC" "Limit": 2 } CLI syntax: aws gamelift search-game-sessions --fleet-id "9999ffff-88ee-77dd-66cc-5555bbbb44aa" --filter-expression "gameSessionProperties.gameMode = 'Ffa' AND gameSessionProperties.gameMap = 'Suzuka' OR gameSessionProperties.gameMap = 'Silverstone'" --sort-expression "gameSessionProperties.difficulty DESC"

Sample Response

{ "GameSessions": [ { "CreationTime": 1469498468.057, "CurrentPlayerSessionCount": 5, "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "GameProperties": [ {"Key": "difficulty","Value": "Easy"}, {"Key": "gameMap","Value": "Suzuka"}, {"Key": "gameMode","Value": "Ffa"} ], "GameSessionId": "gsess-4444dddd-55ee-66ff-77aa-8888bbbb99cc", "IpAddress": "192.0.2.0", "MaximumPlayerSessionCount": 10, "Name": "Matt's Awesome Game win123", "Port": "8080", "Status": "ACTIVE" "Location": "us-west-2" }, { "CreationTime": 1469498497.792, "CurrentPlayerSessionCount": 3, "FleetId": "fleet-9999ffff-88ee-77dd-66cc-5555bbbb44aa", "GameProperties": [ {"Key": "difficulty","Value": "Normal"}, {"Key": "gameMap","Value": "Silverstone"}, {"Key": "gameMode","Value": "Ffa"} ], "GameSessionId": "gsess-7777dddd-55ee-66ff-44aa-8888bbbb99cc", "IpAddress": "192.0.2.0", "MaximumPlayerSessionCount": 10, "Name": "Matt's Awesome Game win456", "Port": "8080", "Status": "ACTIVE" "Location": "us-west-2" } ] }

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: