lambda_1.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. import json
  2. #Create an s3 bucket with the command below after configuing the CLI
  3. import boto3
  4. #Create low level clients for s3 and Transcribe
  5. s3 = boto3.client('s3')
  6. transcribe = boto3.client('transcribe')
  7. def lambda_handler(event, context):
  8. # TODO implement
  9. for record in event['Records']:
  10. file_bucket = record['s3']['bucket']['name']
  11. file_name = record['s3']['object']['key']
  12. print(file_bucket, file_name)
  13. if file_name.find(".wav") == -1:
  14. continue
  15. object_url = f"https://s3.amazonaws.com/{file_bucket}/{file_name}"
  16. print(object_url)
  17. response = transcribe.start_transcription_job(
  18. TranscriptionJobName=file_name.replace('/', '-'),
  19. LanguageCode='ko-KR',
  20. MediaFormat='wav',
  21. Media={
  22. 'MediaFileUri': object_url
  23. })
  24. print(response)
  25. return {
  26. 'statusCode': 200,
  27. 'body': json.dumps('Hello from Lambda!')
  28. }