Use DeleteArchive with an Amazon SDK or CLI - 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.

Use DeleteArchive with an Amazon SDK or CLI

The following code examples show how to use DeleteArchive.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

CLI
Amazon CLI

To delete an archive from a vault

The following delete-archive example removes the specified archive from example_vault.

aws glacier delete-archive \ --account-id 111122223333 \ --vault-name example_vault \ --archive-id Sc0u9ZP8yaWkmh-XGlIvAVprtLhaLCGnNwNl5I5x9HqPIkX5mjc0DrId3Ln-Gi_k2HzmlIDZUz117KSdVMdMXLuFWi9PJUitxWO73edQ43eTlMWkH0pd9zVSAuV_XXZBVhKhyGhJ7w

This command produces no output.

  • For API details, see DeleteArchive in Amazon CLI Command Reference.

Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.glacier.GlacierClient; import software.amazon.awssdk.services.glacier.model.DeleteArchiveRequest; import software.amazon.awssdk.services.glacier.model.GlacierException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DeleteArchive { public static void main(String[] args) { final String usage = """ Usage: <vaultName> <accountId> <archiveId> Where: vaultName - The name of the vault that contains the archive to delete. accountId - The account ID value. archiveId - The archive ID value. """; if (args.length != 3) { System.out.println(usage); System.exit(1); } String vaultName = args[0]; String accountId = args[1]; String archiveId = args[2]; GlacierClient glacier = GlacierClient.builder() .region(Region.US_EAST_1) .build(); deleteGlacierArchive(glacier, vaultName, accountId, archiveId); glacier.close(); } public static void deleteGlacierArchive(GlacierClient glacier, String vaultName, String accountId, String archiveId) { try { DeleteArchiveRequest delArcRequest = DeleteArchiveRequest.builder() .vaultName(vaultName) .accountId(accountId) .archiveId(archiveId) .build(); glacier.deleteArchive(delArcRequest); System.out.println("The archive was deleted."); } catch (GlacierException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } } }
  • For API details, see DeleteArchive in Amazon SDK for Java 2.x API Reference.

Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

class GlacierWrapper: """Encapsulates Amazon S3 Glacier API operations.""" def __init__(self, glacier_resource): """ :param glacier_resource: A Boto3 Amazon S3 Glacier resource. """ self.glacier_resource = glacier_resource @staticmethod def delete_archive(archive): """ Deletes an archive from a vault. :param archive: The archive to delete. """ try: archive.delete() logger.info( "Deleted archive %s from vault %s.", archive.id, archive.vault_name ) except ClientError: logger.exception("Couldn't delete archive %s.", archive.id) raise
  • For API details, see DeleteArchive in Amazon SDK for Python (Boto3) API Reference.

For a complete list of Amazon SDK developer guides and code examples, see Using S3 Glacier with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.