This page describes how to create buckets with hierarchical namespace enabled.
Create a bucket
This section describes how to create a bucket with hierarchical namespace enabled.
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information and then click Continue:
- In the Get started section, do the following:
- Enter a globally unique bucket name that meets the bucket name requirements.
- To enable hierarchical namespace, click the
expander arrow to expand the Optimize for file oriented and data-intensive workloads section, and then select Enable Hierarchical namespace on this bucket.
Note: You cannot enable hierarchical namespace in an existing bucket.
- Optional: To add a bucket label, click the
expander arrow to expand the Labels section, and then click
add_box Add
label, and specify a
key
and avalue
for your label. - In the Choose where to store your data section, do the following:
- Select Region as the Location type.
- In the Location list, select a region where the bucket data will be permanently stored.
- In the Choose a storage class for your data section, select
Set a default class for the bucket.
Note: The Monthly cost estimate panel in the right pane estimates the bucket's monthly costs based on your selected storage class and location, as well as your expected data size and operations.
- In the Choose how to control access to objects section, select whether or not your bucket
enforces public access prevention, and
for Access control, choose
Uniform.
Note: If public access prevention is already enforced by your project's organization policy, the Prevent public access toggle is locked.
- In the Choose how to protect object data section, do the following:
- Optional: Select a Data protection method such as configuring a custom soft delete policy, object versioning, or a retention policy.
- To select a Data encryption method, click the expander arrow labeled Data encryption.
- Click Create.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, see Troubleshooting.
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 storage buckets create
command:gcloud 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. You cannot enable hierarchical namespace in an existing 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 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 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 client libraries.
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 client libraries.
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 client libraries.
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 client libraries.
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 client libraries.
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 client libraries.
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 client libraries.
REST APIs
JSON API
Have gcloud CLI installed and initialized, which lets you generate an access token for 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. You cannot enable hierarchical namespace in an existing bucket.uniformBucketLevelAccess.enabled
is set toTRUE
to enable uniform bucket-level access 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
.
- Use
{ "name": "BUCKET_NAME", "location": "BUCKET_LOCATION", "storageClass": "STORAGE_CLASS", "hierarchicalNamespace": { "enabled": "BOOLEAN" }, "iamConfiguration": { "uniformBucketLevelAccess": { "enabled": true }, }, }
Where:
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.
- List and delete buckets.
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