Create buckets with hierarchical namespace enabled (original) (raw)
To get the permission that you need to create a bucket with hierarchical namespace enabled, ask your administrator to grant you theStorage Admin (roles/storage.admin) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the storage.buckets.create permission, which is required to create a bucket with hierarchical namespace enabled.
Console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
Go to Buckets - Click Create.
- On the Create a bucket page, enter your bucket information. After each of the following steps, click Continue to proceed to the next step:
- In the Get started section, do the following:
- Enter a globally unique name that meets thebucket name requirements.
- In the Choose where to store your data section, do the following:
- Select a Location type.
- Use the location type's drop-down menu to select aLocation where object data within your bucket will be permanently stored.
* If you select the dual-region location type, you can also choose to enableturbo replication by using the relevant checkbox.
- In the Choose how to store your data section, do the following:
- Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
- In the Optimize storage for data-intensive workloads section, do the following:
1. To enable hierarchical namespace, selectEnable Hierarchical namespace on this bucket.
2. In the Choose how to control access to objects section, select whether or not your bucket enforcespublic access prevention, and select anaccess control model for your bucket's objects.
3. In the Choose how to protect object data section, do the following:
* Select any of the options under Data protection that you want to set for your bucket.
* To enable soft delete, click expander arrow labeledsoft delete policy, and specify the number of days you want to retain objects after deletion.
* To choose how your object data will be encrypted, click the expander arrow labeledData encryption, and select aData encryption method. - Click Create.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, seeTroubleshooting.
- In the Get started section, do the following:
Command line
- In the Google Cloud console, activate Cloud Shell.
Activate Cloud Shell
At the bottom of the Google Cloud console, aCloud 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_NAMEis the name you want to give your bucket, subject tonaming requirements. For example,my-bucket.BUCKET_LOCATIONis 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. To automatically manage the storage classes of your objects, use the--enable-autoclassflag instead. For more information, see Autoclass.
For a complete list of options for creating buckets using the Google Cloud CLI, seebuckets 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 --enable-hierarchical-namespace
Client Libraries
C++
For more information, see theCloud Storage C++ API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
C#
For more information, see theCloud Storage C# API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
Go
For more information, see theCloud Storage Go API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
Java
For more information, see theCloud Storage Java API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
Node.js
For more information, see theCloud Storage Node.js API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
PHP
For more information, see theCloud Storage PHP API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
Python
For more information, see theCloud Storage Python API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
Ruby
For more information, see theCloud Storage Ruby API reference documentation.
To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.
REST APIs
JSON API
- Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorizationheader. - Create a JSON file that contains the settings for the bucket, which must include a
namefor the bucket. See theBuckets: Insert documentation for a complete list of settings. The following are common settings to include:
{ "name": "BUCKET_NAME", "location": "BUCKET_LOCATION", "storageClass": "STORAGE_CLASS", "hierarchicalNamespace": { "enabled": "BOOLEAN" }, "iamConfiguration": { "uniformBucketLevelAccess": { "enabled": true }, }, }
Where:
BUCKET_NAMEis the name you want to give your bucket, subject to naming requirements. For example,my-bucket.BUCKET_LOCATIONis the location where you want to store your bucket's object data. For example,US-EAST1.STORAGE_CLASSis the default storage class of your bucket. For example,STANDARD.hierarchicalNamespace.enabledis set toTRUEto enable hierarchical namespace for your bucket. You cannot enable hierarchical namespace in an existing bucket.
uniformBucketLevelAccess.enabledis set toTRUEto enable uniform bucket-level access for your bucket.- Use cURL to call theJSON 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_NAMEis name of the JSON file that contains the bucket settings.PROJECT_IDENTIFIERis the ID or number of the project that your bucket will be associated with. For example,my-project.