Skip to content

cancel_query

cancel_query(
    query_id: UUID,
    *,
    config_overrides: Optional[CloudTrailClientConfig] = None,
    event_data_store: Optional[EventDataStoreArn] = None,
    event_data_store_owner_account_id: Optional[AccountId] = None,
) -> CancelQueryResponse

CloudTrail Lake will no longer be open to new customers starting May 31, 2026. If you would like to use CloudTrail Lake, sign up prior to that date. Existing customers can continue to use the service as normal. For more information, see CloudTrail Lake availability change.

Cancels a query if the query is not in a terminated state, such as CANCELLED, FAILED, TIMED_OUT, or FINISHED. You must specify an ARN value for EventDataStore. The ID of the query that you want to cancel is also required. When you run CancelQuery, the query status might show as CANCELLED even if the operation is not yet finished.

Parameters:

  • event_data_store (Optional[EventDataStoreArn], default: None ) –

    The ARN (or the ID suffix of the ARN) of an event data store on which the specified query is running.

  • query_id (UUID) –

    The ID of the query that you want to cancel. The QueryId comes from the response of a StartQuery operation.

  • event_data_store_owner_account_id (Optional[AccountId], default: None ) –

    The account ID of the event data store owner.

Raises:

Source code in docs_src/capo_cloudtrail/_services/cloud_trail.py
def cancel_query(
    self,
    query_id: "capo_cloudtrail.types.uuid.UUID",
    *,
    config_overrides: Optional[CloudTrailClientConfig] = None,
    event_data_store: Optional[
        "capo_cloudtrail.types.event_data_store_arn.EventDataStoreArn"
    ] = None,
    event_data_store_owner_account_id: Optional[
        "capo_cloudtrail.types.account_id.AccountId"
    ] = None,
) -> "capo_cloudtrail.types.cancel_query_response.CancelQueryResponse":
    """<important> <p>CloudTrail Lake will no longer be open to new customers starting May 31, 2026. If you would like to use CloudTrail Lake, sign up prior to that date. Existing customers can continue to use the service as normal. For more information, see <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-lake-service-availability-change.html">CloudTrail Lake availability change</a>.</p> </important> <p>Cancels a query if the query is not in a terminated state, such as <code>CANCELLED</code>, <code>FAILED</code>, <code>TIMED_OUT</code>, or <code>FINISHED</code>. You must specify an ARN value for <code>EventDataStore</code>. The ID of the query that you want to cancel is also required. When you run <code>CancelQuery</code>, the query status might show as <code>CANCELLED</code> even if the operation is not yet finished.</p>

    Args:
        event_data_store: <p>The ARN (or the ID suffix of the ARN) of an event data store on which the specified query is running.</p>
        query_id: <p>The ID of the query that you want to cancel. The <code>QueryId</code> comes from the response of a <code>StartQuery</code> operation.</p>
        event_data_store_owner_account_id: <p> The account ID of the event data store owner. </p>

    Raises:
        capo_cloudtrail.errors.conflict_exception.ConflictException: <p>This exception is thrown when the specified resource is not ready for an operation. This can occur when you try to run an operation on a resource before CloudTrail has time to fully load the resource, or because another operation is modifying the resource. If this exception occurs, wait a few minutes, and then try the operation again.</p>
        capo_cloudtrail.errors.event_data_store_arn_invalid_exception.EventDataStoreARNInvalidException: <p>The specified event data store ARN is not valid or does not map to an event data store in your account.</p>
        capo_cloudtrail.errors.event_data_store_not_found_exception.EventDataStoreNotFoundException: <p>The specified event data store was not found.</p>
        capo_cloudtrail.errors.inactive_event_data_store_exception.InactiveEventDataStoreException: <p>The event data store is inactive.</p>
        capo_cloudtrail.errors.inactive_query_exception.InactiveQueryException: <p>The specified query cannot be canceled because it is in the <code>FINISHED</code>, <code>FAILED</code>, <code>TIMED_OUT</code>, or <code>CANCELLED</code> state.</p>
        capo_cloudtrail.errors.invalid_parameter_exception.InvalidParameterException: <p>The request includes a parameter that is not valid.</p>
        capo_cloudtrail.errors.no_management_account_slr_exists_exception.NoManagementAccountSLRExistsException: <p> This exception is thrown when the management account does not have a service-linked role. </p>
        capo_cloudtrail.errors.operation_not_permitted_exception.OperationNotPermittedException: <p>This exception is thrown when the requested operation is not permitted.</p>
        capo_cloudtrail.errors.query_id_not_found_exception.QueryIdNotFoundException: <p>The query ID does not exist or does not map to a query.</p>
        capo_cloudtrail.errors.unsupported_operation_exception.UnsupportedOperationException: <p>This exception is thrown when the requested operation is not supported.</p>
        capo_cloudtrail.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudtrail.types.cancel_query_request.CancelQueryRequest]",
    ) -> OperationResponse[
        "capo_cloudtrail.types.cancel_query_response.CancelQueryResponse"
    ]:
        import capo_cloudtrail._operations.cloud_trail_20131101.cancel_query

        output, http_response = (
            capo_cloudtrail._operations.cloud_trail_20131101.cancel_query.cancel_query(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CancelQuery")
    )
    input_: capo_cloudtrail.types.cancel_query_request.CancelQueryRequest = {
        "query_id": query_id
    }
    if event_data_store is not None:
        input_["event_data_store"] = event_data_store
    if event_data_store_owner_account_id is not None:
        input_["event_data_store_owner_account_id"] = (
            event_data_store_owner_account_id
        )

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