Используйте эту основу в качестве отправной точки:
def hello_pubsub(event, context):
if 'data' in event:
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
print(pubsub_message)
// Your custom data
tableId = pubsub_message['requestMetadata']['serviceData']['tableInsertRequest']['resource']['tableName']['tableId']
datasetId = pubsub_message['requestMetadata']['serviceData']['tableInsertRequest']['resource']['tableName']['datasetId']
Декодируйте JSON из комментариев снизу (нижняя часть отсутствует):
MY-MESSAGE: {
"insertId":"-cr1b1ae1x199",
"logName":" logs/cloudaudit.googleapis.com%2Factivity",
"protoPayload":{
"@type":"type.googleapis.com/google.cloud.audit.AuditLog",
"authenticationInfo":{
"principalEmail":"xxx"
},
"authorizationInfo":[{
"granted":true,
"permission":"bigquery.tables.create",
"resource":"xxx"
}],
"methodName":"tableservice.insert",
"requestMetadata":{
"callerIp":"x",
"callerSuppliedUserAgent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/x Safari/537.36,gzip(gfe)"},
"resourceName":"x",
serviceData"":{
"@type":"type.googleapis.com/google.cloud.bigquery.logging.v1.AuditData",
"tableInsertRequest":{
"resource":{
"info":{},
"schemaJson":"{\n}",
"tableName":{
"datasetId":"citi_dev_gcp",
"projectId":"x",
"tableId":"outputCheck"
},
"view":{}
}
},
"tableInsertResponse":{
"resource":{
"createTime":"2019-06-20T18:42:21.106Z",
"expireTime":"2019-07-20T18:42:21.106Z",
"info":{},
"schemaJson":"{\n}",
"tableName":{
"datasetId":"name",
"projectId":"x",
"tableId":"outputCheck"
},
"updateTime":"2019-06-20T18:42:21.151Z",
"view":{}
}
}
},
"serviceName":"bigquery.googleapis.com","status":{}
},
"receiveTimestamp":