Skip to content

create_player_session

create_player_session(
    *,
    config_overrides: Optional[GameLiftClientConfig] = None,
    game_session_id: Optional[ArnStringModel] = None,
    player_id: Optional[PlayerId] = None,
    player_data: Optional[PlayerData] = None,
) -> CreatePlayerSessionOutput

This API works with the following fleet types: EC2, Anywhere, Container

Reserves an open player slot in a game session for a player. New player sessions can be created in any game session with an open slot that is in ACTIVE status and has a player creation policy of ACCEPT_ALL. You can add a group of players to a game session with CreatePlayerSessions .

To create a player session, specify a game session ID, player ID, and optionally a set of player data.

If successful, a slot is reserved in the game session for the player and a new PlayerSessions object is returned with a player session ID. The player references the player session ID when sending a connection request to the game session, and the game server can use it to validate the player reservation with the Amazon GameLift Servers service. Player sessions cannot be updated.

The maximum number of players per game session is 200. It is not adjustable.

Related actions

All APIs by task

Parameters:

  • game_session_id (Optional[ArnStringModel], default: None ) –

    An identifier for the game session that is unique across all regions to add a player to. The value is always a full ARN in the following format: For Home Region game session - arn:aws:gamelift:::gamesession//. For Remote Location game session - arn:aws:gamelift:::gamesession///.

  • player_id (Optional[PlayerId], default: None ) –

    A unique identifier for a player. Player IDs are developer-defined.

  • player_data (Optional[PlayerData], default: None ) –

    Developer-defined information related to a player. Amazon GameLift Servers does not use this data, so it can be formatted as needed for use in the game.

Raises:

  • GameSessionFullException –

    The game instance is currently full and cannot allow the requested player(s) to join. Clients can retry such requests immediately or after a waiting period.

  • InternalServiceException –

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

  • InvalidGameSessionStatusException –

    The requested operation would cause a conflict with the current state of a resource associated with the request and/or the game instance. Resolve the conflict before retrying.

  • InvalidRequestException –

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

  • NotFoundException –

    The requested resource was not found. The resource was either not created yet or deleted.

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

  • UnauthorizedException –

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

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_gamelift/_services/game_lift.py
def create_player_session(
    self,
    *,
    config_overrides: Optional[GameLiftClientConfig] = None,
    game_session_id: Optional[
        "capo_gamelift.types.arn_string_model.ArnStringModel"
    ] = None,
    player_id: Optional["capo_gamelift.types.player_id.PlayerId"] = None,
    player_data: Optional["capo_gamelift.types.player_data.PlayerData"] = None,
) -> "capo_gamelift.types.create_player_session_output.CreatePlayerSessionOutput":
    """<p> <b>This API works with the following fleet types:</b> EC2, Anywhere, Container</p> <p>Reserves an open player slot in a game session for a player. New player sessions can be created in any game session with an open slot that is in <code>ACTIVE</code> status and has a player creation policy of <code>ACCEPT_ALL</code>. You can add a group of players to a game session with <a href="https://docs.aws.amazon.com/gamelift/latest/apireference/API_CreatePlayerSessions.html">CreatePlayerSessions</a> . </p> <p>To create a player session, specify a game session ID, player ID, and optionally a set of player data. </p> <p>If successful, a slot is reserved in the game session for the player and a new <code>PlayerSessions</code> object is returned with a player session ID. The player references the player session ID when sending a connection request to the game session, and the game server can use it to validate the player reservation with the Amazon GameLift Servers service. Player sessions cannot be updated. </p> <p>The maximum number of players per game session is 200. It is not adjustable. </p> <p> <b>Related actions</b> </p> <p> <a href="https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets">All APIs by task</a> </p>

    Args:
        game_session_id: <p>An identifier for the game session that is unique across all regions to add a player to. The value is always a full ARN in the following format: For Home Region game session - <code>arn:aws:gamelift:<home_region>::gamesession/<fleet ID>/<ID string></code>. For Remote Location game session - <code>arn:aws:gamelift:<home_region>::gamesession/<fleet ID>/<location>/<ID string></code>.</p>
        player_id: <p>A unique identifier for a player. Player IDs are developer-defined.</p>
        player_data: <p>Developer-defined information related to a player. Amazon GameLift Servers does not use this data, so it can be formatted as needed for use in the game.</p>

    Raises:
        capo_gamelift.errors.game_session_full_exception.GameSessionFullException: <p>The game instance is currently full and cannot allow the requested player(s) to join. Clients can retry such requests immediately or after a waiting period.</p>
        capo_gamelift.errors.internal_service_exception.InternalServiceException: <p>The service encountered an unrecoverable internal failure while processing the request. Clients can retry such requests immediately or after a waiting period.</p>
        capo_gamelift.errors.invalid_game_session_status_exception.InvalidGameSessionStatusException: <p>The requested operation would cause a conflict with the current state of a resource associated with the request and/or the game instance. Resolve the conflict before retrying.</p>
        capo_gamelift.errors.invalid_request_exception.InvalidRequestException: <p>One or more parameter values in the request are invalid. Correct the invalid parameter values before retrying.</p>
        capo_gamelift.errors.not_found_exception.NotFoundException: <p>The requested resource was not found. The resource was either not created yet or deleted.</p>
        capo_gamelift.errors.terminal_routing_strategy_exception.TerminalRoutingStrategyException: <p>The service is unable to resolve the routing for a particular alias because it has a terminal <code>RoutingStrategy</code> 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. </p>
        capo_gamelift.errors.unauthorized_exception.UnauthorizedException: <p>The client failed authentication. Clients should not retry such requests.</p>
        capo_gamelift.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_gamelift.types.create_player_session_input.CreatePlayerSessionInput]",
    ) -> OperationResponse[
        "capo_gamelift.types.create_player_session_output.CreatePlayerSessionOutput"
    ]:
        import capo_gamelift._operations.game_lift.create_player_session

        output, http_response = (
            capo_gamelift._operations.game_lift.create_player_session.create_player_session(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_gamelift.types.create_player_session_input.CreatePlayerSessionInput",
    ) -> dict[str, Any]:
        import capo_gamelift.types.create_player_session_input

        return capo_gamelift.types.create_player_session_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_gamelift.types.create_player_session_output.CreatePlayerSessionOutput",
    ) -> dict[str, Any]:
        import capo_gamelift.types.create_player_session_output

        return capo_gamelift.types.create_player_session_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreatePlayerSession",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_gamelift.types.create_player_session_input.CreatePlayerSessionInput = {}
    if game_session_id is not None:
        input_["game_session_id"] = game_session_id
    if player_id is not None:
        input_["player_id"] = player_id
    if player_data is not None:
        input_["player_data"] = player_data

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output