This page describes how to create, list, and delete buckets with hierarchical namespace enabled.
Create a bucket
This section describes how to create a bucket with hierarchical namespace enabled.
Command line
-
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, a Cloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
-
In your development environment, run the
gcloud alpha storage buckets create
command:gcloud alpha storage buckets create gs://BUCKET_NAME --location=BUCKET_LOCATION --uniform-bucket-level-access --enable-hierarchical-namespace
Where:
BUCKET_NAME
is the name you want to give your bucket, subject to naming requirements. For example,my-bucket
.BUCKET_LOCATION
is the location of your bucket. For example,us-east1
.--uniform-bucket-level-access
: Enable uniform bucket-level access for the bucket.
--enable-hierarchical-namespace
: Enable hierarchical namespace for the bucket.
If the request is successful, the command returns the following message:
Creating gs://BUCKET_NAME/...
Set the following flags to have greater control over the creation of your bucket:
--project
: Specify the project ID or project number that your bucket will be associated with. For example,my-project
.--default-storage-class
: Specify the default storage class of your bucket. For example,STANDARD
.
For a complete list of options for creating buckets using the Google Cloud CLI, see
buckets create
options.For example:
gcloud alpha storage buckets create gs://BUCKET_NAME --project=PROJECT_ID --default-storage-class=STORAGE_CLASS --location=BUCKET_LOCATION --uniform-bucket-level-access
Client Libraries
C++
For more information, see the Cloud Storage C++ API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
For more information, see the Cloud Storage Go API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
For more information, see the Cloud Storage Java API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
For more information, see the Cloud Storage Node.js API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
For more information, see the Cloud Storage PHP API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
For more information, see the Cloud Storage Python API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Ruby
For more information, see the Cloud Storage Ruby API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
REST APIs
JSON API
Have gcloud CLI installed and initialized, in order to generate an access token for the
Authorization
header.Alternatively, you can create an access token using the OAuth 2.0 Playground and include it in the
Authorization
header.- Create a JSON file that contains the settings for the bucket, which must include a
name
for the bucket. See the Buckets:Insert documentation for a complete list of settings. The following are common settings to include: BUCKET_NAME
is the name you want to give your bucket, subject to naming requirements. For example,my-bucket
.BUCKET_LOCATION
is the location where you want to store your bucket's object data. For example,US-EAST1
.STORAGE_CLASS
is the default storage class of your bucket. For example,STANDARD
.hierarchicalNamespace.enabled
is set toTRUE
to enable hierarchical namespace for your bucket.- Use
cURL
to call the JSON API:curl -X POST --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/b?project=PROJECT_IDENTIFIER"
Where:
JSON_FILE_NAME
is name of the JSON file that contains the bucket settings.PROJECT_IDENTIFIER
is the ID or number of the project that your bucket will be associated with. For example,my-project
.
{ "name": "BUCKET_NAME", "location": "BUCKET_LOCATION", "storageClass": "STORAGE_CLASS", "hierarchicalNamespace": { "enabled": "BOOLEAN" }, }
Where:
List a bucket
Listing buckets with hierarchical namespace enabled uses the same process as listing a bucket without hierarchical namespace enabled. For instructions on listing buckets, see List buckets.
Delete a bucket
You can delete a bucket if it contains only empty folders and no objects or managed folders.
The process for deleting buckets with hierarchical namespace enabled is the same as deleting buckets without hierarchical namespace enabled. For instructions on deleting buckets, see Delete buckets.
What's next
- Get information about a bucket's metadata
- Get information about a bucket's storage layout
- Understand folders.
- Create and manage folders.
- Rename folders.
Try it for yourself
If you're new to Google Cloud, create an account to evaluate how Cloud Storage performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
Try Cloud Storage free