Google Cloud Storage
Google Cloud Storage is the object storage service provided by Google Cloud Platform. It offers scalable and globally distributed storage for a variety of use cases. Here are the key features and details of Google Cloud Storage:
- Multi-regional and regional buckets: Google Cloud Storage provides the flexibility to choose between multi-regional and regional storage buckets. Multi-regional buckets offer high availability and low-latency access across multiple regions, while regional buckets focus on a specific region for cost optimization.
- Data transfer and network performance: Google Cloud Storage leverages Google’s global network infrastructure to provide fast and efficient data transfer. It offers options such as Transfer Service for on-premises data migration and Direct Peering for optimized network performance.
- Life cycle management: Google Cloud Storage includes life cycle management capabilities that allow users to automatically transition data to different storage classes based on predefined rules. This feature helps optimize storage costs by moving data to more cost-effective storage tiers as it ages.
To set up Google Cloud Storage using the Cloud Shell utility in Google Cloud Platform, follow these steps:
- Access Google Cloud Shell: Go to the Google Cloud Console at https://console.cloud.google.com/ and click on the Activate Cloud Shell button in the top-right corner of the screen.
- Create a Google Cloud Storage bucket: In the Cloud Shell terminal, use the gsutil mb command to create a new Google Cloud Storage bucket. The syntax is as follows:
gsutil mb -l REGION gs://YOUR_BUCKET_NAME
- Replace REGION with the desired location for your bucket (for example, us-central1) and YOUR_BUCKET_NAME with a globally unique name for your bucket.
Here’s an example:
gsutil mb -l us-central1 gs://my-gcp-storage-bucket
- Set access control for the bucket (optional):
By default, newly created buckets have private access. If you want to make your bucket publicly readable, you can set the ACL using the gsutil command:
gsutil defacl set public-read gs://YOUR_BUCKET_NAME
This command sets the default ACL for the bucket to allow public read access.
- Upload objects to the bucket: You can use the gsutil cp command to upload files or objects to your bucket. The syntax is as follows:
gsutil cp LOCAL_FILE_PATH gs://YOUR_BUCKET_NAME
Replace LOCAL_FILE_PATH with the path of the file you want to upload and YOUR_BUCKET_NAME with the name of your bucket.
Here’s an example:
gsutil cp my_file.txt gs://my-gcp-storage-bucket
- View the bucket’s contents: To see the contents of your bucket, use the gsutil ls command:
gsutil ls gs://YOUR_BUCKET_NAME
Here’s an example:
gsutil ls gs://my-gcp-storage-bucket
- Download objects from the bucket: You can also download objects from the bucket to your Cloud Shell environment using the gsutil cp command:
gsutil cp gs://YOUR_BUCKET_NAME/REMOTE_FILE_PATH LOCAL_DESTINATION_PATH
Replace REMOTE_FILE_PATH with the path of the file in your bucket and LOCAL_DESTINATION_PATH with the path where you want to save the file in Cloud Shell.
Here’s an example:
gsutil cp gs://my-gcp-storage-bucket/my_file.txt ~/Downloads/
That’s it! You’ve now set up Google Cloud Storage and performed basic operations with your bucket using the Cloud Shell utility. Remember to replace YOUR_BUCKET_NAME and REGION with your preferred values throughout the commands.