def generateThumb()

in rekognitionlambda/index.py [0:0]


def generateThumb(ourBucket, ourKey):

    # Clean the string to add the colon back into requested name
    safeKey = replaceSubstringWithColon(ourKey)

    # Define upload and download paths
    key = unquote_plus(safeKey)
    tmpkey = key.replace('/', '')
    download_path = '/tmp/{}{}'.format(uuid.uuid4(), tmpkey)
    upload_path = '/tmp/resized-{}'.format(tmpkey)

    # Download file from s3 and store it in Lambda /tmp storage (512MB avail)
    try:
        s3_client.download_file(ourBucket, key, download_path)
    except ClientError as e:
        logging.error(e)
    # Create our thumbnail using Pillow library
    resize_image(download_path, upload_path)

    # Upload the thumbnail to the thumbnail bucket
    try:
        s3_client.upload_file(upload_path, thumbBucket, safeKey)
    except ClientError as e:
        logging.error(e)

    # Be good little citizens and clean up files in /tmp so that we don't run out of space
    os.remove(upload_path)
    os.remove(download_path)

    return