Skip to content

Instantly share code, notes, and snippets.

@akarve
Last active January 30, 2019 23:16
Show Gist options
  • Save akarve/f6401f33635f6cde342381ca7cf46c92 to your computer and use it in GitHub Desktop.
Save akarve/f6401f33635f6cde342381ca7cf46c92 to your computer and use it in GitHub Desktop.
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