Setup Amazon S3 backup system using Python with BOTO in Fedora


Boto (https://github.com/boto/boto) is a must have tools when we need to communicate with Amazon Services using Python. Before we start, FYI, I use Fedora 17 in this articles. That’s mean several code may doesn’t works in your Linux OS (If we have different OS). But there are should be a minor issue since there no big difference between Linux distros. We can install this module by:

1
sudo pip-python install boto

You need AWS Access and Secret Key to be able accessing your Amazon account. You will find these values after logging in to your AWS account and clicking Account, then go to Security Credentials. Instead of defining AWS Access and Secret key each time we want to using Boto, we can put our configuration inside :

1. /etc/boto.cfg (For system-wide use)
2. ~/.boto (For spesific user use)

Here is some example with some of parts I removed (*):

1
2
3
4
5
6
7
[Credentials]
aws_access_key_id = C************F
aws_secret_access_key = 8************************w

[Boto]
debug = 2
num_retries = 10

Now we’re ready. Please open your Python intrepeter and we can start playing with Amazon S3

1. Create buckets

1
2
3
import boto
s3 = boto.connect_s3()
s3.create_bucket(‘your-name-image’)

And it will showing results:

1
2
3
4
5
6
7
8
9
send: ‘PUT / HTTP/1.1rnHost: your-host.s3.amazonaws.comrnAccept-Encoding: identityrnDate: Mon, 10 Sep 2012 07:38:34 GMTrnContent-Length: 0rnAuthorization: AWS***rnUser-Agent: Boto/2.5.2 (linux2)rnrn’
reply: ‘HTTP/1.1 200 OKrn’
header: x-amz-id-2: ***
header: x-amz-request-id: ***
header: Date: Mon, 10 Sep 2012 07:39:15 GMT
header: Location: /your-name-image
header: Content-Length: 0
header: Server: AmazonS3
Out[4]: <Bucket: your-name-images>

Now we have a new bucket that ready to get filled with whatever files / images.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.