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.

create_vault.py

create_vault.py demonstrates how to create 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 create_vault(vault_name): """Create an Amazon Glacier vault. :param vault_name: string :return: glacier.Vault object if vault was created, otherwise None """ glacier = boto3.resource('glacier') try: vault = glacier.create_vault(vaultName=vault_name) except ClientError as e: logging.error(e) return None return vault def main(): """ Exercise create_vault()""" # Assign this value before running the program test_vault_name = 'VAULT_NAME' # Set up logging logging.basicConfig(level=logging.DEBUG, format='%(levelname)s: %(asctime)s: %(message)s') # Create the Glacier vault vault = create_vault(test_vault_name) if vault is not None: logging.info(f'Created vault {vault.name}') if __name__ == '__main__': main()

Sample Details

Service: glacier

Last tested: 2019-2-12

Author: AWS

Type: full-example

On this page: