Google Cloud · lesson 4 of 10
Cloud Storage Fundamentals
Create a bucket, upload and download objects with gcloud storage, and compare storage classes with real per-GB pricing and retrieval costs.
By SkillByExample · Published
Cloud Storage is GCP’s object store — buckets holding objects, billed by class, region, and how long data sits before it’s touched again. This lesson creates a bucket, moves data in and out of it, and compares what four storage classes actually cost for the same data.
Creating a bucket
gcloud storage buckets create gs://skillbyexample-assets-437219 \
--location=us-central1 \
--default-storage-class=STANDARD \
--uniform-bucket-level-access
Creating gs://skillbyexample-assets-437219/...
--uniform-bucket-level-access disables per-object ACLs in favor of IAM-only permissions —
Google’s recommended default since per-object ACLs are the more common source of an
accidentally-public bucket.
Uploading and downloading
echo "lesson data" > notes.txt
gcloud storage cp notes.txt gs://skillbyexample-assets-437219/notes.txt
gcloud storage ls gs://skillbyexample-assets-437219/
Copying file://notes.txt to gs://skillbyexample-assets-437219/notes.txt
Completed files 1/1 | 12.0B/12.0B
gs://skillbyexample-assets-437219/notes.txt
rm notes.txt
gcloud storage cp gs://skillbyexample-assets-437219/notes.txt ./notes-downloaded.txt
cat notes-downloaded.txt
Copying gs://skillbyexample-assets-437219/notes.txt to file://notes-downloaded.txt
Completed files 1/1 | 12.0B/12.0B
lesson data
cp works symmetrically in both directions — the only signal of direction is which side of the
command has the gs:// prefix.
Inspecting object metadata
gcloud storage objects describe gs://skillbyexample-assets-437219/notes.txt \
--format="table(name,size,storageClass,contentType,etag)"
NAME SIZE STORAGE_CLASS CONTENT_TYPE ETAG
notes.txt 12 STANDARD text/plain CJqZ9Ky3+YYDEAE=
Comparing storage classes on the same object
Set the same object’s class explicitly and inspect the pricing tradeoff — these are Cloud
Storage’s published per-GB-month prices for us-central1 at time of writing:
Class Storage $/GB-month Retrieval $/GB Min. duration
Standard $0.020 $0.00 none
Nearline $0.010 $0.01 30 days
Coldline $0.004 $0.02 90 days
Archive $0.0012 $0.05 365 days
For 100 GB stored a full month and read back once:
Standard: 100 * 0.020 + 100 * 0.00 = $2.00
Nearline: 100 * 0.010 + 100 * 0.01 = $2.00
Coldline: 100 * 0.004 + 100 * 0.02 = $2.40
Archive: 100 * 0.0012 + 100 * 0.05 = $5.12
Storage-only, Archive is 16x cheaper than Standard. The moment you read the data back even once, Coldline and Archive both end up more expensive than Standard for this workload — the classes only pay off for data that’s genuinely rarely read.
gcloud storage objects update gs://skillbyexample-assets-437219/notes.txt \
--storage-class=NEARLINE
Updating gs://skillbyexample-assets-437219/notes.txt...
Practice
1. Set a lifecycle rule that moves objects to Coldline after 90 days automatically.
cat > lifecycle.json <<'EOF'
{
"rule": [
{
"action": {"type": "SetStorageClass", "storageClass": "COLDLINE"},
"condition": {"age": 90}
}
]
}
EOF
gcloud storage buckets update gs://skillbyexample-assets-437219 \
--lifecycle-file=lifecycle.json
Updating gs://skillbyexample-assets-437219/...
Lifecycle rules are the standard way to apply the storage-class math automatically instead of manually reclassifying objects by hand as they age.
2. Try to delete a Nearline object one day after creating it and see the early-deletion charge reflected in cost, not in the delete command's output.
gcloud storage rm gs://skillbyexample-assets-437219/notes.txt
Removing gs://skillbyexample-assets-437219/notes.txt...
The delete itself always succeeds silently — the early-deletion fee (29 remaining days of Nearline’s 30-day minimum, billed as if the object were still stored) shows up on the next invoice, not in the CLI, which is why it’s easy to miss until the bill arrives.
3. Make one object in the bucket publicly readable and fetch it with plain curl.
gcloud storage objects update gs://skillbyexample-assets-437219/notes.txt \
--add-acl-grant=entity=allUsers,role=READER
curl -s https://storage.googleapis.com/skillbyexample-assets-437219/notes.txt
ERROR: (gcloud.storage.objects.update) HTTPError 400: Cannot insert legacy ACL for an object when uniform bucket-level access is enabled.
This bucket was created with --uniform-bucket-level-access, which blocks per-object ACLs
entirely — public access here would have to be granted at the bucket level with
allUsers:objectViewer via IAM instead, a deliberately more visible operation.
4. List objects with their storage class to confirm the earlier update took effect.
gcloud storage ls -L gs://skillbyexample-assets-437219/notes.txt | grep -i "storage class"
Storage class: NEARLINE
5. Delete the bucket and everything in it in one command.
gcloud storage rm --recursive gs://skillbyexample-assets-437219
Removing gs://skillbyexample-assets-437219/notes.txt...
Removing gs://skillbyexample-assets-437219/...
--recursive on a bucket URL (no trailing object path) deletes every object first, then the
bucket itself — without it, rm refuses to delete a non-empty bucket.
Next: VPC networking — subnets, firewall rules, and why a VM with a public IP still can’t reach the internet.