This page describes how to use dual-region storage.
Prerequisites
Prerequisites can vary based on the tool used:
Console
In order to complete this guide using the Google Cloud console, you must have the proper IAM permissions. If the object you want to delete exists in a project that you did not create, you might need the project owner to give you a role that contains the necessary permissions.
For a list of permissions required for specific actions, see IAM permissions for the Google Cloud console.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
Command line
In order to complete this guide using a command-line utility, you must have the proper IAM permissions. If the object you want to delete exists in a project that you did not create, you might need the project owner to give you a role that contains the necessary permissions.
For a list of permissions required for specific actions, see IAM permissions for gsutil commands.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
Code samples
In order to complete this guide using the Cloud Storage client libraries, you must have the proper IAM permissions. If the object you want to delete exists in a project that you did not create, you might need the project owner to give you a role that contains the necessary permissions. Unless otherwise noted, client library requests are made through the JSON API.
For a list of permissions required for specific actions, see IAM permissions for JSON methods.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
REST APIs
JSON API
In order to complete this guide using the JSON API, you must have the proper IAM permissions. If the object you want to delete exists in a project that you did not create, you might need the project owner to give you a role that contains the necessary permissions.
For a list of permissions required for specific actions, see IAM permissions for JSON methods.
For a list of relevant roles, see Cloud Storage roles. Alternatively, you can create a custom role that has specific, limited permissions.
Create a dual-region bucket
Complete the following steps to create a dual-region bucket:
Console
- In the Google Cloud console, go to the Cloud Storage Browser page.
Click Create bucket.
On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
For Name your bucket, enter a name that meets the bucket naming requirements.
For Choose where to store your data, next to Location type, choose Dual-region. Optional: You can combine the feature with turbo replication, by selecting the Add turbo replication checkbox.
For Location, select the continent and regions you want to use.
For Choose a default storage class for your data, select a storage class for the bucket. The default storage class is assigned by default to all objects uploaded to the bucket.
For Choose how to control access to objects, select the public access prevention and access control options you want to use.
For Choose how to protect object data, select the protection tools you want to use such as a retention policy, object versioning, and an encryption method.
Click Create.
If you select a dual-region combination not yet supported by turbo replication, an error message appears and the bucket is not created. Either select new regions or remove turbo replication and complete the steps again.
To learn how to get detailed error information about failed operations in the Cloud Storage browser, see Troubleshooting.
Command line
Use the gsutil mb -l
command:
gsutil mb -l REGION_1+REGION_2 gs://BUCKET_NAME/
Where:
REGION_1
specifies the geographic location of a region for your bucket.REGION_2
specifies the geographic location of a second region for your bucket.BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
.If the request is successful, the command returns the following message:
Creating gs://BUCKET_NAME/...
Invalid region combinations, such as pairings with unsupported regions or regions from separate continents, will return an error.
Code samples
For more information, see the
Cloud Storage C++ API reference documentation.
For more information, see the
Cloud Storage C# API reference documentation.
For more information, see the
Cloud Storage Go API reference documentation.
For more information, see the
Cloud Storage Java API reference documentation.
For more information, see the
Cloud Storage Node.js API reference documentation.
For more information, see the
Cloud Storage PHP API reference documentation.
For more information, see the
Cloud Storage Python API reference documentation.
For more information, see the
Cloud Storage Ruby API reference documentation.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
REST APIs
JSON API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. For instructions, see API authentication.
Create a .json file that contains the settings for the bucket, which must include a
name
andlocation
. See the Buckets:Insert documentation for a complete list of settings. The following are common settings to include:{ "name": "BUCKET_NAME", "location": "REGION_1+REGION_2", "storageClass": "STORAGE_CLASS" }
Where:
BUCKET_NAME
is the name you want to give your bucket, subject to naming requirements. For example,my-bucket
.REGION_1
andREGION_2
are the regions where you want to store your bucket's object data. For example,US-CENTRAL1
andUS-EAST1
.STORAGE_CLASS
is the storage class of your bucket. For example,STANDARD
.
Use
cURL
to call the JSON API:curl -X POST --data-binary @JSON_FILE_NAME.json \ -H "Authorization: Bearer OAUTH2_TOKEN" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/b?project=PROJECT_ID"
Where:
JSON_FILE_NAME
is name of the JSON file you created in Step 2.OAUTH2_TOKEN
is the access token you generated in Step 1.PROJECT_ID
is the ID of the project with which your bucket will be associated. For example,my-project
.
XML API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. For instructions, see API authentication.
Create an .xml file that contains the following information:
<CreateBucketConfiguration> <LocationConstraint>REGION_1+REGION_2</LocationConstraint> <StorageClass>STORAGE_CLASS</StorageClass> </CreateBucketConfiguration>
Where:
REGION_1
andREGION_2
are the regions where you want to store your bucket's object data. For example,US-CENTRAL1
andUS-EAST1
.STORAGE_CLASS
is the default storage class of your bucket. For example,STANDARD
.
-
curl -X PUT --data-binary @XML_FILE_NAME.xml \ -H "Authorization: Bearer OAUTH2_TOKEN" \ -H "x-goog-project-id: PROJECT_ID" \ "https://storage.googleapis.com/BUCKET_NAME"
Where:
XML_FILE_NAME
is the name of the XML file you created in Step 2.OAUTH2_TOKEN
is the access token you generated in Step 1.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 bucket naming requirements. For example,my-bucket
.
If the request includes unsupported regions, an error message is returned. If the request was successful, a response is not returned.
List the regions used for a dual-region bucket
Complete the following steps to list the bucket details, including the regions used for storage:
Console
- In the Google Cloud console, go to the Cloud Storage Browser page.
In the bucket list, click the name of the bucket you want to verify.
Click the Configuration tab to view bucket details such as the included regions, storage class, permissions, and replication type.
Command line
Use the gsutil ls -Lb
command:
gsutil ls -Lb gs://BUCKET_NAME
Where:
BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
.If the request is successful, the command returns the following or similar:
gs://my-bucket/ :
Storage class: STANDARD
Location type: dual-region
Location constraint: US-CENTRAL1+US-WEST1
...
Code samples
For more information, see the
Cloud Storage C++ API reference documentation.
For more information, see the
Cloud Storage C# API reference documentation.
For more information, see the
Cloud Storage Go API reference documentation.
For more information, see the
Cloud Storage Java API reference documentation.
For more information, see the
Cloud Storage Node.js API reference documentation.
For more information, see the
Cloud Storage PHP API reference documentation.
For more information, see the
Cloud Storage Python API reference documentation.
For more information, see the
Cloud Storage Ruby API reference documentation.
C++
C#
Go
Java
Node.js
PHP
Python
Ruby
REST APIs
JSON API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. For instructions, see API authentication.
Use
cURL
to call the JSON API with aGET
Bucket request. Include thelocation
query parameter:curl -X GET \ -H "Authorization: Bearer OAUTH2_TOKEN" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME?fields=location%2Clocation"
Where:
OAUTH2_TOKEN
is the name of the access token you generated in Step 1.BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
.location
represents the individual regions that comprise the bucket.
The response looks like the following example or similar:
{ "location": "US-CENTRAL1+US-WEST1" }
XML API
- Get an authorization access token from the OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials. For instructions, see API authentication.
Use
cURL
to call the XML API with aGET
Bucket request. Include thelocation
query parameter:curl -X GET \ -H "Authorization: Bearer OAUTH2_TOKEN" \ "https://storage.googleapis.com/BUCKET_NAME?location"
Where:
OAUTH2_TOKEN
is the name of the access token you generated in Step 1.BUCKET_NAME
is the name of the relevant bucket. For example,my-bucket
.location
is the metadata field you want to return. Uselocation
to list the regions associated with the bucket. You can only use one query parameter at a time with the XML API.
The response looks like the following example or similar:
<LocationConstraint>US-CENTRAL1+US-WEST1</LocationConstraint>
What's next
- Learn more about turbo replication.
- Learn more about turbo replication pricing or see a pricing example.