Skip to content

Instantly share code, notes, and snippets.

@TonyFNZ
Created October 17, 2018 22:41

Revisions

  1. TonyFNZ created this gist Oct 17, 2018.
    18 changes: 18 additions & 0 deletions url-to-s3.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    #! /bin/python

    # This script will download a file from a URL and stream it directly
    # into AWS S3 without persisting the file to local disk.
    # File is streamed as it arrives, so memory usage is low (typically <100MB)

    import boto3, urllib2

    source_url = 'http://<Your URL Here>'

    target_bucket = '<Target S3 Bucket Here>'
    target_key = '<Target S3 Filename/Key>'


    S3 = boto3.client('s3')

    file_data = urllib2.urlopen( source )
    S3.upload_fileobj(file_data, target_bucket, target_key)