Skip to content

Instantly share code, notes, and snippets.

Embed
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
# credentials.py 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
self.connect()
# 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 = 's3-us-west-2.amazonaws.com',
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)
key.get_contents_to_filename(filepathout)
def push(self, filepathin, filepathout):
key = self.cbucket.new_key(filepathin)
key.set_contents_from_filename(filepathout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.