簡體   English   中英

S3 上傳時的 Amazon Transcribe:“[錯誤] BadRequestException:提供的 URI 未指向 S3 對象”

[英]Amazon Transcribe on S3 Upload: "[ERROR] BadRequestException: URI provided doesn't point to an S3 object"

我正在對一系列媒體文件嘗試使用 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 &# 876906

它使用這種格式對我有用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM