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).
Delete an Amazon S3 Glacier archive using an Amazon SDK
The following code examples show how to delete an Amazon S3 Glacier archive.
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:
- Java
-
- SDK for Java 2.x
-
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 vault was deleted!");
} catch(GlacierException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
- Python
-
- SDK for Python (Boto3)
-
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 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.