Google Cloud Storage Basics: Buckets, Objects, and Access Control
Introduction
Cloud Storage is Google Cloud's object storage service for files of any size. Like S3 and Blob Storage, it stores objects in buckets with global names and scales without planning. This lesson uses the current gcloud storage commands to create a bucket, move files, understand access control, and clean up.
Prerequisites
- gcloud initialized with a project (previous lesson)
- Billing enabled on the project
Step-by-Step Guide
Step 1: Understand buckets, objects, and classes
A bucket is a container with a globally unique name, a location, and a default storage class, and an object is a file stored in it. Storage classes such as Standard, Nearline, Coldline, and Archive trade lower storage cost for higher retrieval cost and minimum storage periods, so use colder classes only for data you rarely read. Bucket names can use lowercase letters, numbers, dashes, underscores, and dots.
Step 2: Create a bucket
Choose a unique name and a location. Uniform bucket-level access makes IAM the only access control for the bucket, which is simpler and is the recommended model compared with per-object ACLs.
gcloud storage buckets create gs://my-unique-bucket-12345 \
--location=us-central1 \
--uniform-bucket-level-accessStep 3: Upload, list, and download
Use gcloud storage rather than the older gsutil tool, which Google describes as legacy. cp copies files in either direction and ls lists buckets and objects.
echo "hello cloud" > hello.txt
gcloud storage cp hello.txt gs://my-unique-bucket-12345/
gcloud storage ls gs://my-unique-bucket-12345/
gcloud storage cp gs://my-unique-bucket-12345/hello.txt downloaded.txtStep 4: Control who can access it
Buckets are private by default. Grant access by adding an IAM binding for a specific principal and a narrow role, such as Storage Object Viewer to let an application read objects. Avoid granting access to all users unless public hosting is a deliberate decision, and prefer short-lived signed URLs for temporary sharing.
gcloud storage buckets add-iam-policy-binding gs://my-unique-bucket-12345 \
--member="user:someone@example.com" \
--role="roles/storage.objectViewer"Step 5: Clean up
Remove the objects and the bucket so nothing keeps billing. The recursive remove command deletes everything in the bucket and the bucket itself, so confirm the name first.
gcloud storage rm --recursive gs://my-unique-bucket-12345FAQs
- How is Cloud Storage different from S3 and Blob Storage?
- The model is the same: global bucket names, objects, storage classes, and IAM-based access. The commands and some terminology differ, which is why the earlier lessons map equivalent concepts.
- Why use uniform bucket-level access?
- It removes per-object ACLs so access is managed in one place with IAM, which makes permissions easier to understand and audit.
Summary
Create buckets with uniform bucket-level access, move files with gcloud storage cp and ls, grant narrow IAM roles, and remove test buckets when finished. The same ideas apply across all three major clouds.
Related tutorials
- Google Cloud Getting Started: Projects, IAM, and the gcloud CLI
- Azure Blob Storage Basics: Accounts, Containers, and Secure Access
- Azure Getting Started: Subscriptions, Resource Groups, and the Azure CLI
- Amazon S3 Basics: Buckets, Objects, Versioning, and Safe Sharing
- AWS Getting Started: Secure Your Account, Set Up Access, and Use the CLI
Comments
Log in or create a free account to join the discussion.