Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Creating buckets and uploading objects
📖 Scenario: You are working on a cloud project where you need to store files safely. Google Cloud Storage lets you create buckets to hold your files (called objects). You will create a bucket and upload a file to it.
🎯 Goal: Build a Google Cloud Storage bucket and upload a text file into it using Python code.
📋 What You'll Learn
Create a bucket named exactly my-test-bucket-12345
Create a text file named hello.txt with content Hello, Cloud!
Upload the hello.txt file to the bucket
Use the Google Cloud Storage Python client library
💡 Why This Matters
🌍 Real World
Cloud storage buckets are used to store and organize files in the cloud for websites, apps, and backups.
💼 Career
Cloud engineers and developers often create and manage storage buckets and upload files programmatically for scalable cloud applications.
Progress0 / 4 steps
1
Create a bucket named my-test-bucket-12345
Write Python code to create a Google Cloud Storage bucket named my-test-bucket-12345 using the storage.Client() and client.create_bucket() methods.
GCP
Hint
Use storage.Client() to create a client, then call create_bucket() with the bucket name.
2
Create a text file named hello.txt with content Hello, Cloud!
Write Python code to create a file named hello.txt and write the text Hello, Cloud! into it.
GCP
Hint
Use Python's open() function with mode 'w' to write text to a file.
3
Upload the hello.txt file to the bucket
Write Python code to upload the local file hello.txt to the bucket my-test-bucket-12345 using the bucket.blob() and blob.upload_from_filename() methods.
GCP
Hint
Create a blob object with bucket.blob('hello.txt') and upload the file with upload_from_filename().
4
Set the bucket's default storage class to STANDARD
Write Python code to set the bucket's default storage class to STANDARD using the bucket.default_storage_class attribute and update the bucket with bucket.update().
GCP
Hint
Change the default_storage_class attribute and call patch() to apply changes.
Practice
(1/5)
1. What is the main purpose of creating a bucket in Google Cloud Storage?
easy
A. To manage user permissions
B. To organize and store files in the cloud
C. To create databases
D. To run virtual machines
Solution
Step 1: Understand what a bucket is
A bucket is a container in cloud storage used to hold files or objects.
Step 2: Identify the purpose of buckets
Buckets help organize and store files safely in the cloud for easy access and management.
Final Answer:
To organize and store files in the cloud -> Option B
Quick Check:
Bucket = Storage container [OK]
Hint: Buckets hold files in cloud storage, not run machines [OK]
Common Mistakes:
Confusing buckets with virtual machines
Thinking buckets create databases
Mixing buckets with user permission tools
2. Which command correctly creates a new bucket named my-bucket in Google Cloud Storage using the gcloud tool?
easy
A. gcloud storage buckets create my-bucket
B. gcloud create bucket my-bucket
C. gsutil mb gs://my-bucket
D. gcloud storage create-bucket my-bucket
Solution
Step 1: Recall the gcloud syntax for bucket creation
The correct syntax is gcloud storage buckets create [BUCKET_NAME].
Step 2: Match the command with the correct syntax
gcloud storage buckets create my-bucket matches the correct syntax exactly.
Final Answer:
gcloud storage buckets create my-bucket -> Option A
4. You tried to upload a file using gsutil cp myfile.txt gs://my-bucket/ but got an error saying the bucket does not exist. What is the most likely fix?
medium
A. Run the command with sudo
B. Rename the file to match the bucket name
C. Create the bucket first using gsutil mb gs://my-bucket
D. Delete the file and try again
Solution
Step 1: Understand the error cause
The error means the bucket my-bucket does not exist in cloud storage.
Step 2: Fix by creating the bucket
You must create the bucket first using gsutil mb gs://my-bucket before uploading files.
Final Answer:
Create the bucket first using gsutil mb gs://my-bucket -> Option C
Quick Check:
Bucket missing? Create it first [OK]
Hint: Create bucket before upload to avoid errors [OK]
Common Mistakes:
Trying to upload without bucket creation
Changing file name instead of bucket
Using sudo unnecessarily
5. You want to create a bucket named data-archive in the us-central1 region with versioning enabled to keep old versions of files. Which sequence of commands achieves this?
hard
A. gsutil mb -l us-central1 gs://data-archive && gsutil versioning set on gs://data-archive