Delete an Archive from a Vault in Amazon S3 Glacier Using the AWS SDK for Java - Amazon S3 Glacier

Delete an Archive from a Vault in Amazon S3 Glacier Using the AWS SDK for Java

The following code example uses the AWS SDK for Java to delete the archive. In the code, note the following:

  • The DeleteArchiveRequest object describes the delete request, including the vault name where the archive is located and the archive ID.

  • The deleteArchive method sends the request to Amazon S3 Glacier (S3 Glacier) to delete the archive.

  • The example uses the US West (Oregon) Region (us-west-2) to match the location where you created the vault in Step 2: Create a Vault in Amazon S3 Glacier.

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 the archive ID of the file you uploaded in Step 3: Upload an Archive to a Vault in Amazon S3 Glacier.

Example — Deleting an Archive Using the AWS SDK for Java

import; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import; import; public class AmazonGlacierDeleteArchive_GettingStarted { public static String vaultName = "examplevault"; 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); } } }