Checkpoints
Create a bucket
/ 25
Upload objects to your bucket
/ 25
Make objects public
/ 25
Delete your bucket
/ 25
Using gsutil to Perform Operations on Buckets and Objects
- GSP130
- Overview
- Setup
- Task 1. Working with buckets and objects
- Task 2. Create a bucket
- Task 3. Upload objects to your bucket
- Task 4. List objects
- Task 5. Sync changes with bucket
- Task 6. Make objects public
- Task 7. Copy with different storage class
- Task 8. Check storage classes
- Task 9. Delete your bucket
- Congratulations!
- End your lab
GSP130
Overview
In this lab, you will use gsutil
to create a bucket and perform operations on objects. gsutil
is a Python application that lets you access Cloud Storage from the command line. The gsutil
tool has commands such as mb
and cp
to perform operations. Each command has a set of options that are used to customize settings further.
What you'll learn to do
- Create a bucket
- Copy files from a local folder to a bucket
- Synchronize the contents of the local folder with the contents of the bucket
- Change access control permissions on objects
- Delete a bucket.
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 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.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
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 the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
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 Google Cloud console opens in this tab.
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.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
- In Cloud Shell session execute the following command to download sample data for this lab from a git repository:
- Change to the blogs directory:
Task 1. Working with buckets and objects
- First, set some environment variables:
Task 2. Create a bucket
- Create a bucket and multi-regional storage class:
Click Check my progress to verify the objective.
Task 3. Upload objects to your bucket
- Run the following to copy the
endpointslambda
object to your bucket:
Click Check my progress to verify the objective.
If you have a large number of files to transfer, you might want to use the -m
option, to perform a parallel (multi-threaded/multi-processing) copy for faster performance. The -r
option allows gsutil to recurse through directories.
Task 4. List objects
- To list objects in your bucket, execute the following command:
Task 5. Sync changes with bucket
- Use the following commands to rename and delete some files:
- Now synchronize the local changes with the bucket:
In this command, the -d
option deletes files from the target if they're missing in the source (in this case, it deletes app.yaml from the bucket). The -r
option runs the command recursively on directories.
- To verify that the bucket is now in sync with your local changes, list the files in the bucket again:
Task 6. Make objects public
- To allow public access to all files under the
endpointslambda
folder in your bucket, execute the following command:
Click Check my progress to verify the objective.
- To confirm files are viewable by the public, open the following link in a new incognito or private browser window, replacing
<your-bucket-name>
with the full name of your bucket, not the environment variable:
This URL uses the Cloud Storage API link to view the object without authentication. Learn more about accessing public data from the Accessing public data documentation.
Task 7. Copy with different storage class
- Next, copy a file with Nearline storage class instead of the bucket's default Multi-regional storage class:
Task 8. Check storage classes
- Run the following to check the storage classes and view other detailed information about the objects in your bucket:
- Press the
space
key to continue viewing the rest of the command's output.
The output shows that the ghcn_on_bq.ipynb object has NEARLINE
storage class while the other objects have MULTI_REGIONAL
storage class.
Output:
- You can use Ctrl + c to return to the command line.
Task 9. Delete your bucket
- Before deleting a bucket, you must first delete all objects in the bucket. To delete all objects, execute the following command:
- Now delete the bucket:
Click Check my progress to verify the objective.
Congratulations!
You have now learned how to perform operations on Cloud Storage buckets and objects!
Next steps / Learn more
For complete information about the gsutil command-line options, see:
- How-to Guides
- gsutil commands under gsutil Tool
End your lab
When you have completed your lab, click End Lab. Your account and the resources you've used are removed from the lab platform.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
- 1 star = Very dissatisfied
- 2 stars = Dissatisfied
- 3 stars = Neutral
- 4 stars = Satisfied
- 5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Manual Last Updated November 04, 2024
Lab Last Tested November 04, 2024
Copyright 2024 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.