Close
bigquery

How To Cancel a BigQuery Data Transfer Run

So, you want to cancel a BigQuery Data Transfer scheduled run (because you might have accidently created it 😉 and you cannot see any option to delete a particular entry.

If you click DELETE at the top right, it will delete the whole configuration for that Data Transfer.

Unfortunately, it seems there is no easy way to do this via GCP web console. But it can be done with less than 10 lines of code.

You will need 2 details: your project id and the resource name for the scheduled run. Resource name for a scheduled run can be found by selecting it in the web console and right side panel will show it. Copy the whole string.

Replace these 2 details in the below code and run it.

from google.cloud import bigquery_datatransfer
client = bigquery_datatransfer.DataTransferServiceClient()
# TODO: Update to your project ID.
project_id = "{project_id}"
# TODO: Update to your resource name
resource_name = r"projects/{project-id}/locations/{location_id}/transferConfigs/{config_id}/runs/{run_id}"
info = client.delete_transfer_run(name=resource_name)
print("done")

You might also need to setup service account (having required permissions) key path in the environment variable before running the code which can be done by running below command. Replace the path to your key file accordingly.

export GOOGLE_APPLICATION_CREDENTIALS="/home/sur365/key.json"

and you are done!

Have something to say? Leave a comment!