I'm using a Lambda python script to call Elastic Transcoder on a file that I upload. How do I delete the file after transcoding?
At the moment, my code creates the job, and then deletes the source file straight away, i.e., before the job even has a chance to run. :-)
How can I wait for Elastic Transcode to finish?
import os
import boto3
import urllib
def lambda_handler(event, context):
transcoder = boto3.client('elastictranscoder', 'ap-southeast-2')
pipeline_id = get_pipeline(transcoder, 'MP4 Transcode')
base_filename = os.path.basename(event['Records'][0]['s3']['object']['key'])
output = transcoder.create_job(
PipelineId=pipeline_id,
Input={
'Key': create_aws_filename('uploads', base_filename, ''),
'FrameRate': 'auto',
'Resolution': 'auto',
'AspectRatio': 'auto',
'Interlaced': 'auto',
'Container' : 'auto'
})
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key'])
print("deleting " + key)
boto3.client('s3').delete_object(Bucket=bucket, Key=key)