Manage connections
This document describes how to view, list, share, edit, delete, and troubleshoot a BigQuery connection.
As a BigQuery administrator, you can create and manage connections that are used to connect to services and external data sources. BigQuery analysts use these connections to submit queries against external data sources without moving or copying data into BigQuery. You can create the following types of connections:
- Amazon S3 connections
- Apache Spark connections
- Blob Storage connections
- Cloud resource connections to connect to Cloud Storage data and to implement remote functions
- Spanner connections
- Cloud SQL connections
- AlloyDB connections
Before you begin
-
Ensure that you have a working connection. Connections are type-specific and depend on the connected external data source.
Enable the BigQuery Connection API.
Ensure that you can view a list of service accounts in your project. BigQuery creates and uses a service account to connect to your external data source. When you create a connection, a Google Cloud–managed Identity and Access Management (IAM) service account is created on your behalf. To view the service account attached to a particular connection, view the connection details.
Required roles
To get the permissions that you need to manage connections, ask your administrator to grant you the following IAM roles:
-
View connection details:
BigQuery Connection User (
roles/bigquery.connectionUser
) on your dataset -
List all connections:
BigQuery Connection User (
roles/bigquery.connectionUser
) on your dataset -
Share a connection:
BigQuery Connection Admin (
roles/bigquery.connectionAdmin
) on your connection -
Edit a connection:
BigQuery Connection Admin (
roles/bigquery.connectionAdmin
) on your connection -
Delete a connection:
BigQuery Connection Admin (
roles/bigquery.connectionAdmin
) on your connection
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
These predefined roles contain the permissions required to perform the tasks in this document. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
- View connection details:
bigquery.connections.get
- List all connections:
bigquery.connections.list
- Edit and delete a connection:
bigquery.connections.update
- Share a connection:
bigquery.connections.setIamPolicy
You might also be able to get these permissions with custom roles or other predefined roles.
List all connections
Select one of the following options:
Console
Go to the BigQuery page.
Connections are listed in your project, in a group called External connections.
In the Explorer pane, click your project name > External connections to see a list of all connections.
bq
Enter the bq ls
command and specify the --connection
flag. Optionally,
specify the --project_id
and --location
flags to identify the project
and location of the connections to be listed.
bq ls --connection --project_id=PROJECT_ID --location=REGION
Replace the following:
PROJECT_ID
: your Google Cloud project IDREGION
: the connection region
API
Use the projects.locations.connections.list
method
in the REST API reference section.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
View connection details
After you create a connection, you can get information about the connection's configuration. The configuration includes the values you supplied when you created the transfer.
Select one of the following options:
Console
Go to the BigQuery page.
Connection are listed in your project, in a group called External connections.
In the Explorer pane, click your project name > External connections > connection.
bq
Enter the bq show
command and specify the --connection
flag. Optionally,
qualify the connection ID with the project ID and region of the connection.
bq show --connection PROJECT_ID.REGION.CONNECTION_ID
Replace the following:
PROJECT_ID
: your Google Cloud project IDREGION
: the connection regionCONNECTION_I
: the connection ID
API
Use the
projects.locations.connections.get
method
in the REST API reference section.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Share a connection with users
You can grant the following roles to let users query data and manage connections:
roles/bigquery.connectionUser
: enables users to use connections to connect with external data sources and run queries on them.roles/bigquery.connectionAdmin
: enables users to manage connections.
For more information about IAM roles and permissions in BigQuery, see Predefined roles and permissions.
Select one of the following options:
Console
Go to the BigQuery page.
Connections are listed in your project, in a group called External connections.
In the Explorer pane, click your project name > External connections > connection.
In the Details pane, click Share to share a connection. Then do the following:
In the Connection permissions dialog, share the connection with other principals by adding or editing principals.
Click Save.
bq
You cannot share a connection with the bq command-line tool. To share a connection, use the Google Cloud console or the BigQuery Connections API method to share a connection.
API
Use the
projects.locations.connections.setIAM
method
in the BigQuery Connections REST API reference section, and
supply an instance of the policy
resource.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Edit a connection
A connection uses the credentials of the user who created it. If you need to change the user attached to a connection, you can update the user's credentials. This is useful if the user who created the connection is no longer with your organization.
You cannot edit the following elements of a connection:
- Connection type
- Connection ID
- Location
Select one of the following options:
Console
Go to the BigQuery page.
Connections are listed in your project, in a group called External connections.
In the Explorer pane, click your project name > External connections > connection.
In the Details pane, to edit details, click
Edit details. Then do the following:In the Edit connection dialog, edit the connection details including the user credentials.
Click Update connection.
bq
Enter the bq update
command and supply the connection flag:
--connection
. The fully qualified connection_id
is required.
bq update --connection --connection_type='CLOUD_SQL' --properties='{"instanceId" : "INSTANCE", "database" : "DATABASE", "type" : "MYSQL" }' --connection_credential='{"username":"USERNAME", "password":"PASSWORD"}' PROJECT.REGION.CONNECTION_ID
Replace the following:
INSTANCE
: the Cloud SQL instanceDATABASE
: the database nameUSERNAME
: the username of your Cloud SQL databasePASSWORD
: the password to your Cloud SQL databasePROJECT
: the Google Cloud project IDREGION
: the connection regionCONNECTION_ID
: the connection ID
For example, the following command updates the connection in a
project with the ID federation-test
and connection ID test-mysql
.
bq update --connection --connection_type='CLOUD_SQL' --properties='{"instanceId" : "federation-test:us-central1:new-mysql", "database" : "imdb2", "type" : "MYSQL" }' --connection_credential='{"username":"my_username", "password":"my_password"}' federation-test.us.test-mysql
API
See the
projects.locations.connections.patch
method
in the REST API reference section, and supply an instance of the connection
.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
Delete a connection
Select one of the following options:
Console
Go to the BigQuery page.
Connections are listed in your project, in a group called External connections.
In the Explorer pane, click your project name > External connections > connection.
In the Details pane, click
Delete to delete the connection.In the Delete connection? dialog, enter
delete
to confirm deletion.Click Delete.
bq
Enter the bq rm
command and supply the connection flag:
--connection
. The fully qualified connection_id
is required.
bq rm --connection PROJECT_ID.REGION.CONNECTION_ID
Replace the following:
PROJECT_ID
: your Google Cloud project IDREGION
: the connection regionCONNECTION_ID
: the connection ID
API
See the
projects.locations.connections.delete
method
in the REST API reference section.
Java
Before trying this sample, follow the Java setup instructions in the BigQuery quickstart using client libraries. For more information, see the BigQuery Java API reference documentation.
To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries.
What's next
- Learn how to use remote functions.
- Learn how to use stored procedures for Apache Spark.