S3 上传上的 Amazon Transcribe:“[错误] BadRequestException:提供的 URI 未指向 S3 对象”

问题描述 投票:0回答:2

我正在尝试使用 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󖅪

python amazon-web-services amazon-s3 aws-lambda amazon-transcribe
2个回答
3
投票

使用这种格式对我有用:

Media={
    'MediaFileUri': f'https://s3-us-west-2.amazonaws.com/{BUCKET}/{KEY}'
},

0
投票

此错误可能还有其他 2 个原因。

1- OutputBucketName:大多数情况下都会处理输入存储桶,但如果 OutputBucketName 为空或接收到复制粘贴代码且仅写入输出,则可能会遇到相同的错误

2- 权限:应检查输入和输出的权限。默认情况下,公共访问是不可能的

© www.soinside.com 2019 - 2024. All rights reserved.