internal async Task <string> GetVaultNameAsync(CancellationToken cancellationToken) { using (AmazonGlacierClient client = new AmazonGlacierClient(Amazon.RegionEndpoint.USEast2)) { var request = new DescribeVaultRequest { VaultName = $"{PreferedVaultName}_{_configuration.UniqueClientId}" }; try { var details = await client.DescribeVaultAsync(request, cancellationToken).ConfigureAwait(false); if (!string.IsNullOrEmpty(details.VaultName)) { return(details.VaultName); } using (ArchiveTransferManager manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USEast2)) { manager.CreateVault(request.VaultName); } } catch (Exception e) { _logger.Info(e, $"Vault does not exist. Creating vault '{request.VaultName}' ..."); throw new ConfigurationErrorsException("Cannot create vault", e); } return(request.VaultName); } }
public static void createVault(string vaultName) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USEast1); manager.CreateVault(vaultName); //manager.DeleteVault(vaultName); //Console.WriteLine("\nVault deleted. To continue, press Enter"); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } }
static void Main(string[] args) { if (CheckRequiredFields()) { using (manager = new ArchiveTransferManager(RegionEndpoint.USWest2)) { try { // Creates a new Vault Console.WriteLine("Create Vault"); manager.CreateVault(vaultName); // Uploads the specified file to Glacier. Console.WriteLine("Upload a Archive"); var uploadResult = manager.Upload(vaultName, "Archive Description", filePath); archiveId = uploadResult.ArchiveId; Console.WriteLine("Upload successful. Archive Id : {0} Checksum : {1}", uploadResult.ArchiveId, uploadResult.Checksum); // Downloads the file from Glacier // This operation can take a long time to complete. // The ArchiveTransferManager.Download() method creates an Amazon SNS topic, // and an Amazon SQS queue that is subscribed to that topic. // It then initiates the archive retrieval job and polls the queue for the // archive to be available. This polling takes about 4 hours. // Once the archive is available, download will begin. Console.WriteLine("Download the Archive"); var options = new DownloadOptions(); options.StreamTransferProgress += OnProgress; manager.Download(vaultName, archiveId, downloadFilePath, options); Console.WriteLine("Delete the Archive"); manager.DeleteArchive(vaultName, archiveId); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } } } }