menu
arrow_back

Cloud Storage: Qwik Start - CLI/SDK

search favorite_border
Add to favorites
help
Help
—/100

Checkpoints

arrow_forward

Create a GCS Bucket

Copy an object to a folder in the bucket (ada.jpg)

Make your object publicly accessible

Cloud Storage: Qwik Start - CLI/SDK

30 minutes Free

GSP074

Google Cloud Self-Paced Labs

Overview

Cloud Storage allows world-wide storage and retrieval of any amount of data at any time. You can use Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.

In this hands-on lab you will learn how to create a storage bucket, upload objects to it, create folders and subfolders in it, and make objects publicly accessible using the Google Cloud command line.

Throughout this lab you'll be able to verify your work in the Console by going to Navigation menu > Storage. You'll just need to refresh your browser after each command is run to see the new items you've created.

Setup and Requirements

Qwiklabs setup

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.

This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.

What you need

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
  • Time to complete the lab.

Note: If you already have your own personal Google Cloud account or project, do not use it for this lab.

Note: If you are using a Pixelbook, open an Incognito window to run this lab.

How to start your lab and sign in to the Google Cloud Console

  1. Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.

    Open Google Console

  2. Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.

    Sign in

    Tip: Open the tabs in separate windows, side-by-side.

  3. In the Sign in page, paste the username that you copied from the Connection Details panel. Then copy and paste the password.

    Important: You must use the credentials from the Connection Details panel. Do not use your Qwiklabs credentials. If you have your own Google Cloud account, do not use it for this lab (avoids incurring charges).

  4. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Cloud Console opens in this tab.

The Google Cloud Shell

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

In the Cloud Console, in the top right toolbar, click the Activate Cloud Shell button.

Cloud Shell icon

Click Continue.

cloudshell_continue.png

It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:

Cloud Shell Terminal

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

You can list the active account name with this command:

gcloud auth list

(Output)

Credentialed accounts:
 - <myaccount>@<mydomain>.com (active)

(Example output)

Credentialed accounts:
 - google1623327_student@qwiklabs.net

You can list the project ID with this command:

gcloud config list project

(Output)

[core]
project = <project_ID>

(Example output)

[core]
project = qwiklabs-gcp-44776a13dea667a6

Create a bucket

Run the gsutil mb command and replace with a unique name to create a bucket:

gsutil mb gs://YOUR-BUCKET-NAME/

Bucket naming rules:

  • Do not include sensitive information in the bucket name, because the bucket namespace is global and publicly visible.
  • Bucket names must contain only lowercase letters, numbers, dashes (-), underscores (_), and dots (.). Names containing dots require verification.
  • Bucket names must start and end with a number or letter.
  • Bucket names must contain 3 to 63 characters. Names containing dots can contain up to 222 characters, but each dot-separated component can be no longer than 63 characters.
  • Bucket names cannot be represented as an IP address in dotted-decimal notation (for example, 192.168.5.4).
  • Bucket names cannot begin with the "goog" prefix.
  • Bucket names cannot contain "google" or close misspellings of "google".
  • Also, for DNS compliance and future compatibility, you should not use underscores (_) or have a period adjacent to another period or dash. For example, ".." or "-." or ".-" are not valid in DNS names.

If successful, the command returns:

Creating gs://YOUR-BUCKET-NAME/...

You've just created a bucket where you can store your stuff!

Note: If the bucket name is already taken, either by you or someone else, the command returns:

Creating gs://YOUR-BUCKET-NAME/... ServiceException: 409 Bucket YOUR-BUCKET-NAME already exists.

Try again with a different bucket name.

Test Completed Task

Click Check my progress to verify your performed task. If you successfully created Cloud Storage bucket, you will see an assessment score.

Create a cloud storage bucket.

Test your Understanding

Below are a multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.

Upload an object into your bucket

Now upload an object into a bucket.

First, download this image to a temporary instance (ada.jpg) in Cloud Shell:

wget --output-document ada.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Ada_Lovelace_portrait.jpg/800px-Ada_Lovelace_portrait.jpg

Use the gsutil cp command to upload the image from the location where you saved it to the bucket you created:

gsutil cp ada.jpg gs://YOUR-BUCKET-NAME
Tip: When typing your bucket name, you can use the tab key to autocomplete it.

You can see the image load into your bucket from the command line. You've just stored an object in your bucket!

Now remove the downloaded image:

rm ada.jpg

Download an object from your bucket

Use the gsutil cp command to download the image you stored in your bucket to Cloud Shell:

gsutil cp -r gs://YOUR-BUCKET-NAME/ada.jpg .

If successful, the command returns:

Copying gs://YOUR-BUCKET-NAME/ada.jpg...
/ [1 files][299.6 KiB/299.6 KiB]
Operation completed over 1 objects/299.6 KiB.

You've just downloaded the image from your bucket.

Copy an object to a folder in the bucket

Use the gsutil cp command to create a folder called image-folder and copy the image (ada.jpg) into it:

gsutil cp gs://YOUR-BUCKET-NAME/ada.jpg gs://YOUR-BUCKET-NAME/image-folder/
Note: Folders in Cloud Storage have limitations compared to local file systems, but many of the same operations are supported.

If successful, the command returns:

Copying gs://YOUR-BUCKET-NAME/ada.jpg [Content-Type=image/png]...
- [1 files] [ 299.6 KiB/ 299.6 KiB]
Operation completed over 1 objects/299.6 KiB

Now the image file has been copied into a new folder in your bucket.

Test Completed Task

Click Check my progress to verify your performed task. If you have successfully uploaded object in folder over cloud storage, you will see an assessment score.

Copy an object to a folder in the bucket (ada.jpg).

List contents of a bucket or folder

Use the gsutil ls command to list the contents of the bucket:

gsutil ls gs://YOUR-BUCKET-NAME

If successful, the command returns a message similar to:

gs://YOUR-BUCKET-NAME/ada.jpg
gs://YOUR-BUCKET-NAME/image-folder/

That's everything currently in your bucket.

List details for an object

Use the gsutil ls command, with the -l flag to get some details about the image file you uploaded to your bucket:

gsutil ls -l gs://YOUR-BUCKET-NAME/ada.jpg

If successful, the command returns a message similar to:

306768  2017-12-26T16:07:570Z  gs://YOUR-BUCKET-NAME/ada.jpg
TOTAL: 1 objects, 30678 bytes (299.58 KiB)

Now you know the image's size and date of creation.

Make your object publicly accessible

Use the gsutil acl ch command to grant all users read permission for the object stored in your bucket:

gsutil acl ch -u AllUsers:R gs://YOUR-BUCKET-NAME/ada.jpg

If successful, the command returns:

Updated ACL on gs://YOUR-BUCKET-NAME/ada.jpg

Your image is now public, and can be made available to anyone.

Test Completed Task

Click Check my progress to verify your performed task. If you have successfully shared object from storage bucket, you will see an assessment score.

Make your object publicly accessible

Validate that your image is publicly available. Go to Navigation menu > Storage, then click on the name of your bucket. You should see your image with the Public link box. Click the Copy URL and open the URL in a new browser tab.

Who are you looking at? This is Ada Lovelace, credited with being the first computer programmer. She worked with mathematician and computer pioneer Charles Babbage, who proposed the Analytical Engine. Her interest in the Analytical Engine lead to translating a paper on the machine by Italian mathematician Luigi Menabrea, adding her own extensive annotations. These notes are considered the first computer program - an algorithm designed to be carried out by the machine. She developed a vision of the capability of computers, going beyond number crunching, and examined how individuals and society relate to technology as a collaborative tool. Citation: Ada Lovelace, https://commons.wikimedia.org/w/index.php?title=Ada_Lovelace&oldid=176490980 (last visited December 6, 2017).

Test your Understanding

Below are a multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.

Remove public access

To remove this permission, use the command:

gsutil acl ch -d AllUsers gs://YOUR-BUCKET-NAME/ada.jpg

If successful, the command returns:

Updated ACL on gs://YOUR-BUCKET-NAME/ada.jpg

You have removed public access to this object. You can verify this by clicking the Refresh button in the Console. The checkmark will be removed. If you reload the page with the image, you will now get an error.

Test your Understanding

Below are a multiple choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.

Delete objects

Use the gsutil rm command to delete an object - the image file in your bucket:

gsutil rm gs://YOUR-BUCKET-NAME/ada.jpg

If successful, the command returns:

Removing gs://YOUR-BUCKET-NAME/ada.jpg...

Refresh the Console. The copy of the image file is no longer stored on Cloud Storage (though the copy you made in the image-folder/ folder still exists).

Congratulations!

baseline_infra_quest_icon.png

Finish Your Quest

Continue your Quest with Baseline: Infrastructure. A Quest is a series of related labs that form a learning path. Completing this Quest earns you the badge above, to recognize your achievement. You can make your badge (or badges) public and link to them in your online resume or social media account. Enroll in this Quest and get immediate completion credit if you've taken this lab. See other available Qwiklabs Quests.

Next Steps / Learn More

This lab is also part of a series of labs called Qwik Starts. These labs are designed to give you a little taste of the many features available with Google Cloud. Search for "Qwik Starts" in the lab catalog to find the next lab you'd like to take!

Google Cloud Training & Certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated September 29, 2020
Lab Last Tested September 29, 2020

Copyright 2021 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.