DEV Community

Srinivasulu Paranduru
Srinivasulu Paranduru

Posted on

Google Cloud Storage - Labs - Step by step

Cloud Storage - Your Inifinitely Scalable Object Store

Table of Contents

  1. Creating an Cloud Storage Bucket
  2. Access control lists
  3. Enable lifecycle management
  4. Enable versioning

Creating an Cloud Storage Bucket

1.In the Google Cloud console, in the Navigation menu (Navigation menu icon), click Cloud Storage > Buckets.

Note :A bucket must have a globally unique name.

2.Create
3.Specify the following, and leave the remaining settings as their defaults:

  • Name : Enter a globally unique name
  • Location type : Region
  • Region : Select Region
  • Enforce public access prevention on this bucket : unchecked
  • Access control : Fine-grained 4.Make a note of the bucket name. It will be used later in this lab and referred to as [BUCKET_NAME]. 5.Click Create.

Download a sample file using CURL and make two copies

1.In the Cloud console, click Activate Cloud Shell
2.If prompted, click Continue.
3.Store [BUCKET_NAME] in an environment variable:

export BUCKET_NAME=<enter bucket name here>

4.Verify it with echo:

echo $BUCKET_NAME

5.Run the following command to download a sample file (this sample file is a publicly available Hadoop documentation HTML file):


curl \
https://hadoop.apache.org/docs/current/\
hadoop-project-dist/hadoop-common/\
ClusterSetup.html > setup.html
Enter fullscreen mode Exit fullscreen mode

6.To make copies of the file, run the following commands:


cp setup.html setup2.html
cp setup.html setup3.html
Enter fullscreen mode Exit fullscreen mode

Access control lists

Task 2: Access control lists (ACLs)

You set access control lists to restrict access to the file that you copy to the Cloud Storage bucket.

Copy the file to the bucket and configure the access control list

1.Run the following command to copy the first file to the bucket:

gcloud storage cp setup.html gs://$BUCKET_NAME/

Enter fullscreen mode Exit fullscreen mode

2.To get the default access list that's been assigned to setup.html, run the following command:

gsutil acl get gs://$BUCKET_NAME/setup.html  > acl.txt
cat acl.txt
Enter fullscreen mode Exit fullscreen mode

3.To set the access list to private and verify the results, run the following commands:


gsutil acl set private gs://$BUCKET_NAME/setup.html
gsutil acl get gs://$BUCKET_NAME/setup.html  > acl2.txt
cat acl2.txt
Enter fullscreen mode Exit fullscreen mode

4.To update the access list to make the file publicly readable, run the following commands:


gsutil acl ch -u AllUsers:R gs://$BUCKET_NAME/setup.html
gsutil acl get gs://$BUCKET_NAME/setup.html  > acl3.txt
cat acl3.txt
Enter fullscreen mode Exit fullscreen mode

Enable lifecycle management

Task 3: Enable lifecycle management

In this task, you enable lifecycle management for a Cloud Storage bucket to automate the deletion of objects after a specified period.

View the current lifecycle policy for the bucket

  • Run the following command to view the current lifecycle policy:

gsutil lifecycle get gs://$BUCKET_NAME
Enter fullscreen mode Exit fullscreen mode

Note: There is no lifecycle configuration. You create one in the next steps.

Create a JSON lifecycle policy file

1.To create a file named life.json, run the following command:

nano life.json

2.Paste the following value into the life.json file:


{
  "rule":
  [
    {
      "action": {"type": "Delete"},
      "condition": {"age": 31}
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Note: These instructions tell Cloud Storage to delete the object after 31 days.

3.Press Ctrl+O, ENTER to save the file, and then press Ctrl+X to exit nano.

Set the policy and verify

1.To set the policy, run the following command:

gsutil lifecycle set life.json gs://$BUCKET_NAME

2.To verify the policy, run the following command:

gsutil lifecycle get gs://$BUCKET_NAME

Enable versioning

Task 4 : Enable Versioning

In this task, you enable versioning for a Cloud Storage bucket to protect data from accidental deletion or modification.

View the versioning status for the bucket and enable versioning

1.Run the following command to view the current versioning status for the bucket:

gsutil versioning get gs://$BUCKET_NAME

2.To enable versioning, run the following command:

gsutil versioning set on gs://$BUCKET_NAME

3.To verify that versioning was enabled, run the following command:

gsutil versioning get gs://$BUCKET_NAME

💬 If you enjoyed reading this blog post and found it informative, please take a moment to share your thoughts by leaving a review and liking it 😀 and follow me in dev.to , linkedin, github

Top comments (0)