Google Cloud Platform is a cloud-based computing platform that offers a variety of services for businesses and individuals, including computing, storage, and big data analytics.
In this blog, I will be diving into the process of creating a Google Cloud Platform (GCP) account and getting familiar with the gcloud command-line interface (CLI).
7. Click New Project in the upper right. The New Project view displays.
8. Enter a friendly name for your project in the Project name field.
9. Google Cloud Platform generates a corresponding project ID below the Project name field, as the following example shows:
10. You can change the generated project ID by clicking Edit, but the project ID must be unique.
11. Take note of the project ID. You will use it later in this setup process. NOTE: After you create the project, you cannot change the project ID.
12. In the Billing account field, select the account that you will use to pay for your project.
13. In the Location field, select a folder for your project. Folders are an optional part of the Google Cloud Platform project resource tree. Click Create.
14. Google Cloud Platform creates your new project.
Google Cloud services offer a wide range of tools and services for managing data and computing resources. Two popular command-line tools for interacting with these services are gsutil and gcloud. While they may seem similar, these two tools serve different purposes.
Let’s take a closer look at the key differences between gsutil and gcloud.
Which One to Use?
Deciding between gsutil and gcloud depends on your specific needs. If you only need to manage data in GCS, then gsutil is the way to go. It provides a more focused set of commands specifically for GCS. On the other hand, if you need to manage resources across multiple Google Cloud services, then gcloud is the better choice. It provides a more comprehensive set of commands and a consistent interface across multiple services.
Now that you’ve installed the Google Cloud SDK and authenticated your account, let’s look at some of the most commonly used gcloud CLI commands.
gcloud auth login: Create account in google cloud. Returns a URL. Access & login
gcloud auth list : Once you logged into the gcloud account. The auth token will be stored in the system.
gcloud config set project <project-id> : To configure a project gcloud config get project
gcloud compute instances list: This command lists all of the virtual machine instances in your project.
gcloud compute instances create <instance-name>: This command creates a new virtual machine instance with the specified name.
gcloud compute ssh <instance-name>: This command opens an SSH connection to a virtual machine instance.
gcloud compute firewall-rules create <firewall-rule-name>: This command creates a new firewall rule in your project.
gcloud compute disk create <disk-name>: This command creates a new disk in your project.
gcloud compute images list: This command lists all of the images in your project.
gcloud compute snapshots list: This command lists all of the snapshots in your project.
Uploading Files to GCS
One of the most common tasks you’ll perform with gsutil is uploading files to GCS. To upload a file to GCS, simply run the following command:
gsutil cp <file-path> gs://<bucket-name>/<object-name>
Where <file-path> is the path to the file you want to upload, <bucket-name> is the name of the bucket you want to upload the file to, and <object-name> is the name you want to give the file in GCS.
For example, to upload a file named file.txt to a bucket named my-bucket with the object name file.txt, you would run the following command:
gsutil cp file.txt gs://my-bucket/file.txt
Downloading Files from GCS
In addition to uploading files, you can also download files from GCS with gsutil. To download a file from GCS, simply run the following command:
gsutil cp gs://<bucket-name>/<object-name> <file-path>
Where <bucket-name> is the name of the bucket the file is stored in, <object-name> is the name of the file in GCS, and <file-path> is the path where you want to save the file.
For example, to download a file named file.txt from a bucket named my-bucket, you would run the following command:
gsutil cp gs://my-bucket/file.txt file.txt
Managing Buckets and Objects
In addition to uploading and downloading files, gsutil provides several commands for managing buckets and objects in GCS.
The gcloud CLI and gsutil are powerful tool that makes it easy to interact with GCP services from the command line. gsutil is a specialized tool for interacting with Google Cloud Storage, while gcloud is a general-purpose tool for interacting with multiple Google Cloud services. If you're only working with GCS, gsutil is likely the better choice. But if you're working with multiple Google Cloud services, gcloud may be a more convenient choice.