#!/usr/bin/python import urllib import tempfile import shutil import subprocess import boto3 import os def lambda_handler(event, context): tmpd = tempfile.mkdtemp() # fetch movie movie_url = event['movie_url'] movie_file = os.path.join(tmpd, os.path.basename(movie_url)) urllib.urlretrieve(movie_url,movie_file) # motion analysis print subprocess.check_output([ "bin/max-movement-lk.py", movie_file]) # generate montage print subprocess.check_output([ "bin/mk-montage.py",tmpd]) # store montage in s3 s3 = boto3.resource('s3') bucket = "snapshot.linux-magazin.de" data = open(os.path.join( tmpd,'montage.jpg')).read() s3.Bucket(bucket).put_object( Key="montage.jpg", Body=data,ContentType="image/jpeg") result = { "montage_url": "https://s3-us-west-2.amazonaws.com" + "/snapshot.linux-magazin.de/" + "montage.jpg"} shutil.rmtree(tmpd) return result