python - Amazon Transcribe on S3 Upload:“[错误] BadRequestException:提供的 URI 未指向 S3 对象”
问题描述
我正在对一组媒体文件尝试 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慪
解决方案
它适用于我使用这种格式:
Media={
'MediaFileUri': f'https://s3-us-west-2.amazonaws.com/{BUCKET}/{KEY}'
},
推荐阅读
- java - 版本号指标
- python - 抓取和提取多个元素
- r - 带有 R 3.5.1 的 OpenCPU
- python - python:在numpy.ndarray中返回最小值
- sql - 使用插入语句进行转换的问题
- zapier - Zapier Trigger:从动态下拉列表中删除“其他选项”
- azure - 调试 Azure 函数 - 找不到 VoidMethodInvoker.cs
- javascript - 如何通过 Javascript 编辑这个特定类的 href?
- javascript - Konva 文本边界
- .net - 如何在 Windows / .NET 中找出默认的度量单位系统(英制或公制)?