The DeleteBucketRequest contains the parameters used for the DeleteBucket operation.
Required Parameters: BucketName
상속: Amazon.S3.Model.S3Request
예제 #1
0
 public async Task<IHttpActionResult> Delete()
 {
     var bucketRequest = new DeleteBucketRequest
     {
         BucketName = TestBucketName,
         BucketRegion = S3Region.EUC1
     };
     var request = new DeleteObjectsRequest
     {
         BucketName = TestBucketName,
         Objects = new List<KeyVersion>
         {
             new KeyVersion { Key = "test1.txt" },
             new KeyVersion { Key = "test2.txt" },
             new KeyVersion { Key = "test3.txt" },
             new KeyVersion { Key = "test4.txt" },
             new KeyVersion { Key = "test5.txt" },
             new KeyVersion { Key = "test6.txt" },
             new KeyVersion { Key = "test7.txt" },
             new KeyVersion { Key = "test8.txt" },
             new KeyVersion { Key = "test9.txt" },
             new KeyVersion { Key = "test10.txt" }
         }
     };
     await _client.DeleteObjectsAsync(request);
     await _client.DeleteBucketAsync(bucketRequest);
     return Ok();
 }
        public async Task <DeleteBucketResponse> DeleteBucketAsync(string name,
                                                                   CancellationToken cancellationToken = default)
        {
            this.Logger.LogDebug($"[{nameof(this.DeleteBucketAsync)}]");

            this.Logger.LogTrace(JsonConvert.SerializeObject(new { name }));

            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }

            var request = new Amazon.S3.Model.DeleteBucketRequest
            {
                BucketName = name,
            };

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: request));

            var response = await this.Repository.DeleteBucketAsync(request : request,
                                                                   cancellationToken : cancellationToken == default?this.CancellationToken.Token : cancellationToken);

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: response));

            return(response);
        }
 protected override void ProcessRecord()
 {
     AmazonS3 client = base.GetClient();
     Amazon.S3.Model.DeleteBucketRequest request = new Amazon.S3.Model.DeleteBucketRequest();
     request.BucketName = this._BucketName;
     Amazon.S3.Model.DeleteBucketResponse response = client.DeleteBucket(request);
 }
        protected override void ExecuteTask()
        {
            Project.Log(Level.Info, "Deleting S3 bucket: {0}", BucketName);

            /// Check to see if the bucket exists before we try to delete it.
            if (!BucketExists(BucketName))
            {
                Project.Log(Level.Warning, "Bucket: {0} not found!", BucketName);
                return;
            }
            else
            {
                using (Client)
                {
                    try
                    {
                        DeleteBucketRequest request = new DeleteBucketRequest();
                        request.BucketName = BucketName;
                        Client.DeleteBucket(request);
                    }
                    catch (AmazonS3Exception ex)
                    {
                        ShowError(ex);
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Delete a bucket and its content.
        /// </summary>
        /// <param name="bucketName">The name of the bucket.</param>
        public void DeleteBucket(string bucketName)
        {
            var request = new DeleteBucketRequest
                              {
                                  BucketName = bucketName
                              };

            _amazonS3Client.DeleteBucket(request);
        }
예제 #6
0
 public void DeleteBucket(string name)
 {
     try
     {
         var request = new DeleteBucketRequest { BucketName = name };
         _s3Client.DeleteBucket(request);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
예제 #7
0
        /// <summary>
        /// Deletes all keys in a given bucket, then deletes the bucket itself.
        /// </summary>
        /// <param name="client">The client to use.</param>
        /// <param name="bucketName">The bucket to delete.</param>
        public static void DeleteBucketRecursive(this AmazonS3 client, string bucketName)
        {
            while(true)
            {
                // attempt to delete the bucket
                try
                {
                    var deleteRequest = new DeleteBucketRequest()
                    {
                        BucketName = bucketName
                    };
                    using (var deleteResponse = client.DeleteBucket(deleteRequest))
                    {
                        // deletion was successful
                        return;
                    }
                }
                catch (AmazonS3Exception ex)
                {
                    if (ex.ErrorCode != "BucketNotEmpty") throw ex;
                }

                var objRequest = new ListObjectsRequest()
                {
                    BucketName = bucketName
                };
                using (var objResponse = client.ListObjects(objRequest))
                {
                    var delRequest = new DeleteObjectsRequest()
                    {
                        BucketName = bucketName,
                        Quiet = true
                    };

                    // select the objects to delete (up to the supported limit of 1000)
                    var objToDelete = objResponse.S3Objects.Take(1000).Select(o => new KeyVersion(o.Key));
                    delRequest.AddKeys(objToDelete.ToArray());

                    using (var delResponse = client.DeleteObjects(delRequest))
                    {
                    }
                }
            }
        }
예제 #8
0
        public virtual void DeleteBucket(AmazonS3Client s3Client, string bucketName)
        {
            // First, try to delete the bucket.
            var deleteBucketRequest = new DeleteBucketRequest
            {
                BucketName = bucketName
            };

            try
            {
                s3Client.DeleteBucket(deleteBucketRequest);
                // If we get here, no error was generated so we'll assume the bucket was deleted and return.
                return;
            }
            catch (AmazonS3Exception ex)
            {
                if (!ex.ErrorCode.Equals("BucketNotEmpty"))
                {
                    // We got an unanticipated error. Just rethrow.
                    throw;
                }
            }

            // If we got here, then our bucket isn't empty so we need to delete the items in it first.

            DeleteObjectsRequest deleteObjectsRequest = new DeleteObjectsRequest {BucketName = bucketName};

            foreach (S3Object obj in s3Client.ListObjects(new ListObjectsRequest {BucketName = bucketName}).S3Objects)
            {
                // Add keys for the objects to the delete request
                deleteObjectsRequest.AddKey(obj.Key, null);
            }

            // Submit the request
            s3Client.DeleteObjects(deleteObjectsRequest);

            // The bucket is empty now, so delete the bucket.
            s3Client.DeleteBucket(deleteBucketRequest);
        }
예제 #9
0
        private Amazon.S3.Model.DeleteBucketResponse CallAWSServiceOperation(IAmazonS3 client, Amazon.S3.Model.DeleteBucketRequest request)
        {
            Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon S3", "DeleteBucket");

            try
            {
#if DESKTOP
                return(client.DeleteBucket(request));
#elif CORECLR
                return(client.DeleteBucketAsync(request).GetAwaiter().GetResult());
#else
#error "Unknown build edition"
#endif
            }
            catch (AmazonServiceException exc)
            {
                var webException = exc.InnerException as System.Net.WebException;
                if (webException != null)
                {
                    throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
                }

                throw;
            }
        }
예제 #10
0
 /// <summary>
 /// Deletes the bucket. All objects (including all object versions and Delete Markers)
 /// in the bucket must be deleted before the bucket itself can be deleted.
 /// </summary>
 /// <param name="bucketName">A property of DeleteBucketRequest used to execute the DeleteBucket service method.</param>
 /// <param name="cancellationToken">
 ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// 
 /// <returns>The response from the DeleteBucket service method, as returned by S3.</returns>
 public Task<DeleteBucketResponse> DeleteBucketAsync(string bucketName, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new DeleteBucketRequest();
     request.BucketName = bucketName;
     return DeleteBucketAsync(request, cancellationToken);
 }
예제 #11
0
 /// <summary>
 /// Deletes the bucket. All objects (including all object versions and Delete Markers)
 /// in the bucket must be deleted before the bucket itself can be deleted.
 /// </summary>
 /// <param name="bucketName">A property of DeleteBucketRequest used to execute the DeleteBucket service method.</param>
 /// 
 /// <returns>The response from the DeleteBucket service method, as returned by S3.</returns>
 public DeleteBucketResponse DeleteBucket(string bucketName)
 {
     var request = new DeleteBucketRequest();
     request.BucketName = bucketName;
     return DeleteBucket(request);
 }
예제 #12
0
        public void TearDown()
        {
            //A post-requisite for testing S3 objects. Ensure that all the Buckets and objects created are deleted before we exit the test-class.
            bool hasCallbackArrived = false;

            //B. Delete the destination object.
            hasCallbackArrived = false;
            S3ResponseEventHandler<object, ResponseEventArgs> deleteObjectHandler = null;

            deleteObjectHandler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                _client.OnS3Response -= deleteObjectHandler;
                hasCallbackArrived = true;
            };

            _client.OnS3Response += deleteObjectHandler;
            DeleteObjectRequest objectrequest = new DeleteObjectRequest { BucketName = _bucketNameDestination, Key = "key_UnitTesting_destination_1" };
            _client.DeleteObject(objectrequest);

            EnqueueConditional(() => hasCallbackArrived);

            //A. Delete the normal bucket.
            S3ResponseEventHandler<object, ResponseEventArgs> handler = null;
            handler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                if (result is DeleteBucketResponse)
                {
                    //Unhook from event.
                    _client.OnS3Response -= handler;
                    hasCallbackArrived = true;
                }
            };
            _client.OnS3Response += handler;

            DeleteBucketRequest request = new DeleteBucketRequest() { BucketName = _bucketName };
            _client.DeleteBucket(request);

            EnqueueConditional(() => hasCallbackArrived);

            //Delete the destination Bucket
            hasCallbackArrived = false;
            S3ResponseEventHandler<object, ResponseEventArgs> deleteBucketHandler = null;

            deleteBucketHandler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response bucketResult = args.Response;
                if (bucketResult is DeleteBucketResponse)
                {
                    //Unhook from event.
                    _client.OnS3Response -= deleteBucketHandler;
                    hasCallbackArrived = true;

                    //Finally, set the client as null.
                    _client = null;
                }
            };

            _client.OnS3Response += deleteBucketHandler;
            DeleteBucketRequest deleteRequest = new DeleteBucketRequest() { BucketName = _bucketNameDestination };
            _client.DeleteBucket(deleteRequest);

            EnqueueConditional(() => hasCallbackArrived);

            EnqueueTestComplete();
        }
예제 #13
0
        /// <summary>
        /// Deletes the container with the specified name.
        /// </summary>
        /// <param name="name">Name of the container to delete.</param>
        public void Delete(string name)
        {
            BlobContainerUtilities.EnsureValidContainerName(name);

              try {
            var request = new DeleteBucketRequest() { BucketName = name };
            _client.DeleteBucket(request);
              }
              catch (AmazonS3Exception ex) {
            throw WrapException(ex);
              }
        }
예제 #14
0
 IAsyncResult invokeDeleteBucket(DeleteBucketRequest deleteBucketRequest, AsyncCallback callback, object state, bool synchronized)
 {
     var marshaller = new DeleteBucketRequestMarshaller();
     var unmarshaller = DeleteBucketResponseUnmarshaller.GetInstance();
     var result = Invoke(deleteBucketRequest, callback, state, synchronized, marshaller, unmarshaller, this.signer);
     return result;
 }
예제 #15
0
 /// <summary>
 /// <para>Deletes the bucket. All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket
 /// itself can be deleted.</para>
 /// </summary>
 /// 
 /// <param name="deleteBucketRequest">Container for the necessary parameters to execute the DeleteBucket service method on AmazonS3.</param>
 /// 
 public DeleteBucketResponse DeleteBucket(DeleteBucketRequest deleteBucketRequest)
 {
     IAsyncResult asyncResult = invokeDeleteBucket(deleteBucketRequest, null, null, true);
     return EndDeleteBucket(asyncResult);
 }
예제 #16
0
        /// <summary>
        /// <para>Deletes the bucket. All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket
        /// itself can be deleted.</para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteBucket service method on AmazonS3.</param>
		public DeleteBucketResponse DeleteBucket(DeleteBucketRequest request)
        {
            var task = DeleteBucketAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
예제 #17
0
        /// <summary>
        /// <para>Deletes the bucket. All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket
        /// itself can be deleted.</para>
        /// </summary>
        /// 
        /// <param name="deleteBucketRequest">Container for the necessary parameters to execute the DeleteBucket service method on AmazonS3.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public async Task<DeleteBucketResponse> DeleteBucketAsync(DeleteBucketRequest deleteBucketRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteBucketRequestMarshaller();
            var unmarshaller = DeleteBucketResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, DeleteBucketRequest, DeleteBucketResponse>(deleteBucketRequest, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
예제 #18
0
        /// <summary>
        /// <para>Deletes the bucket. All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket
        /// itself can be deleted.</para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteBucket service method on AmazonS3.</param>
		public DeleteBucketResponse DeleteBucket(DeleteBucketRequest request)
        {
            var task = DeleteBucketAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
        private void DeleteFolderInternal(string path, bool recursive)
        {
            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            var bki = new S3BucketKeyInfo(path, terminateWithPathDelimiter: true);

            if (recursive)
            {
                while (true)
                {
                    var objects = ListFolder(bki);

                    if (!objects.Any())
                        break;

                    var keys = objects.Select(o => new KeyVersion
                    {
                        Key = o.Key
                    })
                    .ToList();

                    var deleteObjectsRequest = new DeleteObjectsRequest
                    {
                        BucketName = bki.BucketName,
                        Quiet = true,
                        Objects = keys
                    };

                    S3Client.DeleteObjects(deleteObjectsRequest);
                }
            }
            else if (!bki.IsBucketObject)
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = bki.BucketName,
                    Key = bki.Key
                };

                S3Client.DeleteObject(deleteObjectRequest);
            }

            if (bki.IsBucketObject)
            {
                var request = new DeleteBucketRequest
                {
                    BucketName = bki.BucketName,
                    UseClientRegion = true
                };

                S3Client.DeleteBucket(request);
            }
        }
예제 #20
0
        public void DeleteAllBuckets()
        {
            ListBucketsResponse response = this.amazonS3Client.ListBuckets();
            foreach (S3Bucket b in response.Buckets)
            {
                Console.WriteLine("{0}\t{1}", b.BucketName, b.CreationDate);
                ListObjectsRequest r = new ListObjectsRequest();
                r.BucketName = b.BucketName;
                ListObjectsResponse resp = this.amazonS3Client.ListObjects(r);

                foreach (S3Object o in resp.S3Objects)
                {
                    DeleteObjectRequest dr = new DeleteObjectRequest();
                    dr.BucketName = b.BucketName;
                    dr.Key = o.Key;
                    amazonS3Client.DeleteObject(dr);
                }

                DeleteBucketRequest request = new DeleteBucketRequest();
                request.BucketName = b.BucketName;
                amazonS3Client.DeleteBucket(request);
            }

        }
예제 #21
0
        public bool DeleteBucket()
        {
            try
            {
                ListObjectsRequest request = new ListObjectsRequest();
                request.BucketName = this.bucketName;
                ListObjectsResponse response = amazonS3Client.ListObjects(request);
                foreach (S3Object o in response.S3Objects)
                {
                    DeleteObjectRequest delrequest = new DeleteObjectRequest();
                    delrequest.BucketName = this.bucketName;
                    delrequest.Key = o.Key;
                    amazonS3Client.DeleteObject(delrequest);
                }

                DeleteBucketRequest delbucketrequest = new DeleteBucketRequest();
                delbucketrequest.BucketName = this.bucketName;
                amazonS3Client.DeleteBucket(delbucketrequest);
                return true;
            }

            catch (Exception e)
            {
                structuredLog("E", "Exception in DeleteBucket: " + e);
                return false;
            }
        }
예제 #22
0
 /// <summary>
 /// Deletes the bucket. All objects (including all object versions and Delete Markers)
 /// in the bucket must be deleted before the bucket itself can be deleted.
 /// This API is supported only when AWSConfigs.HttpClient is set to AWSConfigs.HttpClientOption.UnityWebRequest, the default value of this configuration option is AWSConfigs.HttpClientOption.UnityWWW
 /// </summary>
 /// <param name="bucketName">A property of DeleteBucketRequest used to execute the DeleteBucket service method.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">
 ///     A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///     procedure using the AsyncState property.
 /// </param>
 /// 
 /// <returns>The response from the DeleteBucket service method, as returned by S3.</returns>
 public void DeleteBucketAsync(string bucketName,  AmazonServiceCallback<DeleteBucketRequest, DeleteBucketResponse> callback, AsyncOptions options = null)
 {
     var request = new DeleteBucketRequest();
     request.BucketName = bucketName;
     DeleteBucketAsync(request, callback, options);
 }
예제 #23
0
 /// <summary>
 /// Initiates the asynchronous execution of the DeleteBucket operation.
 /// This API is supported only when AWSConfigs.HttpClient is set to AWSConfigs.HttpClientOption.UnityWebRequest, the default value for this configuration option is AWSConfigs.HttpClientOption.UnityWWW
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the DeleteBucket operation on AmazonS3Client.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void DeleteBucketAsync(DeleteBucketRequest request, AmazonServiceCallback<DeleteBucketRequest, DeleteBucketResponse> callback, AsyncOptions options = null)
 {
     if (AWSConfigs.HttpClient == AWSConfigs.HttpClientOption.UnityWWW)
     {
         throw new InvalidOperationException("DeleteBucket is only allowed with AWSConfigs.HttpClientOption.UnityWebRequest API option");
     }
     options = options == null?new AsyncOptions():options;
     var marshaller = new DeleteBucketRequestMarshaller();
     var unmarshaller = DeleteBucketResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<DeleteBucketRequest,DeleteBucketResponse> responseObject 
                     = new AmazonServiceResult<DeleteBucketRequest,DeleteBucketResponse>((DeleteBucketRequest)req, (DeleteBucketResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<DeleteBucketRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
예제 #24
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteBucket operation.
        /// <seealso cref="Amazon.S3.IAmazonS3.DeleteBucket"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteBucket operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public Task<DeleteBucketResponse> DeleteBucketAsync(DeleteBucketRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteBucketRequestMarshaller();
            var unmarshaller = DeleteBucketResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, DeleteBucketRequest, DeleteBucketResponse>(request, marshaller, unmarshaller, signer, cancellationToken);
        }
예제 #25
0
 /// <summary>
 /// Initiates the asynchronous execution of the DeleteBucket operation.
 /// <seealso cref="Amazon.S3.IAmazonS3.DeleteBucket"/>
 /// </summary>
 /// 
 /// <param name="deleteBucketRequest">Container for the necessary parameters to execute the DeleteBucket operation on AmazonS3.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public IAsyncResult BeginDeleteBucket(DeleteBucketRequest deleteBucketRequest, AsyncCallback callback, object state)
 {
     return invokeDeleteBucket(deleteBucketRequest, callback, state, false);
 }
예제 #26
0
        public void BucketSamples()
        {
            {
                #region ListBuckets Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Issue call
                ListBucketsResponse response = client.ListBuckets();

                // View response data
                Console.WriteLine("Buckets owner - {0}", response.Owner.DisplayName);
                foreach (S3Bucket bucket in response.Buckets)
                {
                    Console.WriteLine("Bucket {0}, Created on {1}", bucket.BucketName, bucket.CreationDate);
                }

                #endregion
            }

            {
                #region BucketPolicy Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Put sample bucket policy (overwrite an existing policy)
                string newPolicy = @"{ 
    ""Statement"":[{ 
    ""Sid"":""BasicPerms"", 
    ""Effect"":""Allow"", 
    ""Principal"": ""*"", 
    ""Action"":[""s3:PutObject"",""s3:GetObject""], 
    ""Resource"":[""arn:aws:s3:::samplebucketname/*""] 
}]}";
                PutBucketPolicyRequest putRequest = new PutBucketPolicyRequest
                {
                    BucketName = "SampleBucket",
                    Policy = newPolicy
                };
                client.PutBucketPolicy(putRequest);


                // Retrieve current policy
                GetBucketPolicyRequest getRequest = new GetBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                string policy = client.GetBucketPolicy(getRequest).Policy;

                Console.WriteLine(policy);
                Debug.Assert(policy.Contains("BasicPerms"));


                // Delete current policy
                DeleteBucketPolicyRequest deleteRequest = new DeleteBucketPolicyRequest
                {
                    BucketName = "SampleBucket"
                };
                client.DeleteBucketPolicy(deleteRequest);


                // Retrieve current policy and verify that it is null
                policy = client.GetBucketPolicy(getRequest).Policy;
                Debug.Assert(policy == null);

                #endregion
            }

            {
                #region GetBucketLocation Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                GetBucketLocationRequest request = new GetBucketLocationRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                GetBucketLocationResponse response = client.GetBucketLocation(request);

                // View response data
                Console.WriteLine("Bucket location - {0}", response.Location);

                #endregion
            }

            {
                #region PutBucket Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                PutBucketRequest request = new PutBucketRequest
                {
                    BucketName = "SampleBucket",
                    BucketRegion = S3Region.EU,         // set region to EU
                    CannedACL = S3CannedACL.PublicRead  // make bucket publicly readable
                };

                // Issue call
                PutBucketResponse response = client.PutBucket(request);

                #endregion
            }

            {
                #region DeleteBucket Sample 1

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // Construct request
                DeleteBucketRequest request = new DeleteBucketRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                DeleteBucketResponse response = client.DeleteBucket(request);

                #endregion
            }

            {
                #region DeleteBucket Sample 2

                // Create a client
                AmazonS3Client client = new AmazonS3Client();

                // List and delete all objects
                ListObjectsRequest listRequest = new ListObjectsRequest
                {
                    BucketName = "SampleBucket"
                };

                ListObjectsResponse listResponse;
                do
                {
                    // Get a list of objects
                    listResponse = client.ListObjects(listRequest);
                    foreach (S3Object obj in listResponse.S3Objects)
                    {
                        // Delete each object
                        client.DeleteObject(new DeleteObjectRequest
                        {
                            BucketName = "SampleBucket",
                            Key = obj.Key
                        });
                    }

                    // Set the marker property
                    listRequest.Marker = listResponse.NextMarker;
                } while (listResponse.IsTruncated);

                // Construct DeleteBucket request
                DeleteBucketRequest request = new DeleteBucketRequest
                {
                    BucketName = "SampleBucket"
                };

                // Issue call
                DeleteBucketResponse response = client.DeleteBucket(request);

                #endregion
            }

            {
                #region LifecycleConfiguration Sample

                // Create a client
                AmazonS3Client client = new AmazonS3Client();


                // Put sample lifecycle configuration (overwrite an existing configuration)
                LifecycleConfiguration newConfiguration = new LifecycleConfiguration
                {
                    Rules = new List<LifecycleRule>
                    {
                        // Rule to delete keys with prefix "Test-" after 5 days
                        new LifecycleRule
                        {
                            Prefix = "Test-",
                            Expiration = new LifecycleRuleExpiration { Days = 5 }
                        },
                        // Rule to delete keys in subdirectory "Logs" after 2 days
                        new LifecycleRule
                        {
                            Prefix = "Logs/",
                            Expiration = new LifecycleRuleExpiration  { Days = 2 },
                            Id = "log-file-removal"
                        }
                    }
                };
                PutLifecycleConfigurationRequest putRequest = new PutLifecycleConfigurationRequest
                {
                    BucketName = "SampleBucket",
                    Configuration = newConfiguration
                };
                client.PutLifecycleConfiguration(putRequest);


                // Retrieve current configuration
                GetLifecycleConfigurationRequest getRequest = new GetLifecycleConfigurationRequest
                {
                    BucketName = "SampleBucket"
                };
                LifecycleConfiguration configuration = client.GetLifecycleConfiguration(getRequest).Configuration;

                Console.WriteLine("Configuration contains {0} rules", configuration.Rules.Count);
                foreach (LifecycleRule rule in configuration.Rules)
                {
                    Console.WriteLine("Rule");
                    Console.WriteLine(" Prefix = " + rule.Prefix);
                    Console.WriteLine(" Expiration (days) = " + rule.Expiration.Days);
                    Console.WriteLine(" Id = " + rule.Id);
                    Console.WriteLine(" Status = " + rule.Status);
                }


                // Put a new configuration and overwrite the existing configuration
                configuration.Rules.RemoveAt(0);    // remove first rule
                client.PutLifecycleConfiguration(putRequest);

                // Delete current configuration
                DeleteLifecycleConfigurationRequest deleteRequest = new DeleteLifecycleConfigurationRequest
                {
                    BucketName = "SampleBucket"
                };
                client.DeleteLifecycleConfiguration(deleteRequest);


                // Retrieve current configuration and verify that it is null
                configuration = client.GetLifecycleConfiguration(getRequest).Configuration;
                Debug.Assert(configuration == null);

                #endregion
            }
        }
예제 #27
0
        internal DeleteBucketResponse DeleteBucket(DeleteBucketRequest request)
        {
            var marshaller = new DeleteBucketRequestMarshaller();
            var unmarshaller = DeleteBucketResponseUnmarshaller.Instance;

            return Invoke<DeleteBucketRequest,DeleteBucketResponse>(request, marshaller, unmarshaller);
        }
예제 #28
0
        public void BucketK_DeleteBucketTest()
        {
            bool expectedValue = true;
            bool actualValue = false;
            bool hasCallbackArrived = false;

            S3ResponseEventHandler<object, ResponseEventArgs> handler = null;
            handler = delegate(object sender, ResponseEventArgs args)
            {
                IS3Response result = args.Response;
                //Unhook from event.
                _client.OnS3Response -= handler;
                DeleteBucketResponse response = result as DeleteBucketResponse;
                if (null != response)
                    actualValue = response.IsRequestSuccessful;
                hasCallbackArrived = true;
            };
            _client.OnS3Response += handler;

            DeleteBucketRequest request = new DeleteBucketRequest() { BucketName = _bucketNameForBucketAPIs };
            _client.DeleteBucket(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue,
                string.Format("Expected Value = {0}, Actual Value = {1}", expectedValue, actualValue)));
            EnqueueTestComplete();
        }
예제 #29
0
파일: s3cmd.cs 프로젝트: mmcquillan/s3
 public void rmdir(string bucket)
 {
     try
     {
         DeleteBucketRequest deletebucketrequest = new DeleteBucketRequest();
         deletebucketrequest.BucketName = bucket;
         s3Client.DeleteBucket(deletebucketrequest);
         Console.WriteLine("Bucket '" + bucket + "' has been deleted");
     }
     catch ( Exception e )
     {
         Console.WriteLine("Error deleting bucket '" + bucket + "': " + e.Message);
     }
 }
예제 #30
0
        public void BucketK_DeleteBucketTest_ForException_EmptyBucketName()
        {
            string actualValue = string.Empty;
            string emptyBucketName = string.Empty;

            //Create request object.
            DeleteBucketRequest request = new DeleteBucketRequest { BucketName = emptyBucketName };
            _client.DeleteBucket(request);
            EnqueueTestComplete();
        }
예제 #31
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteBucket operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteBucket operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<DeleteBucketResponse> DeleteBucketAsync(DeleteBucketRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new DeleteBucketRequestMarshaller();
            var unmarshaller = DeleteBucketResponseUnmarshaller.Instance;

            return InvokeAsync<DeleteBucketRequest,DeleteBucketResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
예제 #32
0
        /// <summary>
        /// Initiates the asynchronous execution of the DeleteBucket operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the DeleteBucket operation on AmazonS3Client.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndDeleteBucket
        ///         operation.</returns>
        public IAsyncResult BeginDeleteBucket(DeleteBucketRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new DeleteBucketRequestMarshaller();
            var unmarshaller = DeleteBucketResponseUnmarshaller.Instance;

            return BeginInvoke<DeleteBucketRequest>(request, marshaller, unmarshaller,
                callback, state);
        }