A bucket policy lets you authorize or restrict access of anonymous users or identified users, such as Alibaba Cloud accounts, RAM users, and RAM roles, to specific Object Storage Service (OSS) resources. For example, you can grant read-only permissions on specific OSS resources to a RAM user of another Alibaba Cloud account.
Usage notes
Before you configure bucket policies, make sure that you are familiar with this feature. For more information, see Bucket policies.
The sample code in this topic uses the region ID
cn-hangzhoufor the China (Hangzhou) region. By default, a public endpoint is used to access resources in a bucket. If you want to access resources in the bucket using other Alibaba Cloud services in the same region where the bucket is located, you must use an internal endpoint. For more information about the mappings between OSS regions and endpoints, see Regions and endpoints.To set a bucket policy, you must have the
oss:PutBucketPolicypermission. To obtain a bucket policy, you must have theoss:GetBucketPolicypermission. To delete a bucket policy, you must have theoss:DeleteBucketPolicypermission. For more information, see Attach a custom policy to a RAM user.
Examples
References
For the complete sample code that is used to configure a bucket policy, visit GitHub.
For more information about the API operation that you can call to configure a bucket policy, see PutBucketPolicy.
For the complete sample code that is used to query bucket policies, visit GitHub.
For more information about the API operation that you can call to query bucket policies, see GetBucketPolicy.
For the complete sample code that is used to delete a bucket policy, visit GitHub.
For more information about the API operation that you can call to delete a bucket policy, see DeleteBucketPolicy.