Skip to content

Instantly share code, notes, and snippets.

View garnaat's full-sized avatar

Mitch Garnaat garnaat

View GitHub Profile
@garnaat
garnaat / gist:2238854
Created March 29, 2012 15:52
Example of setting the socket timeout in boto config file.
[Boto]
http_socket_timeout = 5
@garnaat
garnaat / download_keys.py
Created February 27, 2012 17:14
Dowload all of the keys in an S3 bucket with boto
import boto
import os
def download_keys(bucket_name, dst_dir):
"""
Very simple example showing how to download all keys in a bucket.
Assumes key names don't include path separators. Also assumes that
you don't have zillions of objects in the bucket. If you have a lot
you would want to get several download operations going in parallel.
"""
@garnaat
garnaat / download.py
Created February 23, 2012 22:22
Use multiprocess to download objects from S3
"""
"""
import multiprocessing
import boto
import os
import sys
import datetime
import logging
import Queue
@garnaat
garnaat / update_key.py
Created February 10, 2012 17:25
Update the content-type of an existing key in S3 using boto
import boto
s3 = boto.connect_s3()
bucket = s3.lookup('mybucket')
key = bucket.lookup('mykey')
# Copy the key onto itself, preserving the ACL but changing the content-type
key.copy(key.bucket, key.name, preserve_acl=True, metadata={'Content-Type': 'text/plain'})
key = bucket.lookup('mykey')
@garnaat
garnaat / tag_instance.py
Created February 6, 2012 11:41
Add a new/value tag to an instance
>>> import boto
>>> c = boto.connect_ec2()
>>> reservations = c.get_all_instances()
>>> reservations
[Reservation:r-b73716d6]
>>> instance = reservations[0].instances[0]
>>> instance
Instance:i-366c4354
>>> instance.tags
{}
@garnaat
garnaat / gist:1596459
Created January 11, 2012 19:57
Retrieve full Instance info from an InstanceInfo object returned by ELB
import boto
elb = boto.connect_elb()
ec2 = boto.connect_ec2()
load_balancers = elb.get_all_load_balancers()
#
# The InstanceInfo object in the LoadBalancer object contains only a small subset
# of information about the Instance. To get the full set of information, you have
@garnaat
garnaat / gist:1539859
Created December 30, 2011 13:28
Enable debug output with boto and EC2
# This will cause full debug output to go to the console
>>> import boto
>>> boto.set_stream_logger('foo')
>>> ec2 = boto.connect_ec2(debug=2)
@garnaat
garnaat / gist:1443559
Created December 7, 2011 16:52
Using get_all_instance_status method in boto
>>> import boto
>>> ec2 = boto.connect_ec2()
>>> stats = ec2.get_all_instance_status()
>>> stats
[InstanceStatus:i-67c81e0c]
>>> stat = stats[0]
>>> stat
InstanceStatus:i-67c81e0c
>>> stat.id
u'i-67c81e0c'
@garnaat
garnaat / gist:1284171
Created October 13, 2011 12:57
Connecting to Eucalyptus server in boto (assuming boto.cfg is configured properly)
$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto
>>> euca = boto.connect_euca()
>>> euca.get_all_images()
[Image:emi-DFEA10FF, Image:emi-DF0A1104, Image:emi-0CC81777, Image:emi-DF5F1113, Image:emi-DF0B1106, Image:emi-E9E51553,
...
Image:emi-169215C7, Image:emi-622216BC, Image:emi-E4C11567, Image:emi-B153146A, Image:emi-81BC1332]
@garnaat
garnaat / boto.cfg
Created October 13, 2011 12:48
Example showing Eucalyptus credentials in boto config file
[Credentials]
...
euca_access_key_id=999999999999999999999999999999999999
euca_secret_access_key=00000000000000000000000000000000000000
...
[Boto]
...
eucalyptus_host =173.205.188.130
walrus_host = 173.205.188.130
...