public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; CmdletOutput output = new CmdletOutput(); using (var tu = new TransferUtility(Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint))) { Utils.Common.WriteVerboseEndpointMessage(this, Client.Config, "Amazon S3 abort multi-part upload APIs"); try { tu.AbortMultipartUploads(cmdletContext.BucketName, cmdletContext.InitiatedDate); } 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; } catch (Exception e) { output.ErrorResponse = e; } } return(output); }
/// <summary> /// Tracks the multipart upload progress. /// </summary> /// <param name="existingBucketName">Name of the existing bucket.</param> /// <param name="filePath">The file path.</param> /// <param name="keyName">Name of the key.</param> /// <param name="enableTransferAccleration">if set to <c>true</c> [enable transfer accleration].</param> /// <returns></returns> public static string TrackMultipartUploadProgress(string existingBucketName, string filePath, string keyName, bool enableTransferAccleration) { var sw = Stopwatch.StartNew(); var credentialProfileStoreChain = new CredentialProfileStoreChain(); credentialProfileStoreChain.TryGetAWSCredentials("basic_profile", out var defaultCredentials); using (var s3Client = new AmazonS3Client(defaultCredentials, BucketRegion)) { using (var transferUtility = new TransferUtility(s3Client)) { try { EnableTransferAcclerationOnBucket(BucketName); var uploadRequest = new TransferUtilityUploadRequest { BucketName = existingBucketName, FilePath = filePath, Key = keyName, //PartSize = 8388608, // 8 MB. PartSize = 16777216, //PartSize = 6291456, // 6 MB. CannedACL = S3CannedACL.PublicRead, StorageClass = S3StorageClass.ReducedRedundancy }; uploadRequest.UploadProgressEvent += uploadRequest_UploadPartProgressEvent; transferUtility.Upload(uploadRequest); sw.Stop(); Console.WriteLine("TrackMultipartUploadProgress completed in {0} seconds", sw.Elapsed.TotalSeconds); return("OK"); } catch (AmazonS3Exception ex) { transferUtility.AbortMultipartUploads(existingBucketName, DateTime.Now.AddDays(-1)); return("ERROR:" + ex.Message); } catch (AmazonServiceException ex) { transferUtility.AbortMultipartUploads(existingBucketName, DateTime.Now.AddDays(-1)); return("NETWORK_ERROR: " + ex.Message); } } } }
public void BlockTransferUtilityAbortMultipartUploadsTest() { var transferUtility = new TransferUtility(RegionEndpoint.USWest2); try { transferUtility.AbortMultipartUploads("arn:aws:s3-object-lambda:us-west-2:123456789012:accesspoint/mybanner", DateTime.Now); } catch (AmazonS3Exception e) { var expectedMessage = "AbortMultipartUploads does not support S3 Object Lambda resources"; Assert.AreEqual(expectedMessage, e.Message); } }