删除桶生命周期

DeleteLifecycleConfiguration操作可以删除bucket中的全部生命周期规则。

代码示例:

using System;
using System.Threading.Tasks;
using Amazon.Runtime;
using Amazon.S3;
using Amazon.S3.Model;

namespace DotNetSDK.BucketOperation
{
    public class DeleteBucketLifecycleConfigurationExample
    {
        public static async Task DeleteBucketLifeConfiguration()
        {
            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 deleteLifecycleConfigurationRequest = new DeleteLifecycleConfigurationRequest()
                {
                    BucketName = bucketName
                };
                var result = await s3Client.DeleteLifecycleConfigurationAsync(deleteLifecycleConfigurationRequest);
                if (result.HttpStatusCode != System.Net.HttpStatusCode.NoContent)
                {
                    Console.WriteLine("fail to delete lifecycle configuration of bucket {0}, HttpStatusCode:{1}, ErrorCode:{2}.", bucketName, (int) result.HttpStatusCode, result.HttpStatusCode);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

DeleteLifecycleConfigurationRequest可设置的参数如下:

参数 类型 说明 是否必要
BucketName string bucket的名称。

响应结果:

HTTP状态码 响应码 描述
204 NoContent 操作成功。
403 Forbidden 用户没有权限执行操作。
404 NotFound 指定的bucekt不存在。