Created
April 25, 2018 03:04
-
-
Save justinnaldzin/160df79a0579d264f8edb632fdbc259c to your computer and use it in GitHub Desktop.
Define Google Cloud Storage bucket (create bucket if it doesn't exist)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import storage | |
# Define Google Cloud Storage bucket | |
storage_client = storage.Client() | |
bucket = storage_client.lookup_bucket(bucket_name) | |
if bucket: | |
print("Using bucket '{}'.".format(bucket.name)) | |
else: | |
# Create Google Cloud Storage bucket if it doesn't exist | |
print("Bucket '{}' doesn't exist. Creating bucket...".format(bucket_name)) | |
bucket = storage_client.create_bucket(bucket_name) | |
print("Using bucket '{}'.".format(bucket.name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment