Files
data-management/exchange/load/exchange_load_function.py
T
Yam ZhengLim 2738b8bd82 enclose debug
2022-10-01 12:08:19 +08:00

22 lines
756 B
Python

from google.cloud import storage
import boto3
def login_cloudstorage_credential(credential):
try:
storage_client = storage.Client.from_service_account_json(credential)
return storage_client
except Exception as e:
print(e)
print("[FUNCTION_ERROR]-login_cloudstorage_credential")
return False
def upload_to_bucket(storage_client, blob_name, file_path):
try:
exchange_bucket = storage_client.get_bucket('exchange_bucket_raw')
blob = exchange_bucket.blob(blob_name)
blob.upload_from_filename(file_path)
return print("[Upload Complete]",file_path)
except Exception as e:
print(e)
print("[FUNCTION_ERROR]-upload_to_bucket",blob_name)
return False