private void CreateAndCheckTestBucket()
{
TestBucketIsReady = false;
USEast1Client = new AmazonS3Client(RegionEndpoint.USEast1);
USWest1Client = new AmazonS3Client(RegionEndpoint.USWest1);
var sessionCredentials = new AmazonSecurityTokenServiceClient().GetSessionToken().Credentials;
USEast1ClientWithSessionCredentials = new AmazonS3Client(sessionCredentials, RegionEndpoint.USEast1);
TestBucket = USWest1Client.ListBuckets().Buckets.Find(bucket => bucket.BucketName.StartsWith(BucketPrefix));
if (TestBucket == null)
{
// add ticks to bucket name because the bucket namespace is shared globally
var bucketName = BucketPrefix + DateTime.Now.Ticks;
// Create the bucket but don't run the test.
// If the bucket is ready the next time this test runs we'll test then.
USWest1Client.PutBucket(new PutBucketRequest()
{
BucketRegion = S3Region.USW1,
BucketName = bucketName,
});
}
else if (TestBucket.CreationDate.AddHours(TemporaryRedirectMaxExpirationHours) < DateTime.Now)
{
BucketRegionDetector.BucketRegionCache.Clear();
TestBucketIsReady = true;
}
}