Last active
January 30, 2019 23:16
-
-
Save akarve/f6401f33635f6cde342381ca7cf46c92 to your computer and use it in GitHub Desktop.
This file contains 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
def handler(event, context): | |
for record in event['Records']: | |
try: | |
response = S3_CLIENT.get_object(Bucket=bucket, Key=key) | |
eventname = record['eventName'] | |
bucket = unquote(record['s3']['bucket']['name']) | |
if eventname == 'ObjectRemoved:Delete': | |
event_type = 'Delete' | |
post_to_es(event_type, 0, '', key, {}) | |
continue | |
elif eventname == 'ObjectCreated:Put': | |
event_type = 'Create' | |
key = unquote(record['s3']['object']['key']) | |
if key.endswith('.ipynb') and config['ipynb']: | |
try: | |
notebook = response['Body'].read().decode('utf-8') | |
text = extract_text(notebook) | |
post_to_es(event_type, size, text, key, meta, version_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment