You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PreSignedURL调用Amazon Transcribe时S3对象URI异常求助

问题:使用预签名URL调用Amazon Transcribe时提示URI未指向S3对象

我在通过PreSignedURL访问Amazon AWS S3文件并调用Amazon Transcribe时遇到异常,虽然生成的预签名URL能在浏览器正常下载文件,但调用Transcribe时抛出了System.AggregateException。

生成预签名URL的代码

GetPreSignedUrlRequest getPreSignedUrlRequest = new GetPreSignedUrlRequest 
{ 
    BucketName = bucketName, 
    Key = fileKey, 
    Verb = HttpVerb.GET, 
    Expires = DateTime.Now.AddMinutes(5) 
}; 
Uri signedUrl = new Uri(new AmazonS3Client( 
    Credentials.GetCredentials(), 
    RegionEndpoint.USEast1) 
.GetPreSignedURL(getPreSignedUrlRequest));

调用Amazon Transcribe的代码

AmazonTranscribeServiceClient amazonTSClient = new AmazonTranscribeServiceClient( 
    Credentials.GetCredentials(), 
    RegionEndpoint.USEast1); 
StartTranscriptionJobRequest transcriptionJobRequest = new StartTranscriptionJobRequest 
{ 
    TranscriptionJobName = transcriptionJobName, 
    Media = new Media { MediaFileUri = signedUrl }, 
    MediaFormat = MediaFormat.Flac, 
    LanguageCode = "en-us", 
    Settings = new Settings { MaxSpeakerLabels = 2 } 
}; 
Task<StartTranscriptionJobResponse> transcriptionJobResponseTask = amazonTSClient.StartTranscriptionJobAsync(transcriptionJobRequest); 
transcriptionJobResponseTask.Wait(); // 此处抛出System.AggregateException

异常详情

System.AggregateException: 'One or more errors occurred. (The URI that you provided doesn't point to an S3 object. Make sure that the object exists and try your request again.)'

我已尝试用生成的URL在浏览器中访问文件,可正常下载。请问问题可能出在哪里?


问题分析与解决方案

核心原因:Transcribe不支持预签名URL访问S3对象

Amazon Transcribe作为AWS内部服务,无法直接使用S3预签名URL来读取文件。预签名URL是给外部客户端(比如浏览器、移动端APP)使用的临时授权凭证,Transcribe不会解析URL中的签名参数,它只会识别标准的S3对象路径,并且通过IAM权限直接访问S3资源。

正确的实现方式

你需要把MediaFileUri替换为S3对象的标准路径格式:s3://<bucket-name>/<file-key>,修改后的代码如下:

StartTranscriptionJobRequest transcriptionJobRequest = new StartTranscriptionJobRequest 
{ 
    TranscriptionJobName = transcriptionJobName, 
    Media = new Media { MediaFileUri = $"s3://{bucketName}/{fileKey}" }, // 改为标准S3路径
    MediaFormat = MediaFormat.Flac, 
    LanguageCode = "en-us", 
    Settings = new Settings { MaxSpeakerLabels = 2 } 
};

补充:确保IAM权限配置正确

同时要保证你创建AmazonTranscribeServiceClient时使用的IAM凭证(或角色)拥有以下权限:

  • s3:GetObject:针对目标S3桶和具体文件的读取权限
  • transcribe:StartTranscriptionJob:启动转录任务的权限

如果使用IAM角色,还需要在角色的信任策略中允许transcribe.amazonaws.com服务扮演该角色,确保Transcribe能通过角色权限访问S3资源。

为什么浏览器能访问但Transcribe不行?

浏览器访问预签名URL时,会自动携带URL中的签名参数完成身份验证;而Transcribe在处理请求时,只会校验自身的IAM权限,不会解析预签名URL里的临时授权信息,所以对它来说,预签名URL就是一个不符合格式的无效路径。

内容的提问来源于stack exchange,提问作者Jeankowkow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:23:38