Reputation: 1684
I'm running a Python 3.6 application within docker und would like to store the output file directly in a GCS bucket. What sounds obvious to me doing following within the docker image:
gcloud compute scp
to the bucketBut, how can I copy the file without switching to another venv?
Upvotes: 1
Views: 1568
Reputation: 1684
Solution - create file gcpupload.py
from google.cloud import storage
def main():
client = storage.Client()
bucket = client.get_bucket('my_bucket')
blob = bucket.blob('myfile.txt')
blob.upload_from_filename(filename='/path/myfile.txt')
if __name__ == "__main__":
main()
Run the script:
#!/bin/sh
# Need to create the api keys file through google cloud console
# API's and services -> credentials -> service account key
export GOOGLE_APPLICATION_CREDENTIALS=google-api-keys.json
python gcpupload.py
Upvotes: 2
Reputation: 17803
you can store the file to GCS from your Python application or from a 2nd Python script, this is very easy - https://pypi.python.org/pypi/google-cloud-storage
Upvotes: 0