import json
#Create an s3 bucket with the command below after configuing the CLI
import boto3
#Create low level clients for s3 and Transcribe
s3  = boto3.client('s3')
transcribe = boto3.client('transcribe')

def lambda_handler(event, context):
    # TODO implement
    for record in event['Records']:
        file_bucket = record['s3']['bucket']['name']
        file_name = record['s3']['object']['key']
        
        print(file_bucket, file_name)
        if file_name.find(".wav") == -1:
            continue
        
        object_url = f"https://s3.amazonaws.com/{file_bucket}/{file_name}"
        
        print(object_url)
        
        response = transcribe.start_transcription_job(
                TranscriptionJobName=file_name.replace('/', '-'),
                LanguageCode='ko-KR',
                MediaFormat='wav',
                Media={
                    'MediaFileUri': object_url
                })
        print(response)
        
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }