Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Forked from makuk66/s3-download.py
Created May 31, 2013 23:36

Revisions

  1. @makuk66 makuk66 revised this gist Jan 30, 2013. 1 changed file with 16 additions and 11 deletions.
    27 changes: 16 additions & 11 deletions s3-download.py
    Original file line number Diff line number Diff line change
    @@ -3,22 +3,27 @@
    # s3-download.py - a quick-and-dirty download script to download from S3
    # implemented using Boto, which automatically applies AWS IAM role credentials
    #
    # This code is distributed under the MIT license from http://opensource.org/licenses/MIT:
    # This code is distributed under the MIT license from
    # http://opensource.org/licenses/MIT:
    #
    # Copyright (c) 2013 Martijn Koster
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
    # documentation files (the "Software"), to deal in the Software without restriction, including without limitation
    # the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
    # and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    # copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all copies or substantial portions
    # of the Software.
    # The above copyright notice and this permission notice shall be included in
    # all copies or substantial portions of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
    # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
    # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    # DEALINGS IN THE SOFTWARE.

    import urllib2
  2. @makuk66 makuk66 revised this gist Jan 30, 2013. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions s3-download.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,26 @@
    #!/usr/bin/env python
    #
    # s3-download.py - a quick-and-dirty download script to download from S3
    # implemented using Boto, which automatically applies AWS IAM role credentials
    #
    # This code is distributed under the MIT license from http://opensource.org/licenses/MIT:
    #
    # Copyright (c) 2013 Martijn Koster
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
    # documentation files (the "Software"), to deal in the Software without restriction, including without limitation
    # the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
    # and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in all copies or substantial portions
    # of the Software.
    #
    # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
    # TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
    # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    # DEALINGS IN THE SOFTWARE.

    import urllib2
    import boto
    import re
  3. @makuk66 makuk66 revised this gist Jan 14, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion s3-download.py
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    installer_jar=sys.argv[2]
    r=re.search('s3://([^/]+)(.*)', s3_url)
    if r == None:
    aise "Malformed S3 URL"
    raise "Malformed S3 URL"
    s3_bucket=r.group(1)
    s3_path=r.group(2)

  4. @makuk66 makuk66 created this gist Jan 14, 2013.
    23 changes: 23 additions & 0 deletions s3-download.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    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:
    aise "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)