Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Forked from makuk66/s3-download.py
Created May 31, 2013 23:36
Show Gist options
  • Save mostlygeek/5688650 to your computer and use it in GitHub Desktop.
Save mostlygeek/5688650 to your computer and use it in GitHub Desktop.
import urllib2
import boto
import re
import sys
from boto.s3.key import Key
if len(sys.argv) != 3:
print "Usage: s3-download.py s3://bucket/path localfile"
sys.exit(-1)
s3_url=sys.argv[1]
installer_jar=sys.argv[2]
r=re.search('s3://([^/]+)(.*)', s3_url)
if r == None:
raise "Malformed S3 URL"
s3_bucket=r.group(1)
s3_path=r.group(2)
c = boto.connect_s3()
b = c.get_bucket(s3_bucket)
k = Key(b)
k.key = s3_path
print "downloading from S3 {0} to {1}".format(s3_url, installer_jar)
k.get_contents_to_filename(installer_jar)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment