Cloud & AI Analytics

Create Google Cloud Storage Bucket Using CLI In Google Cloud Platform

This Blog deals with creating a GCS buckets using CLI in Google Cloud Platform Features Of Cloud Storage Key Terms…

you can refer on how to Create Google Cloud Storage Bucket Using UI/console In Google Cloud Platform here

  • Click on above icon and you can see shell similar to this opening up.
  • Using gsutil – command line for cloud storage buckets (Cloud Shell)  

Creating Google bucket using CLI

To set your Cloud Platform project in this session use “gcloud config set project [PROJECT_ID]”

  • gcloud config set project <project-id>
  • gsutil is the command line for Google Cloud Storage Buckets in GCP.
    • gsutil –help
  • To list all in console just use “ls”
  • Create a bucket
    • gsutil mb gs://demo02-bucket
  • NOTE: If bucket name already exists we will get error code 409. 409 A Cloud Storage bucket named ‘demo02-bucket’ already exists. Try another name.
  • Bucket names must be globally unique across all Google Cloud projects, including those outside of your organization.

Upload file from local to GCP cloud storage

  •   Click on Upload button and you can choose file to upload into GCP.
  • Here I selected health.json and patient.json file into Cloud storage from cloudshell.
  • The same how it looks in GCP UI.
  • Then to load the uploaded file into bucket created, follow below commands. To give global access to a file in a bucket
  • gsutil acl ch -u ALLUsers:R gs://demo02-bucket/patient.json
  • Copy data from one bucket to another bucket.
    • Error: AccessDeniedException: 403 Object ‘demo01-bucket/health.json’ is subject to bucket’s retention policy and cannot be deleted, overwritten or archived until 2021-09-30T02:01:14.331731-07:00
  • gsutil cp gs://demo01-bucket/* gs://demo02-bucket
  • NOTE: If retention policy is present in bucket, you are likely to face this error “Error: 403, subject to bucket’s retention policy and cannot be deleted, overwritten or archived until 2021-09-30T02:01:14.33”
  • How to enable version in gsutil
  • gsutil versioning get gs://demo01-bucket
  • NOTE: response: gs://demo01-bucket: Suspended (BadRequestException: 400 Bucket’s Versioning cannot be set for Bucket ‘demo01-bucket’ that has retention policy.)
  • Enabling the versioning in demo01-bucket
  • gsutil versioning set on gs://demo01-bucket
  • To list all the files in the bucket
  • gsutil ls gs://demo02-bucket
  • To list all hidden files in the bucket
  • gsutil ls -a gs://demo02-bucket
  • After enabling version in gs://demo02-bucket, Try running the command
  • gsutil cp gs://demo01-bucket/* gs://demo02-bucket
  • To list all the files in the bucket
  • gsutil ls -a gs://demo02-bucket

Share:

Leave a Comment

Your email address will not be published. Required fields are marked *