删除桶策略
DeleteBucketPolicy操作可以删除bucket已经配置的策略,bucket的所有者默认拥有删除bucket策略的权限。
代码示例:
using System;
using System.Threading.Tasks;
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Model;
namespace DotNetSDK.BucketOperation
{
public class DeleteBucketPolicyExample
{
public static async Task DeleteBucketPolicy()
{
var accessKey = "YOUR_ACCESS_KEY";
var secretKey = "YOUR_SECRET_KEY";
var endpoint = "YOUR_ENDPOINT";
var bucketName = "EXAMPLE_BUCKET";
try
{
var credentials = new BasicAWSCredentials(accessKey, secretKey);
var conf = new AmazonS3Config
{
ServiceURL = endpoint
};
var s3Client = new AmazonS3Client(credentials, conf);
var deleteBucketPolicyRequest = new DeleteBucketPolicyRequest()
{
BucketName = bucketName
};
var result = await s3Client.DeleteBucketPolicyAsync(deleteBucketPolicyRequest);
if (result.HttpStatusCode != System.Net.HttpStatusCode.OK)
{
Console.WriteLine("fail to delete policy of bucket {0}, HttpStatusCode:{1}, ErrorCode:{2}.", bucketName, (int) result.HttpStatusCode, result.HttpStatusCode);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
DeleteBucketPolicyRequest可以设置的参数如下:
参数 | 类型 | 说明 | 是否必要 |
---|---|---|---|
BucketName | string | bucekt的名称。 | 是 |
响应结果:
HTTP状态码 | 响应码 | 描述 |
---|---|---|
200 | OK | 操作成功。 |
403 | Forbidden | 用户没有权限执行操作。 |
404 | NotFound | 操作指定的bucekt不存在。 |