【发布时间】:2020-10-08 06:02:53
【问题描述】:
我正在执行以下 AWS Lambda 函数:
import json
import urllib.parse
import boto3
print('Loading function')
s3 = boto3.client('s3')
transcribe = boto3.client('transcribe')
#DOCUMENTATION : https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/transcribe.html#TranscribeService.Client.start_transcription_job
def lambda_handler(event, context):
# 1 - Get the bucket name
bucket = event['Records'][0]['s3']['bucket']['name']
# 2 - Get the file/key name
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
media_uri = "s3://aws-support-ml-demo-bucket/SampleInboundCall2.mp3"
try:
response = transcribe.start_transcription_job(
TranscriptionJobName='thisjobiscomming-from-lambda',
LanguageCode='en-US',
MediaSampleRateHertz=8000,
MediaFormat='mp3',
Media={
'MediaFileUri': media_uri
},
OutputBucketName='aws-support-ml-demo-bucket-transcribe',
# OutputEncryptionKMSKeyId='string',
Settings={
'ShowSpeakerLabels': True,
'MaxSpeakerLabels': 3,
'ChannelIdentification': False,
'ShowAlternatives': False,
},
JobExecutionSettings={
'AllowDeferredExecution': True,
'DataAccessRoleArn': 'arn:aws:iam::026863910802:role/service-role/TEST-AWS-TEST'
},
ContentRedaction={
'RedactionType': 'PII',
'RedactionOutput': 'redacted'
}
)
print(response)
except Exception as e:
print(e)
raise e
有错误:
2020-06-18T11:18:17.628+03:00
An error occurred (BadRequestException) when calling the StartTranscriptionJob operation: The S3 URI that you provided can't be accessed. Make sure that you have read permission and try your request again.
2020-06-18T11:18:17.628+03:00
[ERROR] BadRequestException: An error occurred (BadRequestException) when calling the StartTranscriptionJob operation: The S3 URI that you provided can't be accessed. Make sure that you have read permission and try your request again.
Traceback (most recent call last):
File "/var/task/lambda_function.py", line 63, in lambda_handler
raise e
File "/var/task/lambda_function.py", line 24, in lambda_handler
response = transcribe.start_transcription_job(
存储桶名称为aws-support-ml-demo-bucket,文件直接位于存储桶内。
我的 lambda 角色还可以完全访问 S3。
我没有太多使用 S3 url 的经验,但我认为这可能是问题所在。
关于 IAM 角色,我在 lambda 执行和 lambda 中使用完全相同的一个角色进行转录:
'DataAccessRoleArn': 'arn:aws:iam::026863910802:role/service-role/TEST-AWS-TEST'
该角色具有以下权限:
AmazonS3FullAccess
AWS managed policy
AmazonTranscribeFullAccess
AWS managed policy
IAMassumeRole
Managed policy
AWSLambdaS3ExecutionRole-6fe39002-b20d-4255-a666-98fb5c889b2c
Managed policy
AWSLambdaBasicExecutionRole-9da5b8ab-3601-4975-ad97-1206e6348784
Managed policy
【问题讨论】:
-
您拥有
aws-support-ml-demo-bucket存储桶吗?我无法访问它或 mp3 文件,因此它不是公共存储桶。 -
嘿,约翰,我只是设法通过删除 lambda 的这一部分来让它工作:JobExecutionSettings: {....} 出于某种原因。我无法解释为什么与 DataAccessRoleARN 有冲突……很奇怪
-
最初,我认为问题出在 media_uri 上,但事实证明没关系。桶是不公开的......这是正确的。感谢大家的帮助,我真的很感激。希望这对将来的其他人有所帮助。 :)
标签: amazon-web-services amazon-s3 aws-lambda