Created
April 5, 2017 18:37
-
-
Save marcintustin/1b46199041a09ee6009c050c83c7a405 to your computer and use it in GitHub Desktop.
Boto3 S3 constant batch example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.