Changing the Default Storage Class of a Bucket in GCP

Change Storage Class Bucket in GCP
This tutorial focuses on the steps to change the default storage class of a bucket in the Google Cloud Platform.

 

Google Cloud Platform (GCP) is a set of cloud computing services offered by Google. GCP is a public platform that offers IT resources, such as storage, compute, database, Big Data, application development tools, networking, and more. The GCP services run on the same cloud infrastructure that Google internally uses to run its end-user products, such as Google Photos, Gmail, Google Search, Google Drive, YouTube, etc. Software engineers, IT professionals, and cloud administrators can access the services provided by Google Cloud Platform over the Internet or a dedicated network connection.

 

Buckets are the primary containers that hold user data in Google Cloud. Every data stored in Cloud Storage must be contained in a bucket. Users can also use buckets to control and organize their data; unlike directories and folders, they can’t nest buckets. Since there are some limits to creating and deleting buckets in Google Cloud, users should design their storage applications to favor intensive object operations and relatively few buckets operations.

 

While creating a bucket, the user should specify a globally unique name, a default storage class, and a geographic location where the bucket and its contents are stored. The default storage class that the user chooses applies to objects added to the bucket that doesn’t have a storage class specified explicitly.

 

If the user didn’t specify a location and storage class in their request, buckets are created with a default storage class of Standard Storage in the US multi-region. After creating a bucket, the user can always change its default storage class to any class supported in that bucket’s location. However, the user needs to delete and re-create the bucket if they want to change the bucket name and location.  

 

Changing the Default Storage Class

 When the user uploads an object to the bucket, the object is assigned the bucket’s default storage class if they do not specify a storage class for the object. If the user wants to change the default storage class of a bucket in Google Cloud Platform, follow the below process:

 

Via Google Cloud Console

To change the default storage class of a bucket via Google Cloud Console, follow the below steps: 

  • Login to the Google Cloud Console and go to the Cloud Storage Browser page.
  • Find the bucket you want to modify in the bucket list and click its Bucket overflow menu ().
  • Next, click the Edit default storage class button.
  • Select the new default storage class that the user would like for their bucket in the overlay window.
  • Finally, click the Save button.

 

Via Command Line Interface 

To change the default storage class of a bucket via Google Cloud CLI, follow the below step: 

  • Execute the following gsutil defstorageclass set command: 

 

gsutil defstorageclass set STORAGE_CLASS gs://BUCKET_NAME

 

 

In the above command, the:

  • STORAGE_CLASS is the new storage class that the user wants for their bucket, such as nearline.
  • BUCKET_NAME is the name of the relevant bucket, such as test-bucket.

 

For example: 

gsutil defstorageclass set nearline gs://test-bucket
Setting default storage class to "nearline" for bucket gs://test-bucket

 

Via REST API – JSON API

To change the default storage class of a bucket using JSON API, follow the below steps: 

1. First, get an authorization access token from the OAuth 2.0 Playground and configure the playground to use the user’s OAuth credentials.

2. Then, create a .json file that contains the following information:

 

{
  "storageClass": "STORAGE_CLASS"
}

 

In the above file, replace STORAGE_CLASS with the new storage class that the user wants for their bucket.

 

3. Finally, use cURL to call the JSON API with a PATCH Bucket request:

 

curl -X PATCH --data-binary @JSON_FILE_NAME.json \
  -H "Authorization: Bearer OAUTH2_TOKEN" \
  -H "Content-Type: application/json" \
  "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=storageClass"

 

Where: 

  • JSON_FILE_NAME is the name of the JSON file that we created in step 2.
  • OAUTH2_TOKEN is the access token we generated in step 1. 
  • BUCKET_NAME is the name of the relevant bucket, such as test-bucket.

 

Via REST API – XML API

To change the default storage class of a bucket using XML API, follow the below steps: 

1. First, get an authorization access token from the OAuth 2.0 Playground and configure the playground to use the user’s OAuth credentials.

2. Then, create a .xml file that contains the following information:

 

<StorageClass>STORAGE_CLASS</StorageClass>

 

In the above file, replace STORAGE_CLASS with the new storage class that the user wants for their bucket, such as nearline.

3. Finally, use cURL to call the XML API with a PUT Bucket request:

 

curl -X PUT --data-binary @XML_FILE_NAME.xml \
  -H "Authorization: Bearer OAUTH2_TOKEN" \
  "https://storage.googleapis.com/BUCKET_NAME?storageClass"

 

Where: 

  • XML_FILE_NAME is the name of the XML file that we created in step 2.
  • OAUTH2_TOKEN is the access token we generated in step 1. 
  • BUCKET_NAME is the name of the relevant bucket, such as test-bucket.

 

Conclusion 

This tutorial presents the steps to change the default storage class of a bucket in the GCP using the Google Cloud Console, command-line interface, and REST API. Hope this tutorial was helpful, and do reach out to us if you have any query or suggestions.

Share this post

Services to Explore

Stay up to date!

Stay up to date with the Web Hosting, Cloud and Server Management Industry News and Tutorials!

We will send you only the relevant emails, and we respect your privacy. Please review our privacy policy for more info.

Managed Google Cloud Services

Focus on your business, and let us take care of your Google Cloud Infrastructure!
From what you are reading, it seems you are interested in Google Cloud and related technologies. If you have a moment to spare, please take a look at our Managed GCP Services, and which might interest you even more!
Managed Google Cloud

Value-Added Services

We have services that can help you run a successful business. With us, you don't have to worry about these areas because our experts will take care of it for you.

Introducing - WPHealers!

Complete WordPress Management, 24x7 Support & White Label Agency Plans!

WordPress migration service, security, white-label reseller services and lot more! Grab the introductory deals now!

WPHealers

ServerHealers uses cookies.