Esempio n. 1
0
        public static void WaitForBucket(IAmazonS3 client, string bucketName, int maxSeconds)
        {
            var sleeper = UtilityMethods.ListSleeper.Create();

            UtilityMethods.WaitUntilSuccess(() => {
                //Check if a bucket exists by trying to put an object in it
                var key = Guid.NewGuid().ToString() + "_existskey";

                var res = client.PutObject(new PutObjectRequest
                {
                    BucketName  = bucketName,
                    Key         = key,
                    ContentBody = "exists..."
                });

                try
                {
                    client.Delete(bucketName, key, null);
                }
                catch
                {
                    Console.WriteLine($"Eventual consistency error: failed to delete key {key} from bucket {bucketName}");
                }

                return(true);
            });

            //Double check the bucket still exists using the DoesBucketExistV2 method
            var exists = S3TestUtils.WaitForConsistency(() =>
            {
                return(AmazonS3Util.DoesS3BucketExistV2(client, bucketName) ? (bool?)true : null);
            });
        }
Esempio n. 2
0
 public void HappyCaseDoesS3BucketExist()
 {
     // make sure the cache works when it gets the region from the x-amz-bucket-region header
     using (var runner = new BucketRegionTestRunner(true, true))
     {
         if (runner.TestBucketIsReady)
         {
             Assert.IsTrue(AmazonS3Util.DoesS3BucketExistV2(runner.USEast1Client, runner.BucketName));
             RegionEndpoint cachedRegion;
             Assert.IsTrue(BucketRegionDetector.BucketRegionCache.TryGetValue(runner.BucketName, out cachedRegion));
             Assert.AreEqual(RegionEndpoint.USWest1, cachedRegion);
         }
     }
 }
 public void CreateBucket()
 {
     if (AmazonS3Util.DoesS3BucketExistV2(client, "myappname"))
     {
         Console.WriteLine("The bucket created succesfullyt ");
     }
     else
     {
         var bucketRequest = new PutBucketRequest
         {
             BucketName      = "myappname",
             UseClientRegion = true,
         };
         var bucketResponse = client.PutBucket(bucketRequest);
         if (bucketResponse.HttpStatusCode == System.Net.HttpStatusCode.OK)
         {
             Console.WriteLine("The bucket created succesfullyt ");
         }
     }
 }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;

            using (var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint))
            {
                Utils.Common.WriteVerboseEndpointMessage(this, Client.Config, "Amazon S3");

#if DESKTOP
                var exists = AmazonS3Util.DoesS3BucketExistV2(client, cmdletContext.BucketName);
#elif CORECLR
                var exists = AmazonS3Util.DoesS3BucketExistV2Async(client, cmdletContext.BucketName).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
                var output = new CmdletOutput
                {
                    PipelineOutput = exists
                };
                return(output);
            }
        }
 private void createBucket(string bucketName)
 {
     try
     {
         IAmazonS3 s3client = new AmazonS3Client();
         if (!(AmazonS3Util.DoesS3BucketExistV2(s3client, bucketName)))
         {
             PutBucketRequest request = new PutBucketRequest();
             request.BucketName      = bucketName;
             request.UseClientRegion = true;
             PutBucketResponse putBucketResponse = s3client.PutBucket(request);
         }
     }
     catch (AmazonS3Exception amazonS3Exception)
     {
         MessageBoxResult msbr = MessageBox.Show(String.Format("An error code {0} occured when creating bucket with message {1}", amazonS3Exception.ErrorCode, amazonS3Exception.Message), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         if (msbr == MessageBoxResult.OK)
         {
             Process p = Process.GetCurrentProcess();
             p.Kill();
         }
     }
 }
Esempio n. 6
0
        public void Create()
        {
            {
                if (!AmazonS3Util.DoesS3BucketExistV2(client, "stellaoliveirabertth"))
                {
                    var bucket = new PutBucketRequest {
                        BucketName = "stellaoliveirabertth", UseClientRegion = true
                    };
                    var bucketResponse = client.PutBucket(bucket);

                    if (bucketResponse.HttpStatusCode.IsSuccess())
                    {
                        Console.WriteLine("Bucket Created Success");
                    }
                }
                else
                {
                    Console.WriteLine("Bucket exists!");
                }
            }

            Console.ReadLine();
        }