Deleting an Archive 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).

If you're new to archival storage in Amazon Simple Storage Service (Amazon S3), we recommend that you start by learning more about the S3 Glacier storage classes in Amazon S3, S3 Glacier Instant Retrieval, S3 Glacier Flexible Retrieval, and S3 Glacier Deep Archive. For more information, see S3 Glacier storage classes and Storage classes for archiving objects in the Amazon S3 User Guide.

Deleting an Archive 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 delete an archive.

Deleting an Archive Using the High-Level API of the Amazon SDK for .NET

The ArchiveTransferManager class of the high-level API provides the DeleteArchive method you can use to delete an archive.

Example: Deleting an Archive Using the High-Level API of the Amazon SDK for .NET

The following C# code example uses the high-level API of the Amazon SDK for .NET to delete an archive. For step-by-step instructions on how to run this example, see Running Code Examples. You need to update the code as shown with the archive ID of the archive you want to delete.

using System; using Amazon.Glacier; using Amazon.Glacier.Transfer; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class ArchiveDeleteHighLevel { static string vaultName = "examplevault"; static string archiveId = "*** Provide archive ID ***"; public static void Main(string[] args) { try { var manager = new ArchiveTransferManager(Amazon.RegionEndpoint.USWest2); manager.DeleteArchive(vaultName, archiveId); 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(); } } }

Deleting an Archive Using the Low-Level API Amazon SDK for .NET

The following are the steps to delete an using the Amazon SDK for .NET.

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

    You need to specify an Amazon Region where the archive you want to delete is stored. All operations you perform using this client apply to that Amazon Region.

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

    You need to provide an archive ID, 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 SDKs with Amazon S3 Glacier.

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

Example: Deleting an Archive Using the Low-Level API of the Amazon SDK for .NET

The following C# example illustrates the preceding steps. The example uses the low-level API of the Amazon SDK for .NET to delete an archive.

Note

For information about the underlying REST API, see Delete Archive (DELETE archive).

For step-by-step instructions on how to run this example, see Running Code Examples. You need to update the code as shown with the archive ID of the archive you want to delete.

using System; using Amazon.Glacier; using Amazon.Glacier.Model; using Amazon.Runtime; namespace glacier.amazon.com.docsamples { class ArchiveDeleteLowLevel { static string vaultName = "examplevault"; static string archiveId = "*** Provide archive ID ***"; public static void Main(string[] args) { AmazonGlacierClient client; try { using (client = new AmazonGlacierClient(Amazon.RegionEndpoint.USWest2)) { Console.WriteLine("Deleting the archive"); DeleteAnArchive(client); } Console.WriteLine("Operations successful. 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(); } static void DeleteAnArchive(AmazonGlacierClient client) { DeleteArchiveRequest request = new DeleteArchiveRequest() { VaultName = vaultName, ArchiveId = archiveId }; DeleteArchiveResponse response = client.DeleteArchive(request); } } }