Creating a Vault in Amazon S3 Glacier Using the Amazon SDK for .NET - Amazon S3 Glacier
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

This page is only for existing customers of the S3 Glacier service using Vaults and the original REST API from 2012.

If you're looking for archival storage solutions we suggest using the S3 Glacier storage classes in Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval, and S3 Glacier Deep Archive. To learn more about these storage options, see S3 Glacier storage classes and Long-term data storage using S3 Glacier storage classes in the Amazon S3 User Guide. These storage classes use the Amazon S3 API, are available in all regions, and can be managed within the Amazon S3 console. They offer features like Storage Cost Analysis, Storage Lens, advanced optional encryption features, and more.

Creating a Vault in Amazon S3 Glacier Using the Amazon SDK for .NET

Both the high-level and low-level APIs provided by the Amazon SDK for .NET provide a method to create a vault.

Creating a Vault Using the High-Level API of the Amazon SDK for .NET

The ArchiveTransferManager class of the high-level API provides the CreateVault method you can use to create a vault in an Amazon Region.

Example: Vault Operations Using the High-Level API of the Amazon SDK for .NET

The following C# code example creates and delete a vault in the US West (Oregon) Region. For a list of Amazon Web Services Regions in which you can create vaults, see Accessing Amazon S3 Glacier.

For step-by-step instructions on how to run the following example, see Running Code Examples. You need to update the code as shown with a vault name.

using System; using Amazon.Glacier; using Amazon.Glacier.Transfer; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class VaultCreateDescribeListVaultsDeleteHighLevel { static string vaultName = "*** Provide vault name ***"; public static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); manager.CreateVault(vaultName); Console.WriteLine("Vault created. To delete the vault, press Enter"); Console.ReadKey(); manager.DeleteVault(vaultName); Console.WriteLine("\nVault deleted. To continue, press Enter"); Console.ReadKey(); } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } } }

Creating a Vault Using the Low-Level API of the Amazon SDK for .NET

The low-level API provides methods for all the vault operations, including create and delete vaults, get a vault description, and get a list of vaults created in a specific Amazon Web Services Region. The following are the steps to create a vault using the Amazon SDK for .NET.

  1. Create an instance of the AmazonGlacierClient class (the client).

    You need to specify an Amazon Web Services Region in which you want to create a vault. All operations you perform using this client apply to that Amazon Web Services Region.

  2. Provide request information by creating an instance of the CreateVaultRequest class.

    Amazon S3 Glacier (S3 Glacier) requires you to provide a vault name and your account ID. If you don't provide an account ID, then account ID associated with the credentials you provide to sign the request is assumed. For more information, see Using the Amazon SDK for .NET with Amazon S3 Glacier.

  3. Run the CreateVault method by providing the request object as a parameter.

    The response S3 Glacier returns is available in the CreateVaultResponse object.

Example: Vault Operations Using the Low-Level API of the Amazon SDK for .NET

The following C# example illustrates the preceding steps. The example creates a vault in the US West (Oregon) Region. In addition, the code example retrieves the vault information, lists all vaults in the same Amazon Web Services Region, and then deletes the vault created. The Location printed is the relative URI of the vault that includes your account ID, the Amazon Web Services Region, and the vault name.

Note

For information about the underlying REST API, see Create Vault (PUT vault).

For step-by-step instructions on how to run the following example, see Running Code Examples. You need to update the code as shown with a vault name.

using System; using Amazon.Glacier; using Amazon.Glacier.Model; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class VaultCreateDescribeListVaultsDelete { static string vaultName = "*** Provide vault name ***"; static AmazonGlacierClient client; public static void Main(string[] args) { try { using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2)) { Console.WriteLine("Creating a vault."); CreateAVault(); DescribeVault(); GetVaultsList(); Console.WriteLine("\nVault created. Now press Enter to delete the vault..."); Console.ReadKey(); DeleteVault(); } } catch (AmazonGlacierException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("To continue, press Enter"); Console.ReadKey(); } static void CreateAVault() { CreateVaultRequest request = new CreateVaultRequest() { VaultName = vaultName }; CreateVaultResponse response = client.CreateVault(request); Console.WriteLine("Vault created: {0}\n", response.Location); } static void DescribeVault() { DescribeVaultRequest describeVaultRequest = new DescribeVaultRequest() { VaultName = vaultName }; DescribeVaultResponse describeVaultResponse = client.DescribeVault(describeVaultRequest); Console.WriteLine("\nVault description..."); Console.WriteLine( "\nVaultName: " + describeVaultResponse.VaultName + "\nVaultARN: " + describeVaultResponse.VaultARN + "\nVaultCreationDate: " + describeVaultResponse.CreationDate + "\nNumberOfArchives: " + describeVaultResponse.NumberOfArchives + "\nSizeInBytes: " + describeVaultResponse.SizeInBytes + "\nLastInventoryDate: " + describeVaultResponse.LastInventoryDate ); } static void GetVaultsList() { string lastMarker = null; Console.WriteLine("\n List of vaults in your account in the specific region ..."); do { ListVaultsRequest request = new ListVaultsRequest() { Marker = lastMarker }; ListVaultsResponse response = client.ListVaults(request); foreach (DescribeVaultOutput output in response.VaultList) { Console.WriteLine("Vault Name: {0} \tCreation Date: {1} \t #of archives: {2}", output.VaultName, output.CreationDate, output.NumberOfArchives); } lastMarker = response.Marker; } while (lastMarker != null); } static void DeleteVault() { DeleteVaultRequest request = new DeleteVaultRequest() { VaultName = vaultName }; DeleteVaultResponse response = client.DeleteVault(request); } } }