Using boto, I was able to download just a subset of a file from Amazon s3. Given an s3 key, I specified the start and stop bytes and passed them into the get_contents_as_string
call.
# Define bytes to focus on
headers={'Range' : 'bytes={}-{}'.format(start_byte, stop_byte)}
resp = key.get_contents_as_string(headers=headers)
Is there a way to accomplish the same task in boto3?
In the Amazon S3 console, choose your S3 bucket, choose the file that you want to open or download, choose Actions, and then choose Open or Download. If you are downloading an object, specify where you want to save it.
Download multiple files from AWS CloudShell using Amazon S3 Now you need to download the contents of the bucket to your local machine. Because the Amazon S3 console doesn't support the downloading of multiple objects, you need to use the AWS CLI tool that's installed on your local machine.
You can use the same Range
parameter in get_object()
method:
s3 = boto3.client('s3')
resp = s3.get_object(Bucket='bucket', Range='bytes={}-{}'.format(start_byte, stop_byte))
content = resp['Body']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With