-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreate_CloudStorage_Bucket.py
26 lines (21 loc) · 1.04 KB
/
Create_CloudStorage_Bucket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from google.cloud import storage
from google.cloud.storage import Bucket
def create_bucket(bucket_name, project='cloudscore20240120', location='US'):
"""
Creates a new bucket in Google Cloud Storage.
Parameters:
bucket_name (str): The name of the bucket to create.
project (str, optional): The ID of the GCP project in which to create the bucket. If not set, defaults to the project set in the environment.
location (str, optional): The location in which to create the bucket. Defaults to 'US'.
Returns:
Bucket: The created bucket.
"""
storage_client = storage.Client(project=project)
bucket = storage_client.bucket(bucket_name)
new_bucket = storage_client.create_bucket(bucket, location=location)
print(f"Bucket {new_bucket.name} created in {new_bucket.location} with storage class {new_bucket.storage_class}")
return new_bucket
if __name__ == "__main__":
bucket_name = input("Enter the name for the new bucket: ")
# Optionally you can also input project and location
create_bucket(bucket_name)