Learn to use Google Cloud SDK: Command-Line Tools & Libraries

  1. Home
  2. Google
  3. Learn to use Google Cloud SDK: Command-Line Tools & Libraries
Learn to use Google Cloud SDK: Command-Line Tools & Libraries

In cloud computing, using an object storage service is frequently the first option. It has advantages, such as simplicity of use and low operating overhead, which are very tempting to cloud consumers. The object storage service in Google Cloud is supplied by the appropriately called Google Cloud SDK. Let us look in detail at how to use the Google Cloud SDK: Command-Line Tools and Libraries for Google Cloud.

Overview of Cloud SDK

Google Cloud SDK is a set of command-line tools developed by Google to manage resources and services in the Google Cloud Platform (GCP). It provides a consistent and easy-to-use interface for interacting with GCP services from the command line, making it an ideal tool for developers, administrators, and other users who need to manage GCP resources on a regular basis.

The Google Cloud SDK includes several useful tools, such as the Cloud SDK command-line interface, which enables users to interact with GCP services and resources; the Cloud SDK emulator, which enables developers to test and debug their applications locally before deploying them to GCP; and the Cloud SDK APIs, which provide programmatic access to GCP services and resources.

What Is Object Storage?

Files are simply referred to as objects in object storage and arranged into buckets—logical namespaces that may store one or more objects. While a bucket can contain several objects, an object can only be associated with one bucket. Google Cloud Storage is the name of Google Cloud’s object storage service. Google Cloud Storage has options for managing and automating bucket lifecycle rules.

Cloud Storage | Google Cloud
Image source – Google

The availability of data in Google Cloud Storage may be adjusted by selecting a storage class for the bucket and its objects: Standard, Nearline, and Coldline. Furthermore, the data location may be defined, which affects availability, by selecting between region, dual-region, and multi-region. Google Cloud Storage has options for managing and automating bucket lifecycle rules.

Different Ways to Interact with Google Cloud Platform

It has never been simpler to use cloud computing services. The variety of tools and ways available to interact with these materials is beneficial to a wide range of consumers. There are three primary techniques available in Google Cloud Platform:

Google Cloud Console

When working with Google Cloud, the most common method is to use the Console, often known as the Web User Interface. It reduces the barrier for entry-level users to begin using GCP while yet providing a comprehensive set of capabilities and an easy UI. It is worth noting, however, that not all functionalities are available via the Console—users may sometimes need to utilize the SDK or command-line tool to execute specific activities.

SDK

A Software Development Kit, or SDK, is frequently the preferred method for apps to communicate with Google Cloud. Google Cloud provides SDKs for a variety of programming languages, including Go, Python, and node.js.

While Google Cloud’s command-line tools are technically part of the SDK, they are frequently referred to independently. GCP includes a single command-line interface; gcloud, that can be used to communicate with any GCP service. In addition, Google Cloud Storage provides its command-line utility called gsutil. This tool allows the consumer to engage with GCP by utilizing all of the available functionalities.

How to Use the gsutil Command-Line Tool?

In this part, we’ll look at how the gsutil command-line utility works in practice. This tool may assist with the transfer of multiple items, including folders; and is also ideally suitable for automating processes that are difficult to accomplish using the Google Cloud Console.

Learn to Set Up a Workspace with Google Cloud Tools
  • Begin by entering into the Google Cloud Console (the online user interface) and creating a new Google Cloud Platform project with billing enabled and setup.
  • Furthermore, Get the most recent version of Google Cloud SDK from the official documentation page and install it. The installation method may differ slightly depending on your machine’s operating system, but it should be very simple in general.
  • Additionally, Open your computer terminal and run the command gsutil -v to confirm that the installation was successful. The version of gsutil installed on your PC will be shown (Fig. 1). If this is not the case, please return to steps 1 and 2 before continuing.
  • You must first authenticate gsutil with your Google Cloud Platform account before you can use it. When you run the command gcloud auth login; you will be to your browser to authenticate. When the procedure is complete, your email address and current GCP project will be present in the terminal.
Steps to create a Google Cloud Storage Bucket with gsutil

The first step is to create a Google Cloud Storage bucket before uploading any files (i.e. objects) to Google Cloud Storage. The bucket serves as a virtual namespace for our objects, and as you may recall, an item may only belong to one bucket at a time.

Quickstart: Using the Console | Cloud Storage | Google Cloud
Image source – Google

1. Run the command gsutil help MB from your system terminal (Fig. 2.). This help command will show you the syntax for the MB (create bucket) option. With any of the gsutil options, you may use the help command, which is a fantastic resource for giving information and thorough explanations on all the essential and optional flags.

GCP Bucket using gsutil

2. As you can see from the above output, creating a Google Cloud Storage bucket is pretty straightforward. Create it with the command gsutil MB gs:/YOUR BUCKET NAME>. You must ensure that YOUR BUCKET NAME> is a unique name not only in your GCP account but also across the whole Google Cloud Platform.

Step for Adding/Removing Data from a Google Storage Bucket with gsutil

The procedure of uploading and withdrawing data from a Google storage bucket is straightforward and quick, with the only possible stumbling block being the speed of your internet connection. If you’re used to using the terminal, you’re probably acquainted with the commands cp (copy) and rm (delete) (remove). A similar idea is in use by the Google Cloud Storage command-line utility gsutil.

  • Begin by setting the directory to the folder on your local system containing the files you wish to upload.
  • We will use the command gsutil cp * gs:/YOUR BUCKET NAME> to copy all of the files in the current directory to the storage bucket we previously constructed. One thing to keep in mind is that when uploading numerous big files, adding the flag -m to do a parallel (multi-threaded/multi-processing) copy will considerably increase performance. In addition, if you want to include local subfolders in your upload, you must use the parameter -r, which means you must execute a recursive copy.
  • Additionally, You can check that the files were correctly generate by running gsutil ls gs:/YOUR BUCKET NAME> ; and listing the contents of the bucket.
  • Similarly, if you want to remove the objects from the storage bucket, use the command gsutil rm gs:/YOUR BUCKET NAME>/* to delete all the files included within the bucket. Clean up the environment by removing the Cloud Storage bucket you created using the rb (remove bucket) subcommand, i.e., gsutil rb gs:/YOUR BUCKET NAME>.

Cloud API Client Libraries

If you are a programmer who prefers to work using a programming language, Google Cloud has provided another option to use GCP. Google Cloud includes seven Client API libraries. You may create a visually appealing dashboard for your AWS and GCP cloud workloads. API Client Libraries come with extensive documentation and code samples in each language. Here’s a link to Java Sample – JAVA SAMPLE

If none of the samples supplied have a service implementation for a certain API, you can develop your own using Google APIs.

Security and Privacy Considerations

Last but not least, using Google Cloud SDK on your local workstation may raise certain security concerns for you. To avoid data leaking; gsutil guarantees that all data passes through the TLS protocol. There are several safeguards in place to guarantee security while performing these commands on your local/dev system.

Expert’s Corner

Google Cloud SDK is a powerful and flexible tool for managing GCP resources and is essential for anyone working with GCP services and applications.. However, you’ve now learned how to use Google Cloud Platform’s console, command-line tools, and SDKs. There’s a lot more on Google Cloud and Google Cloud Storage now that you know how to install and authenticate with Google Cloud using your machine console.

Menu