0
0
GcpHow-ToBeginner · 3 min read

How to Create a Bucket in Google Cloud Storage

To create a bucket in Google Cloud Storage, use the gcloud storage buckets create command followed by your bucket name and location. This command sets up a new storage container where you can save your files securely.
📐

Syntax

The basic command to create a bucket is:

gcloud storage buckets create BUCKET_NAME --location=LOCATION

Here:

  • BUCKET_NAME is the unique name you choose for your bucket.
  • --location specifies the geographic region where your bucket will be stored.
bash
gcloud storage buckets create BUCKET_NAME --location=LOCATION
💻

Example

This example creates a bucket named my-sample-bucket-123 in the us-central1 region.

bash
gcloud storage buckets create my-sample-bucket-123 --location=us-central1
Output
Created bucket [my-sample-bucket-123].
⚠️

Common Pitfalls

Common mistakes when creating buckets include:

  • Using a bucket name that is already taken globally. Bucket names must be unique across all users.
  • Not specifying a location, which may cause the command to fail or create the bucket in an undesired region.
  • Using invalid characters in the bucket name. Only lowercase letters, numbers, dashes (-), underscores (_), and dots (.) are allowed.
bash
Wrong:
gcloud storage buckets create MyBucket --location=us-central1

Right:
gcloud storage buckets create my-bucket --location=us-central1
📊

Quick Reference

OptionDescription
BUCKET_NAMEUnique name for your bucket, lowercase, numbers, dashes, underscores, dots
--locationRegion where the bucket data is stored (e.g., us-central1, europe-west1)
--projectOptional: specify the GCP project if not set by default
--helpShow help for the command

Key Takeaways

Use the gcloud CLI command 'gcloud storage buckets create' with a unique bucket name and location.
Bucket names must be globally unique and follow naming rules with lowercase letters and allowed symbols.
Always specify the location to control where your data is stored and reduce latency.
Check for errors about name conflicts or invalid characters to avoid creation failure.