Use the resource-group command to assign a resource group to a bucket or retrieve the resource group currently assigned to a bucket.
Prerequisites
Before you begin, make sure you have:
ossutil 1.7.16 or later. The
resource-groupcommand is not available in earlier versions.The
oss:PutBucketResourceGrouppermission to assign a resource group to a bucketThe
oss:GetBucketResourceGrouppermission to retrieve the resource group of a bucket
For ossutil 1.6.16 and later, use ossutil directly as the binary name. For earlier versions, specify the OS-specific binary name. See ossutil command reference.
To grant these permissions to a RAM user, see Attach a custom policy to a RAM user.
Assign a resource group to a bucket
Syntax
ossutil resource-group --method put oss://<bucketname>/ <local_xml_file>| Parameter | Description |
|---|---|
<bucketname> | The name of the bucket to assign to a resource group. |
<local_xml_file> | The path to a local XML file that specifies the resource group ID. For example, config.xml. |
XML file format
<?xml version="1.0" encoding="UTF-8"?>
<BucketResourceGroupConfiguration>
<ResourceGroupId>rg-aekz****</ResourceGroupId>
</BucketResourceGroupConfiguration>| Field | Description |
|---|---|
ResourceGroupId | The ID of the resource group to assign to the bucket. |
Example
Create a local XML file named
config.xmlwith the resource group ID:<?xml version="1.0" encoding="UTF-8"?> <BucketResourceGroupConfiguration> <ResourceGroupId>rg-aekz****</ResourceGroupId> </BucketResourceGroupConfiguration>Run the following command to assign the resource group to
examplebucket:ossutil resource-group --method put oss://examplebucket/ config.xmlExpected output:
0.299514(s) elapsed
Query the resource group of a bucket
Syntax
ossutil resource-group --method get oss://<bucketname>/ [local_xml_file]| Parameter | Description |
|---|---|
<bucketname> | The name of the bucket whose resource group you want to retrieve. |
[local_xml_file] | (Optional) The path to a local file where the returned configuration is saved. For example, local.xml. If omitted, the result is printed to the terminal. |
Output fields
| Field | Description |
|---|---|
ResourceGroupId | The ID of the resource group currently assigned to the bucket. |
Examples
Retrieve and print the resource group of
examplebucket:ossutil resource-group --method get oss://examplebucket/Expected output:
<?xml version="1.0" encoding="UTF-8"?> <BucketResourceGroupConfiguration> <ResourceGroupId>rg-aekz****</ResourceGroupId> </BucketResourceGroupConfiguration> 0.154689(s) elapsedRetrieve the resource group of
examplebucketand save it tolocal.xml:ossutil resource-group --method get oss://examplebucket/ local.xmlExpected terminal output:
0.214483(s) elapsedThe saved file contains:
<?xml version="1.0" encoding="UTF-8"?> <BucketResourceGroupConfiguration> <ResourceGroupId>rg-aekz****</ResourceGroupId> </BucketResourceGroupConfiguration>