GCS Bucket Operations and Lifecycle
Beginner8 min
Create Cloud Storage buckets, upload and download objects, configure lifecycle rules, and manage access controls.
Prerequisites
- -gcloud CLI installed
- -GCP project with billing enabled
Steps
1
Create a bucket
Creates a regional bucket with standard storage class.
$ gcloud storage buckets create gs://my-unique-bucket-name --location us-central1 --default-storage-class standard
Bucket names are globally unique. Use your project ID as a prefix to avoid conflicts.
2
Upload files
Uploads all CSV files from the local data directory to the imports/ prefix in the bucket.
$ gcloud storage cp ./data/*.csv gs://my-unique-bucket-name/imports/
3
List objects
Lists objects with size, storage class, and creation time.
$ gcloud storage ls gs://my-unique-bucket-name/imports/ --long
4
Download objects
Downloads a specific object to a local directory.
$ gcloud storage cp gs://my-unique-bucket-name/imports/report.csv ./downloads/
5
Set a lifecycle rule
Applies lifecycle rules such as automatically deleting objects older than 90 days or transitioning to Nearline storage.
$ gcloud storage buckets update gs://my-unique-bucket-name --lifecycle-file=lifecycle.json
Create a lifecycle.json with rules like: {"rule": [{"action": {"type": "Delete"}, "condition": {"age": 90}}]}
Full Script
FAQ
Discussion
Loading comments...