Create a BigQuery export configuration
Stay organized with collections
Save and categorize content based on your preferences.
Export findings from a project to a BigQuery dataset by creating an export configuration.
Code sample
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],[],[],[],null,["# Create a BigQuery export configuration\n\nExport findings from a project to a BigQuery dataset by creating an export configuration.\n\nCode sample\n-----------\n\n### Java\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.cloud.securitycenter.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.BigQueryExport.html;\n import com.google.cloud.securitycenter.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest.html;\n import com.google.cloud.securitycenter.v1.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html;\n import java.io.IOException;\n import java.util.UUID;\n\n public class CreateBigQueryExport {\n\n public static void main(String[] args) throws IOException {\n // TODO(Developer): Modify the following variable values.\n\n // parent: Use any one of the following resource paths:\n // - organizations/{organization_id}\n // - folders/{folder_id}\n // - projects/{project_id}\n String parent = String.format(\"projects/%s\", \"your-google-cloud-project-id\");\n\n // filter: Expression that defines the filter to apply across create/update events of findings.\n String filter =\n \"severity=\\\"LOW\\\" OR severity=\\\"MEDIUM\\\" AND \"\n + \"category=\\\"Persistence: IAM Anomalous Grant\\\" AND \"\n + \"-resource.type:\\\"compute\\\"\";\n\n // bigQueryDatasetId: The BigQuery dataset to write findings' updates to.\n String bigQueryDatasetId = \"your-bigquery-dataset-id\";\n\n // bigQueryExportId: Unique identifier provided by the client.\n // For more info, see:\n // https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to\n String bigQueryExportId = \"default-\" + UUID.randomUUID().toString().split(\"-\")[0];\n\n createBigQueryExport(parent, filter, bigQueryDatasetId, bigQueryExportId);\n }\n\n // Create export configuration to export findings from a project to a BigQuery dataset.\n // Optionally specify filter to export certain findings only.\n public static void createBigQueryExport(\n String parent, String filter, String bigQueryDatasetId, String bigQueryExportId)\n throws IOException {\n // Initialize client that will be used to send requests. This client only needs to be created\n // once, and can be reused for multiple requests. After completing all of your requests, call\n // the \"close\" method on the client to safely clean up any remaining background resources.\n try (https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html client = https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.SecurityCenterClient.html.create()) {\n\n // Create the BigQuery export configuration.\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.BigQueryExport.html bigQueryExport =\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.BigQueryExport.html.newBuilder()\n .setDescription(\n \"Export low and medium findings if the compute resource \"\n + \"has an IAM anomalous grant\")\n .setFilter(filter)\n .https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.BigQueryExport.Builder.html#com_google_cloud_securitycenter_v1_BigQueryExport_Builder_setDataset_java_lang_String_(String.format(\"%s/datasets/%s\", parent, bigQueryDatasetId))\n .build();\n\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest.html bigQueryExportRequest =\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest.html.newBuilder()\n .setParent(parent)\n .setBigQueryExport(bigQueryExport)\n .https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.CreateBigQueryExportRequest.Builder.html#com_google_cloud_securitycenter_v1_CreateBigQueryExportRequest_Builder_setBigQueryExportId_java_lang_String_(bigQueryExportId)\n .build();\n\n // Create the export request.\n https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.BigQueryExport.html response = client.createBigQueryExport(bigQueryExportRequest);\n\n System.out.printf(\"BigQuery export request created successfully: %s\\n\", response.https://cloud.google.com/java/docs/reference/google-cloud-securitycenter/latest/com.google.cloud.securitycenter.v1.BigQueryExport.html#com_google_cloud_securitycenter_v1_BigQueryExport_getName__());\n }\n }\n }\n\n### Python\n\n\nTo authenticate to Security Command Center, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n\n def create_bigquery_export(\n parent: str, export_filter: str, bigquery_dataset_id: str, bigquery_export_id: str\n ):\n from google.cloud import securitycenter\n\n \"\"\"\n Create export configuration to export findings from a project to a BigQuery dataset.\n Optionally specify filter to export certain findings only.\n\n Args:\n parent: Use any one of the following resource paths:\n - organizations/{organization_id}\n - folders/{folder_id}\n - projects/{project_id}\n export_filter: Expression that defines the filter to apply across create/update events of findings.\n bigquery_dataset_id: The BigQuery dataset to write findings' updates to.\n bigquery_export_id: Unique identifier provided by the client.\n - example id: f\"default-{str(uuid.uuid4()).split('-')[0]}\"\n For more info, see:\n https://cloud.google.com/security-command-center/docs/how-to-analyze-findings-in-big-query#export_findings_from_to\n \"\"\"\n client = securitycenter.SecurityCenterClient()\n\n # Create the BigQuery export configuration.\n bigquery_export = securitycenter.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.types.BigQueryExport.html()\n bigquery_export.description = \"Export low and medium findings if the compute resource has an IAM anomalous grant\"\n bigquery_export.filter = export_filter\n bigquery_export.dataset = f\"{parent}/datasets/{bigquery_dataset_id}\"\n\n request = securitycenter.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.types.CreateBigQueryExportRequest.html()\n request.parent = parent\n request.big_query_export = bigquery_export\n request.big_query_export_id = bigquery_export_id\n\n # Create the export request.\n response = client.https://cloud.google.com/python/docs/reference/securitycenter/latest/google.cloud.securitycenter_v1.services.security_center.SecurityCenterClient.html#google_cloud_securitycenter_v1_services_security_center_SecurityCenterClient_create_big_query_export(request)\n\n print(f\"BigQuery export request created successfully: {response.name}\\n\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=securitycenter)."]]