Upload image available at public URL to S3 using boto

后端 未结 9 1311
广开言路
广开言路 2020-12-23 13:48

I\'m working in a Python web environment and I can simply upload a file from the filesystem to S3 using boto\'s key.set_contents_from_filename(path/to/file). However, I\'d l

9条回答
  •  余生分开走
    2020-12-23 14:47

    A simple 3-lines implementation that works on a lambda out-of-the-box:

    import boto3
    import requests
    
    s3_object = boto3.resource('s3').Object(bucket_name, object_key)
    
    with requests.get(url, stream=True) as r:
        s3_object.put(Body=r.content)
    

    The source for the .get part comes straight from the requests documentation

提交回复
热议问题