Skip to content

Instantly share code, notes, and snippets.

@marcintustin
Created April 5, 2017 18:37
Show Gist options
  • Select an option

  • Save marcintustin/1b46199041a09ee6009c050c83c7a405 to your computer and use it in GitHub Desktop.

Select an option

Save marcintustin/1b46199041a09ee6009c050c83c7a405 to your computer and use it in GitHub Desktop.
Boto3 S3 constant batch example
import boto3
BATCH_SIZE = 1024
s3 = boto3.resource('s3')
s3_object = s3.Object('test-bucket', 'example_object')
stream = s3_object.get()['Body']
batch = stream.read(BATCH_SIZE)
while batch:
result = do_some_work(batch)
batch = stream.read(BATCH_SIZE)
@marcintustin

Copy link
Copy Markdown
Author

Note this code is not tested, and contains a free reference to the function do_some_work.

The problem with this approach is that you have to be able to deal with fixed sized chunks, so you'll need some buffering in there to find actual record boundaries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment