我正在对一组媒体文件尝试 Amazon Transcribe,调整示例文档代码并使用本系列作为参考,以适应任何上传到我指定的媒体 S3 文件夹的内容,但我的测试文件存在问题。
上传存储桶/文件夹路径:
'MediaFileUri': https://us-west-2.console.aws.amazon.com/s3/buckets/upload-asr/mediaupload/file.mp4
我已验证该文件存在并且存储桶权限授予对 Amazon Transcribe 服务的访问权限。我可以使用相同的 URL 启动手动转录作业,但不能使用 SDK:我还使用上面的路径将它直接链接到函数中,但没有结果。我很欣赏这可能是一个 URL 路径问题,但没有看到太多关于该主题的内容,因此请检查是否存在明显错误。
import json
import time
import boto3
from urllib.request import urlopen
def lambda_handler(event, context):
transcribe = boto3.client("transcribe")
s3 = boto3.client("s3")
if event:
file_obj = event["Records"][0]
bucket_name = str(file_obj['s3']['bucket']['name'])
file_name = str(file_obj['s3']['object']['key'])
file_type = file_name.split(".")[1]
s3_uri = create_uri(bucket_name, file_name)
job_name = context.aws_request_id
transcribe.start_transcription_job(TranscriptionJobName = job_name,
Media = {'MediaFileUri': s3_uri},
OutputBucketName = "bucket-name",
MediaFormat = file_type,
LanguageCode = "en-US")
def create_uri(bucket_name, file_name):
CloudWatch 日志失败报告:
[ERROR] BadRequestException: An error occurred (BadRequestException) when calling the StartTranscriptionJob operation:
The URI that you provided doesn't point to an S3 object. Make sure that the object exists and try your request again.
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 25, in lambda_handler
LanguageCode = "en-US")
File "/var/runtime/botocore/client.py", line 320, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/var/runtime/botocore/client.py", line 623, in _make_api_call
raise error_class(parsed_response, operation_name)
类似: https ://forums.aws.amazon.com/thread.jspa?messageID=876906慪