Menu
Amazon GameLift Service
API Reference (API Version 2015-10-01)

SearchGameSessions

Retrieves a set of game sessions that match a set of search criteria and sorts them in a specified order. A game session search is limited to a single fleet. Search results include only game sessions that are in ACTIVE status. If you need to retrieve game sessions with a status other than active, use DescribeGameSessions. If you need to retrieve the protection policy for each game session, use DescribeGameSessionDetails.

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

  • gameSessionId -- 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.

  • 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.

  • 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.

  • hasAvailablePlayerSessions -- Boolean value indicating whether a game session has reached its maximum number of players. When searching with this attribute, the search value must be true or false. It is highly recommended that all search requests include this filter attribute to optimize search performance and return only sessions that players can join.

To search or sort, specify either a fleet ID or an alias ID, and provide a search filter expression, a sort expression, or both. Use the pagination parameters to retrieve results as a set of sequential pages. If successful, a collection of GameSession objects matching the request is returned.

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.

Game-session-related operations include:

Request Syntax

{
   "AliasId": "string",
   "FilterExpression": "string",
   "FleetId": "string",
   "Limit": number,
   "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

Unique identifier for an alias associated with the fleet to search for active game sessions. Each request must reference either a fleet ID or alias ID, but not both.

Type: String

Pattern: ^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, creationTimeMillis, playerSessionCount, maximumSessions, hasAvailablePlayerSessions.

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

  • Value -- Value to be searched for. Values can be numbers, boolean values (true/false) or strings. String values are case sensitive, 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

Unique identifier for a fleet to search for active game sessions. Each request must reference either a fleet ID or alias ID, but not both.

Type: String

Pattern: ^fleet-\S+

Required: No

Limit

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

NextToken

Token that indicates the start of the next sequential page of results. Use the token that is returned with a previous call to this action. 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, creationTimeMillis, playerSessionCount, maximumSessions, 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,
         "FleetId": "string",
         "GameProperties": [ 
            { 
               "Key": "string",
               "Value": "string"
            }
         ],
         "GameSessionData": "string",
         "GameSessionId": "string",
         "IpAddress": "string",
         "MaximumPlayerSessionCount": number,
         "Name": "string",
         "PlayerSessionCreationPolicy": "string",
         "Port": number,
         "Status": "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

Collection of objects containing game session properties for each session matching the request.

Type: Array of GameSession objects

NextToken

Token that indicates where to resume retrieving results on the next call to this action. 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

This example finds all game sessions with at least two players already connected. We recommend that all game session searches also filter out all active game sessions that are not accepting new players.

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

Sample Request

POST / HTTP/1.1
Host: gamelift.us-west-2.amazonaws.com;
Accept-Encoding: identity
Content-Length: 135
User-Agent: aws-cli/1.11.36 Python/2.7.9 Windows/7 botocore/1.4.93
Content-Type: application/x-amz-json-1.0
Authorization: AWS4-HMAC-SHA256  Credential=AKIAIOSFODNN7EXAMPLE/20170406/us-west-2/gamelift/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
X-Amz-Date: 20170406T004805Z
X-Amz-Target: GameLift.SearchGameSessions 
	
    {"AliasId": "MAG-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

HTTP/1.1 200 OK
x-amzn-RequestId: b34f8665-EXAMPLE
Content-Type: application/x-amz-json-1.1
Content-Length: 1036
Date: Thu, 06 Apr 2017 00:48:07 GMT

{"GameSessions": 
  [
     "GameSessionId": "gsess-653522bb-89e8-4b96-b925-725c169b1e5d", 
     "IpAddress": "54.186.43.45", 
     "MaximumPlayerSessionCount": 10, 
     "Name": "Matt's Awesome Game", 
     "Status": "ACTIVE"},
    {"CreationTime": 1469498468.057, 
     "CurrentPlayerSessionCount": 5, 
     "FleetId": "fleet-a7abc071-5537-4f0f-b5ee-1b5c1187565f", 
     "GameProperties": [
        {"Key": "Map",
         "Value": "Snowfall"},
        {"Key": "Scheme",
         "Value": "Blue"}
     ], 
     "GameSessionId": "gsess-be142e60-04d1-452a-8016-6790b796eea1", 
     "IpAddress": "54.186.139.221", 
     "MaximumPlayerSessionCount": 10, 
     "Name": "Matt's Awesome Game", 
     "Status": "ACTIVE"}, 
    {"CreationTime": 1469498497.792, 
     "CurrentPlayerSessionCount": 3,
     "FleetId": "fleet-a7abc071-5537-4f0f-b5ee-1b5c1187565f", 
     "GameProperties": [
        {"Key": "Map",
         "Value": "Dystopia"},
        {"Key": "Scheme",
         "Value": "GreenBlack"}
     ] 
   ]
}                

Search and sort game sessions

This example finds all game sessions that allow 20 players (indicates team fighting mode) and are currently accepting new players. Results are sorted so that the newest game sessions are returned first.

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

Sample Request

POST / HTTP/1.1
Host: gamelift.us-west-2.amazonaws.com;
Accept-Encoding: identity
Content-Length: 198
User-Agent: aws-cli/1.11.36 Python/2.7.9 Windows/7 botocore/1.4.93
Content-Type: application/x-amz-json-1.0
Authorization: AWS4-HMAC-SHA256  Credential=AKIAIOSFODNN7EXAMPLE/20170406/us-west-2/gamelift/aws4_request, SignedHeaders=content-type;host;x-amz-date;x-amz-target, Signature=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
X-Amz-Date: 20170406T004805Z
X-Amz-Target: GameLift.SearchGameSessions 
	
    {"FleetId": "fleet-a7abc071-5537-4f0f-b5ee-1b5c1187565f",
     "FilterExpression": "maximumSessions=20 AND hasAvailablePlayerSessions=true",
     "SortExpression": "creationTimeMillis DESC"
    }
    
CLI syntax:
    aws gamelift search-game-sessions --fleet-id "fleet-a7abc071-5537-4f0f-b5ee-1b5c1187565f" --filter-expression "maximumSessions=20 AND hasAvailablePlayerSessions=true" --sort-expression "creationTimeMillis DESC"
                

Sample Response

HTTP/1.1 200 OK
x-amzn-RequestId: b34f8665-EXAMPLE
Content-Type: application/x-amz-json-1.1
Content-Length: 1184
Date: Thu, 06 Apr 2017 00:48:07 GMT

{"GameSessions": [
    {
        "CreationTime": 1469498497.792, 
        "CurrentPlayerSessionCount": 16,
        "FleetId": "fleet-a7abc071-5537-4f0f-b5ee-1b5c1198676087565f", 
        "GameProperties": [
            {   "Key": "Map",
                "Value": "Snowfall"},
            {   "Key": "Scheme",
                "Value": "Blue"}
        ], 
        "GameSessionId": "gsess-653522bb-89e8-4b96-b925-725c169f2ee0", 
        "IpAddress": "54.186.43.45", 
        "MaximumPlayerSessionCount": 20, 
        "Name": "Matt's Awesome Game", 
        "Status": "ACTIVE"
    },
    {
        "CreationTime": 1469498468.057, 
        "CurrentPlayerSessionCount": 5, 
        "FleetId": "fleet-a7abc071-5537-4f0f-b5ee-1b5c1187565f", 
        "GameProperties": [
            {   "Key": "Map",
                "Value": "Dystopia"},
            {   "Key": "Scheme",
                "Value": "GreenBlack"}
         ], 
         "GameSessionId": "gsess-be142e60-04d1-452a-8016-6790b792ffa3", 
         "IpAddress": "54.186.139.221", 
        "MaximumPlayerSessionCount": 20, 
        "Name": "Matt's Awesome Game", 
        "Status": "ACTIVE"
    } 
   ]
}                            

See Also

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