A bucket policy allows you to allow or deny 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.
Notes
Before you configure bucket policies, make sure that you are familiar with this feature. For more information, see Bucket Policy.
The sample code in this topic uses the region ID
cn-hangzhou
of 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 by using other Alibaba Cloud services in the same region in which the bucket is located, use an internal endpoint. For more information about the regions and endpoints supported by Object Storage Service (OSS), see OSS regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
The
oss:PutBucketPolicy
permission is required to configure a bucket policy. Theoss:GetBucketPolicy
permission is required to query a bucket policy. Theoss:DeleteBucketPolicy
permission is required to delete a bucket policy. For more information, see Authorize custom policies for RAM users.
Sample code
References
For the complete sample code that is used to configure a bucket policy, visit GitHub example.
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 a bucket policy, visit GitHub example.
For more information about the API operation that you can call to query a bucket policy, see GetBucketPolicy.
For the complete sample code that is used to delete a bucket policy, visit GitHub example.
For more information about the API operation that you can call to delete a bucket policy, see DeleteBucketPolicy.