Working with Google Cloud Storage
Google Cloud Training Architect II in Content
Digital objects — images, videos, documents, etc. — are a key aspect of any type of computing, whether local or cloud-based. Cloud Storage is Google Cloud's central facility for storing and retrieving your binary objects and is therefore utilized by the vast majority of applications on the platform. In this hands-on lab, you’ll gain practical experience in creating and managing the primary component of Cloud Storage, the bucket, as well as manipulating the objects it holds, through both the Google Cloud console and the command line.
Working with Google Cloud Storage
In this hands-on lab, we’ll create and manage the primary component of Cloud Storage — the bucket — as well as manipulate the objects it holds through both the Google Cloud console and the command line.
Before starting, download the diagram from the course downloads page, and store it in an easily accessible location.
How to Log in to Google Lab Accounts
On the lab page, right-click Open GCP Console and select the option to open it in a new private browser window (this option will read differently depending on your browser — e.g., in Chrome, it says "Open Link in Incognito Window"). Then, sign in to Google Cloud Platform using the credentials provided on the lab page.
On the Welcome to your new account screen, review the text, and click Accept. In the "Welcome L.A.!" pop-up once you're signed in, check to agree to the terms of service, choose your country of residence, and click Agree and Continue.
Working with Cloud Storage
Now, on to the lab!
- Navigate to APIs & Services > Library.
- Search for "cloud storage", select Google Cloud Storage, and make sure it's enabled.
Create a bucket.
- Navigate to Storage > Browser.
- Click Create Bucket.
- Name the bucket uniquely (e.g., "la-cs-001" with extra numbers or initials).
- Select an appropriate storage class (e.g., Regional).
- Click Create.
Add file to bucket.
- Click the bucket name to get into it.
- Drag and drop an image onto the interface.
- Click the name of the object in the bucket to verify.
Rename the object.
- From the object context menu (the three vertical dots on the right), choose Rename.
- Give the object a new name.
Share the object publicly.
- From the selected object's context menu, choose Edit permissions.
- Click + Add item, and set the following values:
- Entity: User
- Name: allUsers
- Access: Reader
- Click Save.
- Choose the Objects tab.
- Confirm the operation by clicking the new link under Public access.
Create a folder.
- On the bucket page, click Create folder.
- Name the folder (e.g., "artwork") and click Create.
- Click the folder name to get into it, and then click the Permissions tab.
- Click Add members, and set the following values:
- Members: allUsers
- Roles: Storage Object Viewer
- Click Add.
Upload folder of files.
Click the Activate Cloud Shell icon in the upper right navigation bar.
Clone a repo:
git clone https://github.com/linuxacademy/content-gcpro-developer
Change directory to the repo:
Download all files in folder from repo:
cloudshell dl cloud-functions-lab/*
Create a new folder on your desktop, and place all files within it.
In the console, choose Upload folder, and select the new folder on your desktop. Click Upload.
Perform Cloud Storage operations via command line.
In the Cloud Shell,
Copy file to bucket:
gsutil cp main.py gs://&lt;BUCKET_NAME>
List contents of bucket:
gsutil ls gs://&lt;BUCKET_NAME>
Create a new bucket:
gsutil mb -c regional -l us-central1 gs://&lt;NEW_BUCKET_NAME>
Verify bucket was created:
Move a file into the new bucket:
gsutil cp main.py gs://&lt;NEW_BUCKET_NAME>
Make object publicly accessible:
gsutil acl ch -u AllUsers:R gs://&lt;NEW_BUCKET_NAME>/main.py
Copy a file from another project's bucket:
gsutil cp gs://la-gcloud-course-resources/pro-developer/pinehead-meme.jpg gs://&lt;NEW_BUCKET_NAME>
Congratulations on completing this lab!