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.

list_vaults.py

list_vaults.py demonstrates how to list the Amazon S3 Glacier vaults owned by the AWS account.

# 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 def list_vaults(max_vaults=10, iter_marker=None): """List Amazon S3 Glacier vaults owned by the AWS account :param max_vaults: Maximum number of vaults to retrieve :param iter_marker: Marker used to identify start of next batch of vaults to retrieve :return: List of dictionaries containing vault information :return: String marking the start of next batch of vaults to retrieve. Pass this string as the iter_marker argument in the next invocation of list_vaults(). """ # Retrieve vaults glacier = boto3.client('glacier') if iter_marker is None: vaults = glacier.list_vaults(limit=str(max_vaults)) else: vaults = glacier.list_vaults(limit=str(max_vaults), marker=iter_marker) marker = vaults.get('Marker') # None if no more vaults to retrieve return vaults['VaultList'], marker def main(): """Exercise list_vaults()""" # Set up logging logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(asctime)s: %(message)s') # List the vaults vaults, marker = list_vaults() while True: # Print info about retrieved vaults for vault in vaults: logging.info(f'{vault["NumberOfArchives"]:3d} ' f'{vault["SizeInBytes"]:12d} {vault["VaultName"]}') # If no more vaults exist, exit loop, otherwise retrieve the next batch if marker is None: break vaults, marker = list_vaults(iter_marker=marker) if __name__ == '__main__': main()

Sample Details

Service: glacier

Last tested: 2019-2-12

Author: AWS

Type: full-example

On this page: