A bucket policy is an OSS authorization policy that you can use to grant or restrict fine-grained access to specified OSS resources for identified users, such as Alibaba Cloud accounts, RAM users, RAM roles, or anonymous users. For example, you can grant read-only permissions on specified OSS resources to a RAM user that belongs to another Alibaba Cloud account.
Notes
Before you configure a bucket policy, ensure that you are familiar with this feature. For more information, see Bucket Policy.
The sample code in this topic uses the region ID
cn-hangzhoufor the China (Hangzhou) region as an example. By default, a public endpoint is used. If you want to access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the regions and endpoints that OSS supports, see Regions and endpoints.You must have the
oss:PutBucketPolicypermission to set a bucket policy, theoss:GetBucketPolicypermission to query a bucket policy, and theoss:DeleteBucketPolicypermission to delete a bucket policy. For more information, see Attach a custom policy to a RAM user.
Method definitions
Set a bucket policy
put_bucket_policy(request: PutBucketPolicyRequest, **kwargs) → PutBucketPolicyResultQuery a bucket policy
get_bucket_policy(request: GetBucketPolicyRequest, **kwargs) → GetBucketPolicyResultDelete a bucket policy
delete_bucket_policy(request: DeleteBucketPolicyRequest, **kwargs) → DeleteBucketPolicyResultParameter | Type | Description |
request | PutBucketPolicyRequest | The request parameters. For more information, see PutBucketPolicyRequest |
GetBucketPolicyRequest | The request parameters. For more information, see GetBucketPolicyRequest | |
DeleteBucketPolicyRequest | The request parameters. For more information, see DeleteBucketPolicyRequest |
Return values
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 definition of the method to set a bucket policy, see put_bucket_policy.
For the complete definition of the method to query a bucket policy, see get_bucket_policy.
For the complete definition of the method to delete a bucket policy, see delete_bucket_policy.
Sample code
References
For the complete sample code to set a bucket policy, see put_bucket_policy.py.
For the complete sample code to query a bucket policy, see get_bucket_policy.py.
For the complete sample code to delete a bucket policy, see delete_bucket_policy.py.