public static void Main(string[] args) { // create the AWS S3 client ECSS3Client s3 = ECSS3Factory.getS3Client(); bool moreRecords = true; string nextMarker = string.Empty; while (moreRecords) { ListVersionsRequest request = new ListVersionsRequest() { BucketName = ECSS3Factory.S3_BUCKET, }; if (nextMarker.Length > 0) { request.KeyMarker = nextMarker; } ListVersionsResponse response = new ListVersionsResponse(); response = s3.ListVersions(request); foreach (S3ObjectVersion theObject in response.Versions) { s3.DeleteObject(new DeleteObjectRequest() { BucketName = ECSS3Factory.S3_BUCKET, Key = theObject.Key, VersionId = theObject.VersionId }); Console.WriteLine("Deleted {0}/{1}", ECSS3Factory.S3_BUCKET, theObject.Key); } Console.WriteLine(string.Format("Next Marker: {0} Version Count: {1}", response.NextKeyMarker, response.Versions.Count.ToString())); if (response.IsTruncated) { nextMarker = response.NextKeyMarker; } else { moreRecords = false; } } s3.DeleteBucket(new DeleteBucketRequest() { BucketName = ECSS3Factory.S3_BUCKET }); // print bucket name for validation Console.WriteLine(string.Format("Deleted bucket {0}", ECSS3Factory.S3_BUCKET)); Console.ReadLine(); }
private static bool CleanBucket(string bucket) { bool moreRecords = true; string nextMarker = string.Empty; while (moreRecords) { ListVersionsRequest request = new ListVersionsRequest() { BucketName = bucket, }; if (nextMarker.Length > 0) { request.KeyMarker = nextMarker; } ListVersionsResponse response = new ListVersionsResponse(); response = client.ListVersions(request); foreach (S3ObjectVersion theObject in response.Versions) { client.DeleteObject(new DeleteObjectRequest() { BucketName = bucket, Key = theObject.Key, VersionId = theObject.VersionId }); } if (response.IsTruncated) { nextMarker = response.NextKeyMarker; } else { moreRecords = false; } } return(true); }
public static void Main(string[] args) { // create the ECS S3 client ECSS3Client s3 = ECSS3Factory.getS3Client(); // retrieve the object key from user Console.Write("Enter the object key: "); string key = Console.ReadLine(); // create the request object DeleteObjectRequest request = new DeleteObjectRequest() { BucketName = ECSS3Factory.S3_BUCKET, Key = key }; // delete the object in the demo bucket s3.DeleteObject(request); // print out object key/value for validation Console.WriteLine(string.Format("Object {0}/{1} deleted", ECSS3Factory.S3_BUCKET, key)); Console.ReadLine(); }
public static void Main(string[] args) { // create the AWS S3 client ECSS3Client s3 = ECSS3Factory.getS3Client(); foreach (string key in KEY_LIST) { // create object request with retrieved input PutObjectRequest request = new PutObjectRequest() { BucketName = ECSS3Factory.S3_BUCKET, ContentBody = key, Key = key }; // create the object in demo bucket s3.PutObject(request); } while (true) { Console.Write("Enter the prefix (empty if none): "); string prefix = Console.ReadLine(); Console.Write("Enter the delimiter (e.g. /, empty for none): "); string delimiter = Console.ReadLine(); Console.Write("Enter the marker (empty if none): "); string marker = Console.ReadLine(); Console.Write("Enter the max keys (empty for defaul): "); string maxKeys = Console.ReadLine(); ListObjectsRequest request = new ListObjectsRequest() { BucketName = ECSS3Factory.S3_BUCKET }; if (prefix.Length > 0) { request.Prefix = prefix; } if (delimiter.Length > 0) { request.Delimiter = delimiter; } if (marker.Length > 0) { request.Marker = marker; } if (maxKeys.Length > 0) { request.MaxKeys = Int32.Parse(maxKeys); } ListObjectsResponse response = s3.ListObjects(request); Console.WriteLine("-----------------"); Console.WriteLine("Bucket: " + ECSS3Factory.S3_BUCKET); Console.WriteLine("Prefix: " + response.Prefix); Console.WriteLine("Delimiter: " + response.Delimiter); Console.WriteLine("Marker: " + marker); Console.WriteLine("IsTruncated? " + response.IsTruncated); Console.WriteLine("NextMarker: " + response.NextMarker); Console.WriteLine(); if (response.CommonPrefixes != null) { foreach (string commonPrefix in response.CommonPrefixes) { Console.WriteLine("CommonPrefix: " + commonPrefix); } } Console.WriteLine("Printing objects"); Console.WriteLine("-----------------"); foreach (S3Object s3Object in response.S3Objects) { Console.WriteLine(String.Format("{0} {1} {2}", s3Object.LastModified.ToString(), s3Object.Size, s3Object.Key)); } Console.Write("Another? (Y/N) "); string another = Console.ReadLine(); if (another.ToUpper() == "N") { break; } } foreach (string key in KEY_LIST) { s3.DeleteObject(ECSS3Factory.S3_BUCKET, key); } Console.ReadLine(); }
public static void Main(string[] args) { // create the ECS S3 client ECSS3Client s3 = ECSS3Factory.getS3Client(); // Create the bucket with indexed keys List <MetaSearchKey> bucketMetadataSearchKeys = new List <MetaSearchKey>() { new MetaSearchKey() { Name = USER_PREFIX + FIELD_ACCOUNT_ID, Type = MetaSearchDatatype.integer }, new MetaSearchKey() { Name = USER_PREFIX + FIELD_BILLING_DATE, Type = MetaSearchDatatype.datetime }, new MetaSearchKey() { Name = USER_PREFIX + FIELD_BILL_TYPE, Type = MetaSearchDatatype.@string } }; PutBucketRequestECS pbr = new PutBucketRequestECS(); pbr.BucketName = BUCKET_NAME; pbr.SetMetadataSearchKeys(bucketMetadataSearchKeys); s3.PutBucket(pbr); foreach (string key in KEY_LIST) { PutObjectRequestECS por = new PutObjectRequestECS(); por.BucketName = BUCKET_NAME; por.Key = key; por.Metadata.Add(FIELD_ACCOUNT_ID, extractAccountId(key)); por.Metadata.Add(FIELD_BILLING_DATE, extractBillDate(key)); por.Metadata.Add(FIELD_BILL_TYPE, extractBillType(key)); s3.PutObject(por); } while (true) { Console.Write("Enter the account id (empty for none): "); string accountId = Console.ReadLine(); Console.Write("Enter the billing date (e.g. 2016-09-22, empty for none): "); string billingDate = Console.ReadLine(); Console.Write("Enter the bill type (e.g. xml. empty for none): "); string billType = Console.ReadLine(); QueryObjectsRequest qor = new QueryObjectsRequest() { BucketName = BUCKET_NAME }; StringBuilder query = new StringBuilder(); if (accountId.Length > 0) { query.Append(USER_PREFIX + FIELD_ACCOUNT_ID + "==" + accountId + ""); } if (billingDate.Length > 0) { if (query.Length > 0) { query.Append(" and "); } query.Append(USER_PREFIX + FIELD_BILLING_DATE + "==" + billingDate + "T00:00:00Z"); } if (billType.Length > 0) { if (query.Length > 0) { query.Append(" and "); } query.Append(USER_PREFIX + FIELD_BILL_TYPE + "=='" + billType + "'"); } qor.Query = query.ToString(); QueryObjectsResponse res = s3.QueryObjects(qor); Console.WriteLine("--------------------------"); Console.WriteLine("Bucket: " + res.BucketName); Console.WriteLine("Query: " + qor.Query); Console.WriteLine(); Console.WriteLine("Key"); Console.WriteLine("--------------------------"); foreach (QueryObject obj in res.ObjectMatches) { Console.WriteLine(string.Format("{0}", obj.Name)); } Console.Write("Another? (Y/N) "); string another = Console.ReadLine(); if (another.ToUpper() == "N") { break; } } //cleanup foreach (string key in KEY_LIST) { s3.DeleteObject(BUCKET_NAME, key); } s3.DeleteBucket(BUCKET_NAME); }