Cloud Storage Buckets
Globally named buckets, storage classes, and locations - and the gcloud storage commands to move files in and out.
On this page7 sections
Cloud Storage is Google Cloud's object storage. Files (objects) live in buckets and are addressed with gs:// URLs:
gs://learninx-demo-assets/images/logo.png
└ bucket └ object name
There are no real directories. images/ is just part of the object's name, which tools display as a folder.
Bucket names are global
Bucket names share one namespace across all of Google Cloud. If anyone, anywhere, already owns gs://backup, you cannot have it. Prefix names with something unique to you, such as your project ID. Names use lowercase letters, digits, dashes, underscores, and dots.
Locations
A bucket's location is fixed at creation:
- Region - one region, such as
us-central1. Lowest latency to compute in the same region. - Dual-region - two specific regions, for higher availability.
- Multi-region - a large area such as
USorEU, for content served widely.
If you leave out --location, gcloud storage buckets create uses the US multi-region.
Storage classes
All classes have the same eleven-nines (99.999999999%) annual durability and millisecond access. They differ in price, in how long you must keep data, and in retrieval fees:
| Class | Minimum storage duration | Designed for |
|---|---|---|
| Standard | None | Frequently accessed ("hot") data |
| Nearline | 30 days | Read about once a month or less |
| Coldline | 90 days | Read at most once a quarter |
| Archive | 365 days | Read less than once a year: backups, compliance |
Nearline, Coldline, and Archive charge a retrieval fee and bill the full minimum duration even if you delete early. Standard is the default class. Lifecycle rules can move objects to colder classes as they age, or delete them automatically.
Working with objects
gcloud storage is the current tool for Cloud Storage (the older gsutil is legacy):
gcloud storage buckets create gs://learninx-demo-assets --location=us-central1
gcloud storage cp report.csv gs://learninx-demo-assets/
gcloud storage ls gs://learninx-demo-assets
gcloud storage cp gs://learninx-demo-assets/report.csv ./restored.csv
gcloud storage rm gs://learninx-demo-assets/report.csv
Access control
Use uniform bucket-level access, so IAM roles on the bucket are the only access mechanism and per-object ACLs cannot quietly grant extra access. Grant the narrowest role that works, for example roles/storage.objectViewer for read-only. Keep public access prevention on unless a bucket must serve the public internet.
Try it
gcloud storage buckets create gs://backup
gcloud storage buckets create gs://learninx-demo-assets --location=us-central1
echo "hello, bucket" > hello.txt
gcloud storage cp hello.txt gs://learninx-demo-assets/
gcloud storage ls gs://learninx-demo-assets
gcloud storage cat gs://learninx-demo-assets/hello.txt
The first command fails on purpose: someone else already owns that name.
When you're ready, hit Mark complete and move to the next lesson.
Further reading
- Storage classes (opens in a new tab) - durations, availability, and retrieval fees for each class.
- gcloud storage buckets create (opens in a new tab) - every bucket option, including defaults.
- Bucket locations (opens in a new tab) - region, dual-region, and multi-region trade-offs.
Challenge
Create a bucket called gs://learninx-demo-assets in the us-central1 region.
Want to experiment first? Try things in the practice terminal (opens in a new tab), then enter the command that solves the task here.
Quiz
Lock in the concepts. Score at least 80% to mark the lesson complete.
Done with this one?
Skipped the challenge? You can mark the lesson complete by hand.