Deleting an Archive in Amazon S3 Glacier Using the Amazon SDK for Java - 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).

Deleting an Archive in Amazon S3 Glacier Using the Amazon SDK for Java

The following are the steps to delete an archive using the Amazon SDK for Java low-level API.

  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 SDK for Java with Amazon S3 Glacier.

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

The following Java code snippet illustrates the preceding steps.

AmazonGlacierClient client; DeleteArchiveRequest request = new DeleteArchiveRequest() .withVaultName("*** provide a vault name ***") .withArchiveId("*** provide an archive ID ***"); client.deleteArchive(request);


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

Example: Deleting an Archive Using the Amazon SDK for Java

The following Java code example uses the Amazon SDK for Java to delete an archive. For step-by-step instructions on how to run this example, see Running Java Examples for Amazon S3 Glacier Using Eclipse. You need to update the code as shown with a vault name and the archive ID of the archive you want to delete.

import; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import; import; public class ArchiveDelete { public static String vaultName = "*** provide vault name ****"; public static String archiveId = "*** provide archive ID***"; public static AmazonGlacierClient client; public static void main(String[] args) throws IOException { ProfileCredentialsProvider credentials = new ProfileCredentialsProvider(); client = new AmazonGlacierClient(credentials); client.setEndpoint(""); try { // Delete the archive. client.deleteArchive(new DeleteArchiveRequest() .withVaultName(vaultName) .withArchiveId(archiveId)); System.out.println("Deleted archive successfully."); } catch (Exception e) { System.err.println("Archive not deleted."); System.err.println(e); } } }