def lambda_handler(event, context):
LOGGER.debug("Received event: " + json.dumps(event, indent=2))
n_fail = 0
n_succ = 0
recs = event['Records']
tp = ThreadPool(min(len(recs),20))
try:
recs = [event_to_dynamo_images(x) for x in recs]
rc = tp.map_async(check_remove_queue,recs)
# identities can be bulk-deleted in groups of 60 via AWS API, so handle in this thread
check_remove_identities(recs)
rc.wait(max(context.get_remaining_time_in_millis()/1000.0 - 2.0,0))
if not rc.ready():
LOGGER.error("Timeout waiting on processors")
tp.terminate()
else:
n_del = len([x for x in rc.get() if x])
LOGGER.info("Processed {0} records, {1} queues deleted".format(len(recs),n_del))
finally:
tp.close()
评论列表
文章目录