Bucket policies let you authorize or restrict access to specific OSS resources for anonymous users or identified users such as Alibaba Cloud accounts, RAM users, and RAM roles. For example, you can grant a RAM user of another Alibaba Cloud account read-only permissions on specific OSS resources.
Notes
-
Before you configure bucket policies, make sure that you understand this feature.
-
The sample code in this topic uses the region ID
cn-hangzhouof the China (Hangzhou) region. By default, the public endpoint is used to access resources in a bucket. If you want to access resources in the bucket from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about supported regions and endpoints, see Regions and Endpoints. -
The
oss:PutBucketPolicypermission is required to configure a bucket policy. Theoss:GetBucketPolicypermission is required to query a bucket policy. Theoss:DeleteBucketPolicypermission is required to delete a bucket policy. For more information, see Grant a custom policy.
Methods
Configure a bucket policy
put_bucket_policy(request: PutBucketPolicyRequest, **kwargs) → PutBucketPolicyResult
Query bucket policies
get_bucket_policy(request: GetBucketPolicyRequest, **kwargs) → GetBucketPolicyResult
Delete a bucket policy
delete_bucket_policy(request: DeleteBucketPolicyRequest, **kwargs) → DeleteBucketPolicyResult
|
Parameter |
Type |
Description |
|
request |
PutBucketPolicyRequest |
The request for the PutBucketPolicy operation. For request parameters, see PutBucketPolicyRequest. |
|
GetBucketPolicyRequest |
The request for the GetBucketPolicy operation. For request parameters, see GetBucketPolicyRequest. |
|
|
DeleteBucketPolicyRequest |
The request for the DeleteBucketPolicy operation. For request parameters, see DeleteBucketPolicyRequest. |
Response parameters
|
Type |
Description |
|
PutBucketPolicyResult |
The return value. For more information, see PutBucketPolicyResult. |
|
GetBucketPolicyResult |
The return value. For more information, see GetBucketPolicyResult. |
|
DeleteBucketPolicyResult |
The return value. For more information, see DeleteBucketPolicyResult. |
For the complete method definition for configuring a bucket policy, see put_bucket_policy.
For the complete method definition for querying bucket policies, see get_bucket_policy.
For the complete method definition for deleting a bucket policy, see delete_bucket_policy.
Sample code
References
-
For complete sample code for configuring a bucket policy, visit put_bucket_policy.py.
-
For complete sample code for querying bucket policies, visit get_bucket_policy.py.
-
For complete sample code for deleting a bucket policy, visit delete_bucket_policy.py.