working on it ...

Filters

snippets
18
followers
23
Published by lbottaro

Amazon AWS Python

The channel contains snippets on how to interact with Amazon Web Service using python API
Sort by

Found 18 snippets

    public by lbottaro @ Amazon_AWS_Python_API  5089  1  8  0

    How To Create A Connection To Amazon S3 Aws with Boto using connect_s3 method

    This snippet focuses on the Simple Storage Service from Amazon Web Services, using the connect_s3 method provided by python boto interface. Learn more on boto API : [https://github.com/boto/boto](https://github.com/boto/boto) Find out Amazon AWS tutorial: [http://boto.s3.amazonaws.com/s3\_tut.html](http://boto.s3.amazonaws.com/s3\_tut.html)
    import boto
    conn = boto.connect_s3()
    # connect_s3() will return the S3Connection object.
    # conn will point to your S3Connection object, ready to interact with your AWS account

    public by micurs  2672  0  6  1

    Upload a file into a S3 bucket in Python

    Uploading a local file into S3 using the Boto library is pretty simple. In this example we upload the localFilepath into a destS3Name location in the destBucket. Here is the snippet:
    s3Link = S3Connection()
    s3Bucket = s3Link.get_bucket(destBucket)
    
    newItem = s3Bucket.new_key(destS3Name)
    newItem.set_contents_from_filename(localFilepath)
    
    

    public by micurs  3432  1  7  0

    Connecting to S3 using boto

    In this example we assume you set your Amazon credentials ( WS\_ACCESS\_KEY\_ID and AWS\_SECRET\_ACCESS\_KEY ) as environment variables or in the [boto config file](https://code.google.com/p/boto/wiki/BotoConfig)
    # Method 1
    import boto
    conn = boto.connect_s3()
    
    # Method 2
    from boto.s3.connection import S3Connection
    conn = S3Connection()
    

    public by lbottaro @ Amazon_AWS_Python_API  3541  3  8  0

    How To Create A Connection To Amazon S3 Aws with Boto using S3Connection object

    This snippet focuses on the Simple Storage Service from Amazon Web Services, using the S3Connection object provided by python boto interface. Learn more on boto API : [https://github.com/boto/boto](https://github.com/boto/boto) Find out Amazon AWS tutorial: [http://boto.s3.amazonaws.com/s3\_tut.html](http://boto.s3.amazonaws.com/s3\_tut.htm
    from boto.s3.connection import S3Connection
    # Setup S3 connection
    conn = S3Connection('<aws access key>', '<aws secret key>')
    # conn will point to your S3Connection object, ready to interact with your AWS account
    

    public by lbottaro @ Amazon_AWS_Python_API  6135  1  8  1

    Amazon S3 Aws - get_bucket method in boto python API

    This example shows how to get a single key from a bucket and then write that key to a file.
    from boto.s3.connection import S3Connection
    from boto.s3.key import Key
    
    # Get connection using Amazon secret and access keys
    conn = S3Connection('<aws secret key>', '<aws access key>')
    
    # Get the bucket with name 'bucketname'
    bucket = conn.get_bucket('bucketname')
    
    # Get the key reference to file 'picture.jpg'
    key = bucket.get_key("picture.jpg")
    
    # Open file in write mode
    fp = open ("picture.jpg", "w")
    
    # Set the reference to file
    key.get_file (fp)

    public by lbottaro @ Amazon_AWS_Python_API  3615  4  7  0

    Amazon S3 Aws - Listing Owned Buckets using boto api

    This code returns a list of Buckets that you own, invoking get\_all\_buckets() method. For each bucket you can get name and creation date.
    import boto
    import boto.s3.connection
    access_key = 'put your access key here!'
    secret_key = 'put your secret key here!'
    
    # Setup Amazon S3 connection
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration on all buckets get from get_all_buckets() method
    # For each bucket object the name and creation date is shown
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )

    public by lbottaro @ Amazon_AWS_Python_API  6270  3  8  0

    Amazon S3 Aws - How to get content information for a given bucket using boto python api

    This snippet shows how to iterate through your own Amazon S3 buckets and list the available content.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration through all available buckets stored into S3
    # Name and creation date are listed
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )
            # For each bucket get all data content put into the bucket
            for key in bucket.list():
                    # Get name, size and date
                    print "{name}\t{size}\t{modified}".format(
                            name = key.name,
                            size = key.size,
                            modified = key.last_modified,
                            )

    public by lbottaro @ Amazon_AWS_Python_API  3192  1  8  1

    Amazon S3 Aws - How to delete a file from a bucket

    This code shows how to delete an object from an existing bucket, using boto python API.
    # This call deletes the file pippo.txt
    bucket.delete_key('pippo.txt')

    public by lbottaro @ Amazon_AWS_Python_API  6432  19  8  1

    Amazon S3 Aws - How to delete a bucket using boto API

    This example shows how to remove a bucket invoking python API provided by boto. Important note: the bucket must be empty.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # Iteration through all available buckets stored into S3
    # Name and creation date are listed
    for bucket in conn.get_all_buckets():
            print "{name}\t{created}".format(
                    name = bucket.name,
                    created = bucket.creation_date,
            )
            # Remove the bucket
            conn.delete_bucket(bucket.name)

    public by lbottaro @ Amazon_AWS_Python_API  4590  1  8  2

    Amazon S3 Aws - Creating a bucket in python

    This code shows how to create a new bucket using boto API on a S3 Amazon account. Please note that the name of the bucket must be unique, different from any other bucket existing in Amazon S3 storage. For this reason you can add some random value to make it unique.
    import boto
    import boto.s3.connection
    access_key = '<aws access key>'
    secret_key = '<aws secret key>'
    
    # This code initialize the Amazon S3 connection to your account
    conn = boto.connect_s3(
            aws_access_key_id = access_key,
            aws_secret_access_key = secret_key)
    
    # This creates a new bucket called myBucket
    bucket = conn.create_bucket('myBucket')
    • Public Snippets
    • Channels Snippets