AWS Code Sample
Catalog

The AWS Documentation website is getting a new look!
Try it now and let us know what you think. Switch to the new look >>

You can return to the original look by selecting English in the language selector above.

delete_archive.py

delete_archive.py demonstrates how to delete an archive from an Amazon S3 Glacier vault.

# Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # http://aws.amazon.com/apache2.0/ # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import logging import boto3 from botocore.exceptions import ClientError def delete_archive(vault_name, archive_id): """Delete an archive from an Amazon S3 Glacier vault :param vault_name: string :param archive_id: string :return: True if archive was deleted, otherwise False """ # Delete the archive glacier = boto3.client('glacier') try: response = glacier.delete_archive(vaultName=vault_name, archiveId=archive_id) except ClientError as e: logging.error(e) return False return True def main(): """Exercise delete_vault()""" # Assign these values before running the program test_vault_name = 'VAULT_NAME' test_archive_id = 'ARCHIVE_ID' # Set up logging logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(asctime)s: %(message)s') # Delete the archive success = delete_archive(test_vault_name, test_archive_id) if success: logging.info(f'Deleted archive {test_archive_id} from {test_vault_name}') if __name__ == '__main__': main()

Sample Details

Service: glacier

Last tested: 2019-2-12

Author: AWS

Type: full-example

On this page: