/// <summary> /// Creates an S3 Multi-Region Access Point and waits for it to be ready /// </summary> /// <param name="s3ControlClient">S3Control client to create the MRAP with</param> /// <param name="mrapRequest">Prepared CreateMultiRegionAccessPoint request</param> /// <returns>Alias of the new Multi-Region Access Point</returns> public static string CreateMRAPWithWait(IAmazonS3Control s3ControlClient, CreateMultiRegionAccessPointRequest mrapRequest) { var asyncRequestArn = s3ControlClient.CreateMultiRegionAccessPoint(mrapRequest).RequestTokenARN; var mrapAlias = UtilityMethods.WaitUntilSuccess(() => { var request = new GetMultiRegionAccessPointRequest { AccountId = mrapRequest.AccountId, Name = mrapRequest.Details.Name }; var response = s3ControlClient.GetMultiRegionAccessPoint(request); if (response.AccessPoint.Status == MultiRegionAccessPointStatus.READY) { return(response.AccessPoint.Alias); } else { throw new Exception("S3 Multi-Region Access Point not ready yet, will continue waiting."); } }); return(mrapAlias); }
/// <summary> /// Gets a long-lived S3 Multi-Region Access Point for running integration tests against if /// if exists in the current account. If not, creates it and waits for it to be ready. /// </summary> /// <param name="s3ControlClient">S3Control client to create the MRAP with</param> /// <param name="s3Client">S3 client to create the backing bucket with</param> /// <returns>ARN of the new Multi-Region Access Point</returns> public static string GetOrCreateTestMRAP(IAmazonS3Control s3ControlClient, IAmazonS3 s3Client) { var accountId = new AmazonSecurityTokenServiceClient().GetCallerIdentity(new GetCallerIdentityRequest()).Account; // If the MRAP already exists, return it var mrapArn = CheckIfMRAPExists(s3ControlClient, accountId, TEST_MRAP_NAME); if (!string.IsNullOrEmpty(mrapArn)) { return(mrapArn); } // Otherwise the MRAP doesn't exist, so we must create it, starting with the backing bucket. var putBucketRequest = new PutBucketRequest { BucketName = $"{accountId}-{TEST_MRAP_NAME}" }; var backingBucketName = CreateBucketWithWait(s3Client, putBucketRequest); var createMrapRequest = new CreateMultiRegionAccessPointRequest { AccountId = accountId, Details = new CreateMultiRegionAccessPointInput { Name = TEST_MRAP_NAME, Regions = new List <Region> { new Region { Bucket = backingBucketName } } } }; // Initiate the MRAP creation var asyncRequestArn = s3ControlClient.CreateMultiRegionAccessPoint(createMrapRequest).RequestTokenARN; // Wait until its status is READY UtilityMethods.WaitUntilSuccess(() => { var request = new GetMultiRegionAccessPointRequest { AccountId = accountId, Name = TEST_MRAP_NAME }; var response = s3ControlClient.GetMultiRegionAccessPoint(request); if (response.AccessPoint.Status == MultiRegionAccessPointStatus.READY) { // Wait for SSL provisioning to finish Thread.Sleep(TimeSpan.FromMinutes(1)); return($"arn:aws:s3::{accountId}:accesspoint/{response.AccessPoint.Alias}"); } else { throw new Exception("S3 Multi-Region Access Point not ready yet, will continue waiting."); } }); throw new Exception($"{nameof(GetOrCreateTestMRAP)} timed out while creating a new Multi-Region Access Point"); }