working on it ...

Filters

Explore Public Snippets

Sort by

Found 15 snippets matching: "amazon web services python"

    public by fabio.nosenzo @ Amazon_AWS_Python_API  588162  5  8  -1

    Amazon S3 Aws - S3Connection object from python boto API

    This snippet is about the S3Connection object provided by python boto package for Amazon AWS API. Here the __init__ method is listed with all its variables. The AWSAuthConnection object is initialized and it handles all the data for managing requests and response from Amazon AWS service. Path: [boto/s3/connection.py] Learn more about S3Con
    import boto.utils
    from boto.connection import AWSAuthConnection
    
    class S3Connection(AWSAuthConnection):
        DefaultHost = boto.config.get('s3', 'host', 's3.amazonaws.com')
        DefaultCallingFormat = boto.config.get('s3', 'calling_format', 'boto.s3.connection.SubdomainCallingFormat')
        QueryString = 'Signature=%s&Expires=%d&AWSAccessKeyId=%s'
    
        def __init__(self, aws_access_key_id=None, aws_secret_access_key=None,
                     is_secure=True, port=None, proxy=None, proxy_port=None,
                     proxy_user=None, proxy_pass=None,
                     host=DefaultHost, debug=0, https_connection_factory=None,
                     calling_format=DefaultCallingFormat, path='/',
                     provider='aws', bucket_class=Bucket, security_token=None,
                     suppress_consec_slashes=True, anon=False,
                     validate_certs=None):
            if isinstance(calling_format, str):
                calling_format=boto.utils.find_class(calling_format)()
            self.calling_format = calling_format
            self.bucket_class = bucket_class
            self.anon = anon
            AWSAuthConnection.__init__(self, host,
                    aws_access_key_id, aws_secret_access_key,
                    is_secure, port, proxy, proxy_port, proxy_user, proxy_pass,
                    debug=debug, https_connection_factory=https_connection_factory,
                    path=path, provider=provider, security_token=security_token,
                    suppress_consec_slashes=suppress_consec_slashes,
                    validate_certs=validate_certs)

    public by lbottaro @ Amazon_AWS_Python_API  304432  0  8  0

    Amazon S3 Aws - How to download a file from a bucket to a target directory

    This code shows how to download a file from an existing bucket invoking the boto python API, saving to a target directory. You need to specify the filename and path where to save the data. [How to create a bucket](http://www.snip2code.com/Snippet/4892/Amazon-Aws-S3---Creating-a-bucket-in-pyt) [How to upload a file to a bucket](http://www.sn
    # This downloads the object foobar.pdf and saves it in /home/luca/documents/
    
    key = bucket.get_key('foobar.pdf')
    key.get_contents_to_filename('/home/luca/documents/foobar.pdf')

    public by lbottaro @ Amazon_AWS_Python_API  10725  32  8  0

    Amazon S3 Aws - Change an object's acl using boto API

    This code shows how to change the access rights on a file uploaded on S3 storage. This example sets the object foo_bar.txt to be publicly readable, and secret.txt to be private. Supported acl values defined in boto.gs.acl.py. CannedACLStrings = ['private', 'public-read', 'project-private', 'public-read-write', 'authenticated-read', 'buc
    # Public ACL example
    # Here you get the key reference for file foo_bar.txt
    foo_bar_key = bucket.get_key('foo_bar.txt')
    # This set the foo_bar file publicly readable
    foo_bar_key.set_canned_acl('public-read')
    
    # Private ACL example
    # Here you get the key reference for file secret.txt
    secret_key = bucket.get_key('secret.txt')
    # This set the secret.txt file as private
    secret_key.set_canned_acl('private')

    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  6267  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  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  5976  1  8  1

    Amazon S3 Aws - Generate signed object download URLs

    This python code generates signed URL to download a private file from Amazon S3 storage, invoking boto API. Note that this generates a signed download URL for secret_plans.txt that will work for 1 hour (3600 seconds). Signed download URLs will work for the time period even if the object is private (when the time period is up, the URL will stop w
    # Get the private key reference to secret_plans.txt file
    plans_key = bucket.get_key('secret_plans.txt')
    # Generate a signed URL, timer is set to 1 hour
    plans_url = plans_key.generate_url(3600, query_auth=True, force_http=True)
    print plans_url

    public by lbottaro @ Amazon_AWS_Python_API  5466  5  8  1

    Amazon S3 Aws - Generate unsigned object download URLs

    This python code generates unsigned URL to download a public file from Amazon S3 storage. Note that unsigned URL can be generated for object with public acl.
    # Create an unsigned download URL for hello.txt. 
    # Requirements:
    # file hello.txt is public by setting its ACL 
    
    # Get hello.txt file key from bucket
    hello_key = bucket.get_key('hello.txt')
    # Create the unsigned URL
    hello_url = hello_key.generate_url(0, query_auth=False, force_http=True)
    print hello_url
    

    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 lbottaro @ Amazon_AWS_Python_API  4589  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