i have a cloud function which gets triggered when data is inserted into a specific BigQuery table (event type – google.cloud.bigquery.v2.JobService.InsertJob). My requirement is to get this “row data” into the cloud function logic.
cloud event(input to function) has details about event type. This has details like project id, dataset id, table etc. But it doesn’t have the actual data that was inserted. Not sure if insert id or something from this log can be used to get the actual data that was inserted.
sample cloud event data:
{‘attributes’: {‘specversion’: ‘1.0’, ‘id’: ‘projects/GCP_project_id/logs/cloudaudit.googleapis.com%2Fdata_access-p8u2s9e59ouj1718902358732636’, ‘source’: ‘//cloudaudit.googleapis.com/projects/GCP_project_id/logs/data_access’, ‘type’: ‘google.cloud.audit.log.v1.written’, ‘datacontenttype’: ‘application/json; charset=utf-8’, ‘dataschema’: ‘https://googleapis.github.io/google-cloudevents/jsonschema/google/events/cloud/audit/v1/LogEntryData.json’, ‘subject’: ‘bigquery.googleapis.com/projects/GCP_project_id/datasets/BQ_Dataset_name/tables/BQ_Table_name’, ‘time’: ‘2024-06-20T16:52:39.469382553Z’, ‘recordedtime’: ‘2024-06-20T16:52:38.732636Z’, ‘methodname’: ‘google.cloud.bigquery.v2.JobService.InsertJob’, ‘resourcename’: ‘projects/GCP_project_id/datasets/BQ_Dataset_name/tables/BQ_Table_name’, ‘servicename’: ‘bigquery.googleapis.com’}, ‘data’: {‘@type’: ‘type.googleapis.com/google.events.cloud.audit.v1.LogEntryData’, ‘protoPayload’: {‘status’: {}, ‘authenticationInfo’: {‘principalEmail’: ‘[email protected]’}, ‘requestMetadata’: {‘callerIp’: ‘29.285.100.0’, ‘callerSuppliedUserAgent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36,gzip(gfe),gzip(gfe)’, ‘requestAttributes’: {}, ‘destinationAttributes’: {}}, ‘serviceName’: ‘bigquery.googleapis.com’, ‘methodName’: ‘google.cloud.bigquery.v2.JobService.InsertJob’, ‘authorizationInfo’: [{‘resource’: ‘projects/GCP_project_id/datasets/BQ_Dataset_name/tables/BQ_Table_name’, ‘permission’: ‘bigquery.tables.getData’, ‘granted’: True, ‘resourceAttributes’: {}}], ‘resourceName’: ‘projects/GCP_project_id/datasets/BQ_Dataset_name/tables/BQ_Table_name’, ‘serviceData’: {}, ‘metadata’: {‘tableDataRead’: {‘jobName’: ‘projects/GCP_project_id/jobs/bquxjob_24008bd9_19066907743’, ‘reason’: ‘JOB’}, ‘@type’: ‘type.googleapis.com/google.cloud.audit.BigQueryAuditMetadata’}}, ‘insertId’: ‘-p0u2j8e59auj’, ‘resource’: {‘type’: ‘bigquery_dataset’, ‘labels’: {‘dataset_id’: ‘BQ_Dataset_name’, ‘project_id’: ‘GCP_project_id’}}, ‘timestamp’: ‘2024-06-20T16:52:38.732636Z’, ‘severity’: ‘INFO’, ‘logName’: ‘projects/GCP_project_id/logs/cloudaudit.googleapis.com%2Fdata_access’, ‘receiveTimestamp’: ‘2024-06-20T16:52:39.469382553Z’}}
Need help with solution or any alternative to this. Thanks in advance.
user25652088 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.