Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2013 06:27
What would you like to do?
This is a python class wrapped around a number of common boto methods that I use to access AWS. Makes the code a little cleaner and abstracts away the details of making the connection to aws. At the moment it only contains methods to push and pull data to S3. WIll most likely add a method to retrieve a list files in a S3 bucket, and possibly add…
import boto
import boto.s3.connection
# should contain the access_key and secret_key which are needed for
# the boto S3 connection
import credentials as cr
class AwsConnect(object):
def __init__(self, bucket):
self.bucket = bucket
# Connect to S3
def connect(self):
conn = boto.connect_s3(
aws_access_key_id = cr.access_key,
aws_secret_access_key = cr.secret_key,
host = '',
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
# Connect to bucket
self.cbucket = conn.get_bucket(self.bucket)
def pull(self, filepathin, filepathout):
key = self.cbucket.get_key(filepathin)
def push(self, filepathin, filepathout):
key = self.cbucket.new_key(filepathin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment