This topic describes how to configure a resource group for a bucket and obtain the ID of the resource group to which the bucket belongs.
Usage notes
The sample code in this topic uses the
cn-hangzhouregion ID of the China (Hangzhou) region as an example. The public endpoint is used by default. If you want to access OSS from other Alibaba Cloud products in the same region, use the internal endpoint. For more information about the mappings between OSS regions and endpoints, see Regions and endpoints.This topic provides an example of obtaining access credentials from environment variables. For more information about how to configure access credentials, see Configure access credentials.
To configure a resource group for a bucket, you must have the
oss:PutBucketResourceGrouppermission. To query the resource group ID of a bucket, you must have theoss:GetBucketResourceGrouppermission. For more information, see Attach a custom policy to a RAM user.
Method definitions
Configure the resource group for a bucket
func (c *Client) PutBucketResourceGroup(ctx context.Context, request *PutBucketResourceGroupRequest, optFns ...func(*Options)) (*PutBucketResourceGroupResult, error)Obtain the ID of the resource group for a bucket
func (c *Client) GetBucketResourceGroup(ctx context.Context, request *GetBucketResourceGroupRequest, optFns ...func(*Options)) (*GetBucketResourceGroupResult, error)Request parameters
Parameter | Type | Description |
ctx | context.Context | The context of the request. You can use this parameter to set the total timeout period for the request. |
request | *PutBucketResourceGroupRequest | The request parameters of the API operation. For more information, see PutBucketResourceGroupRequest |
*GetBucketResourceGroupRequest | The request parameters of the API operation. For more information, see GetBucketResourceGroupRequest | |
optFns | ...func(*Options) | Optional. The operation-level configuration parameters. For more information, see Options |
Return values
Return value | Type | Description |
result | *PutBucketResourceGroupResult | The return value of the API operation. This parameter is valid when err is nil. For more information, see PutBucketResourceGroupResult |
*GetBucketResourceGroupRequest | The return value of the API operation. This parameter is valid when err is nil. For more information, see GetBucketResourceGroupResult | |
err | error | The status of the request. If the request fails, err is not nil. |
Examples
References
For the complete sample code on how to configure a resource group for a bucket, see GitHub example.
For more information about the API operation for configuring a resource group for a bucket, see PutBucketResourceGroup.
For the complete sample code on how to obtain the resource group ID of a bucket, see GitHub example.
For more information about the API operation for obtaining the resource group ID of a bucket, see GetBucketResourceGroup.