Skip to content

create_stream_session_connection

create_stream_session_connection(
    identifier: Identifier,
    stream_session_identifier: Identifier,
    signal_request: SignalRequest,
    *,
    config_overrides: Optional[GameLiftStreamsClientConfig] = None,
    client_token: Optional[ClientToken] = None,
) -> CreateStreamSessionConnectionOutput

Enables clients to reconnect to a stream session while preserving all session state and data in the disconnected session. This reconnection process can be initiated when a stream session is in either PENDING_CLIENT_RECONNECTION or ACTIVE status. The process works as follows:

  1. Initial disconnect:

    • When a client disconnects or loses connection, the stream session transitions from CONNECTED to PENDING_CLIENT_RECONNECTION

  2. Reconnection time window:

    • Clients have ConnectionTimeoutSeconds (defined in StartStreamSession) to reconnect before session termination

    • Your backend server must call CreateStreamSessionConnection to initiate reconnection

    • Session transitions to RECONNECTING status

  3. Reconnection completion:

    • On successful CreateStreamSessionConnection, session status changes to ACTIVE

    • Provide the new connection information to the requesting client

    • Client must establish connection within ConnectionTimeoutSeconds

    • Session terminates automatically if client fails to connect in time

For more information about the stream session lifecycle, see Stream sessions in the Amazon GameLift Streams Developer Guide.

To begin re-connecting to an existing stream session, specify the stream group ID and stream session ID that you want to reconnect to, and the signal request to use with the stream.

Parameters:

  • client_token (Optional[ClientToken], default: None ) –

    A unique identifier that represents a client request. The request is idempotent, which ensures that an API request completes only once. When users send a request, Amazon GameLift Streams automatically populates this field.

  • identifier (Identifier) –

    Amazon Resource Name (ARN) or ID that uniquely identifies the stream group resource. Example ARN: arn:aws:gameliftstreams:us-west-2:111122223333:streamgroup/sg-1AB2C3De4. Example ID: sg-1AB2C3De4.

    The stream group that you want to run this stream session with. The stream group must be in ACTIVE status.

  • stream_session_identifier (Identifier) –

    Amazon Resource Name (ARN) or ID that uniquely identifies the stream session resource. Example ARN: arn:aws:gameliftstreams:us-west-2:111122223333:streamsession/sg-1AB2C3De4/ABC123def4567. Example ID: ABC123def4567.

    The stream session must be in PENDING_CLIENT_RECONNECTION or ACTIVE status.

  • signal_request (SignalRequest) –

    A WebRTC ICE offer string to use when initializing a WebRTC connection. The offer is a very long JSON string. Provide the string as a text value in quotes. The offer must be newly generated, not the same offer provided to StartStreamSession.

Raises:

  • AccessDeniedException –

    You don't have the required permissions to access this Amazon GameLift Streams resource. Correct the permissions before you try again.

  • ConflictException –

    The requested operation would cause a conflict with the current state of a service resource associated with the request. Resolve the conflict before retrying this request.

  • InternalServerException –

    The service encountered an internal error and is unable to complete the request.

  • ResourceNotFoundException –

    The resource specified in the request was not found. Correct the request before you try again.

  • ThrottlingException –

    The request was denied due to request throttling. Retry the request after the suggested wait time.

  • ValidationException –

    One or more parameter values in the request fail to satisfy the specified constraints. Correct the invalid parameter values before retrying the request.

  • UnknownServiceError –

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

Source code in docs_src/capo_gameliftstreams/_services/game_lift_streams.py
def create_stream_session_connection(
    self,
    identifier: "capo_gameliftstreams.types.identifier.Identifier",
    stream_session_identifier: "capo_gameliftstreams.types.identifier.Identifier",
    signal_request: "capo_gameliftstreams.types.signal_request.SignalRequest",
    *,
    config_overrides: Optional[GameLiftStreamsClientConfig] = None,
    client_token: Optional[
        "capo_gameliftstreams.types.client_token.ClientToken"
    ] = None,
) -> "capo_gameliftstreams.types.create_stream_session_connection_output.CreateStreamSessionConnectionOutput":
    """<p>Enables clients to reconnect to a stream session while preserving all session state and data in the disconnected session. This reconnection process can be initiated when a stream session is in either <code>PENDING_CLIENT_RECONNECTION</code> or <code>ACTIVE</code> status. The process works as follows: </p> <ol> <li> <p>Initial disconnect:</p> <ul> <li> <p>When a client disconnects or loses connection, the stream session transitions from <code>CONNECTED</code> to <code>PENDING_CLIENT_RECONNECTION</code> </p> </li> </ul> </li> <li> <p>Reconnection time window:</p> <ul> <li> <p>Clients have <code>ConnectionTimeoutSeconds</code> (defined in <a href="https://docs.aws.amazon.com/gameliftstreams/latest/apireference/API_StartStreamSession.html">StartStreamSession</a>) to reconnect before session termination</p> </li> <li> <p>Your backend server must call <b>CreateStreamSessionConnection</b> to initiate reconnection</p> </li> <li> <p>Session transitions to <code>RECONNECTING</code> status</p> </li> </ul> </li> <li> <p>Reconnection completion:</p> <ul> <li> <p>On successful <b>CreateStreamSessionConnection</b>, session status changes to <code>ACTIVE</code> </p> </li> <li> <p>Provide the new connection information to the requesting client</p> </li> <li> <p>Client must establish connection within <code>ConnectionTimeoutSeconds</code> </p> </li> <li> <p>Session terminates automatically if client fails to connect in time</p> </li> </ul> </li> </ol> <p>For more information about the stream session lifecycle, see <a href="https://docs.aws.amazon.com/gameliftstreams/latest/developerguide/stream-sessions.html">Stream sessions</a> in the <i>Amazon GameLift Streams Developer Guide</i>.</p> <p>To begin re-connecting to an existing stream session, specify the stream group ID and stream session ID that you want to reconnect to, and the signal request to use with the stream.</p>

    Args:
        client_token: <p> A unique identifier that represents a client request. The request is idempotent, which ensures that an API request completes only once. When users send a request, Amazon GameLift Streams automatically populates this field. </p>
        identifier: <p> <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html">Amazon Resource Name (ARN)</a> or ID that uniquely identifies the stream group resource. Example ARN: <code>arn:aws:gameliftstreams:us-west-2:111122223333:streamgroup/sg-1AB2C3De4</code>. Example ID: <code>sg-1AB2C3De4</code>. </p> <p> The stream group that you want to run this stream session with. The stream group must be in <code>ACTIVE</code> status. </p>
        stream_session_identifier: <p> <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference-arns.html">Amazon Resource Name (ARN)</a> or ID that uniquely identifies the stream session resource. Example ARN: <code>arn:aws:gameliftstreams:us-west-2:111122223333:streamsession/sg-1AB2C3De4/ABC123def4567</code>. Example ID: <code>ABC123def4567</code>. </p> <p> The stream session must be in <code>PENDING_CLIENT_RECONNECTION</code> or <code>ACTIVE</code> status. </p>
        signal_request: <p>A WebRTC ICE offer string to use when initializing a WebRTC connection. The offer is a very long JSON string. Provide the string as a text value in quotes. The offer must be newly generated, not the same offer provided to <code>StartStreamSession</code>. </p>

    Raises:
        capo_gameliftstreams.errors.access_denied_exception.AccessDeniedException: <p>You don't have the required permissions to access this Amazon GameLift Streams resource. Correct the permissions before you try again.</p>
        capo_gameliftstreams.errors.conflict_exception.ConflictException: <p>The requested operation would cause a conflict with the current state of a service resource associated with the request. Resolve the conflict before retrying this request.</p>
        capo_gameliftstreams.errors.internal_server_exception.InternalServerException: <p>The service encountered an internal error and is unable to complete the request.</p>
        capo_gameliftstreams.errors.resource_not_found_exception.ResourceNotFoundException: <p>The resource specified in the request was not found. Correct the request before you try again.</p>
        capo_gameliftstreams.errors.throttling_exception.ThrottlingException: <p>The request was denied due to request throttling. Retry the request after the suggested wait time.</p>
        capo_gameliftstreams.errors.validation_exception.ValidationException: <p>One or more parameter values in the request fail to satisfy the specified constraints. Correct the invalid parameter values before retrying the request.</p>
        capo_gameliftstreams.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_gameliftstreams.types.create_stream_session_connection_input.CreateStreamSessionConnectionInput]",
    ) -> OperationResponse[
        "capo_gameliftstreams.types.create_stream_session_connection_output.CreateStreamSessionConnectionOutput"
    ]:
        import capo_gameliftstreams._operations.game_lift_streams.create_stream_session_connection

        output, http_response = (
            capo_gameliftstreams._operations.game_lift_streams.create_stream_session_connection.create_stream_session_connection(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_gameliftstreams.types.create_stream_session_connection_input.CreateStreamSessionConnectionInput",
    ) -> dict[str, Any]:
        import capo_gameliftstreams.types.create_stream_session_connection_input

        return capo_gameliftstreams.types.create_stream_session_connection_input.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_gameliftstreams.types.create_stream_session_connection_output.CreateStreamSessionConnectionOutput",
    ) -> dict[str, Any]:
        import capo_gameliftstreams.types.create_stream_session_connection_output

        return capo_gameliftstreams.types.create_stream_session_connection_output.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateStreamSessionConnection",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_gameliftstreams.types.create_stream_session_connection_input.CreateStreamSessionConnectionInput = {
        "identifier": identifier,
        "stream_session_identifier": stream_session_identifier,
        "signal_request": signal_request,
    }
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

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