Skip to content

Instantly share code, notes, and snippets.

@exarkun
Created July 11, 2017 12:41
Show Gist options
  • Save exarkun/4a6983028e4eed480f5d033a96f61f40 to your computer and use it in GitHub Desktop.
Save exarkun/4a6983028e4eed480f5d033a96f61f40 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function, unicode_literals
from sys import argv
from datetime import datetime, timedelta
from twisted.internet.defer import inlineCallbacks
from twisted.internet.task import react
from txaws.service import AWSServiceRegion
@inlineCallbacks
def main(reactor, bucket, age):
age = int(age)
starting_time = datetime.utcnow() - timedelta(hours=age)
marker = starting_time.strftime("/%Y%m%d%H_0.gz")
region = AWSServiceRegion()
s3 = region.get_s3_client()
listing = yield s3.get_bucket(bucket, marker=marker)
for item in listing.contents:
obj = yield s3.get_object(bucket, item.key)
print(obj)
if __name__ == '__main__':
react(main, argv[1:])
listed
main function encountered error
Traceback (most recent call last):
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 459, in callback
self._startRunCallbacks(result)
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 567, in _startRunCallbacks
self._runCallbacks()
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1442, in gotResult
_inlineCallbacks(r, g, deferred)
--- <exception caught here> ---
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 1384, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/python/failure.py", line 393, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "./ops/tail-logs", line 24, in main
obj = yield s3.get_object(bucket, item.key)
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 653, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/txaws/s3/client.py", line 56, in s3_error_wrapper
error_wrapper(error, S3Error)
File "/home/exarkun/Environments/leastauthority.com/local/lib/python2.7/site-packages/txaws/client/base.py", line 75, in error_wrapper
raise fallback_error
txaws.s3.exception.S3Error: Error Message: The specified key does not exist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment