Create a bucket (original) (raw)
This page shows you how to create a Cloud Storage bucket. If not otherwise specified in your request, buckets are created in theUS multi-region with a default storage class of Standard storageand have a seven-day soft delete retention duration.
In order to get the required permissions for creating a Cloud Storage bucket, ask your administrator to grant you the Storage Admin (roles/storage.admin
) IAM role for the project.
This predefined role contains the permission required to create a bucket. To see the exact permissions that are required, expand theRequired permissions section:
You might also be able to get these permissions with custom roles or other predefined roles. To see which roles are associated with which permissions, refer to IAM roles for Cloud Storage.
To create a bucket with specific settings or advanced configurations, complete the following steps:
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.
- To add a bucket label, click the expander arrow to expand the Labels section, clickAdd label, and specify a
key
and avalue
for your label.
- 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 enable turbo replication by using the relevant checkbox. - To set up cross-bucket replication, selectAdd cross-bucket replication via Storage Transfer Service and follow the steps:
Set up cross-bucket replication
1. In the **Bucket** menu, select a bucket. 2. In the **Replication settings** section, click **Configure** to configure settings for the replication job. The **Configure cross-bucket replication** pane appears. * To filter objects to replicate by object name prefix, enter a prefix with which you want to include or exclude objects, then click **Add a prefix**. * To set a storage class for the replicated objects, select a storage class from the **Storage class** menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default. * Click **Done**.
- In the Choose how to store your data section, do the following:
- Select a default storage class for the bucket orAutoclass for automatic storage class management of your bucket's data.
- To enable hierarchical namespace, in theOptimize storage for data-intensive workloads section, selectEnable Hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control model for your bucket's objects.
- 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 labeled soft 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 labeled Data encryption, and select aData encryption method.
- In the Get started section, do the following:
- Click Create.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, seeTroubleshooting.
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 thegcloud storage buckets create command:
gcloud storage buckets create gs://BUCKET_NAME --location=BUCKET_LOCATION
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
.
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 with which your bucket will be associated. For example,my-project
.--default-storage-class
: Specify the default storage classof your bucket. For example,STANDARD
.--uniform-bucket-level-access
: Enable uniform bucket-level accessfor your bucket.--soft-delete-duration
: Specify a soft delete retention duration, which is the number of days you want to retain objects after they get deleted. For example,10d
.
For example:
gcloud storage buckets create gs://BUCKET_NAME --project=PROJECT_ID --default-storage-class=STORAGE_CLASS --location=BUCKET_LOCATION --uniform-bucket-level-access
--soft-delete-duration=RETENTION_DURATION
For a complete list of options for bucket creation use the gcloud CLI, see buckets create options.
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.
Terraform
You can use a Terraform resource to create a storage bucket.
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:Insertdocumentation for a complete list of settings. The following are common settings to include:
{
"name": "BUCKET_NAME",
"location": "BUCKET_LOCATION",
"storageClass": "STORAGE_CLASS",
"iamConfiguration": {
"uniformBucketLevelAccess": {
"enabled": true
},
}
}
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 where you want to store your bucket's object data. For example,US
.STORAGE_CLASS
is the defaultstorage class of your bucket. For example,STANDARD
.
- 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 you created in Step 2.PROJECT_IDENTIFIER
is the ID or number of the project with which your bucket will be associated. For example,my-project
.
XML API
- Have gcloud CLI installed and initialized, which lets you generate an access token for the
Authorization
header. - Create an XML file that contains settings for the bucket. See theXML: Create a bucket documentation for a complete list of settings. The following are common settings to include: STORAGE_CLASS BUCKET_LOCATION Where: * `STORAGE_CLASS` is the default[storage class](/storage/docs/storage-classes) of your bucket. For example, `STANDARD`. * `BUCKET_LOCATION` is the [location](/storage/docs/locations) where you want to store your bucket's [object data](/storage/docs/objects). For example,`US`.
- Use cURL to call the XML API:
curl -X PUT --data-binary @XML_FILE_NAME \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-project-id: PROJECT_ID" \
"https://storage.googleapis.com/BUCKET_NAME"
Where:XML_FILE_NAME
is name of the XML file you created in Step 2.PROJECT_ID
is the ID of the project with which your bucket will be associated. For example,my-project
.BUCKET_NAME
is the name you want to give your bucket, subject to naming requirements. For example,my-bucket
.
If the request was successful, a response is not returned.