Skip to content

Instantly share code, notes, and snippets.

@makeittotop
Created March 23, 2015 11:55
Show Gist options
  • Save makeittotop/a3a611c9974d6380335e to your computer and use it in GitHub Desktop.
Save makeittotop/a3a611c9974d6380335e to your computer and use it in GitHub Desktop.
Create a bucket on google nearline if it doesn't already exist
#!/usr/bin/env python
import boto
import gcs_oauth2_boto_plugin
import os, sys
import shutil
import StringIO
import tempfile
import time
# URI scheme for Google Cloud Storage.
GOOGLE_STORAGE = 'gs'
# URI scheme for accessing local files.
LOCAL_FILE = 'file'
# Your project ID can be found at https://console.developers.google.com/
# If there is no domain for your project, then project_id = 'YOUR_PROJECT'
project_id = 'iron-atom-89306'
header_values = {"x-goog-project-id": project_id}
# If the default project is defined, call get_all_buckets() without arguments.
bucket = sys.argv[1]
for bucket in (sys.argv[1:]):
uri = boto.storage_uri(bucket, GOOGLE_STORAGE)
try:
uri.create_bucket(headers=header_values)
print 'Successfully created bucket "%s"' % bucket
except boto.exception.StorageCreateError, e:
print 'Failed to create bucket:', e.message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment