1

我正在尝试使用以下 python 代码对存储在 S3 中的批处理数据运行 AWS Translate 作业

role_arn='arn:aws:iam::<account-id>:role/service-role/AmazonTranslateServiceRoleS3FullAccess-ExploreML'
inp_data_path='s3://exploring-ml/aws-translate/assets/input/'
opt_data_path='s3://exploring-ml/aws-translate/assets/output/'

response = translate_client.start_text_translation_job(
    JobName='string',
    InputDataConfig={
        'S3Uri': inp_data_path,
        'ContentType': 'text/plain'
    },
    OutputDataConfig={
        'S3Uri': opt_data_path
    },
    DataAccessRoleArn=role_arn,
    SourceLanguageCode='zh',
    TargetLanguageCodes=[
        'en'
    ]
)

我可以确认该角色具有完整的 S3 访问权限,但是,在执行上述代码时,出现以下错误

---------------------------------------------------------------------------
InvalidRequestException                   Traceback (most recent call last)
<ipython-input-11-2bf8de09e0fe> in <module>
     11     SourceLanguageCode='zh',
     12     TargetLanguageCodes=[
---> 13         'en'
     14     ]
     15 )

~/.local/share/virtualenvs/exploring-ml-tools-zug9J9gH/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs)
    314                     "%s() only accepts keyword arguments." % py_operation_name)
    315             # The "self" in this scope is referring to the BaseClient.
--> 316             return self._make_api_call(operation_name, kwargs)
    317 
    318         _api_call.__name__ = str(py_operation_name)

~/.local/share/virtualenvs/exploring-ml-tools-zug9J9gH/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params)
    633             error_code = parsed_response.get("Error", {}).get("Code")
    634             error_class = self.exceptions.from_code(error_code)
--> 635             raise error_class(parsed_response, operation_name)
    636         else:
    637             return parsed_response

InvalidRequestException: An error occurred (InvalidRequestException) when calling the StartTextTranslationJob operation: NO_READ_ACCESS_TO_S3: The provided data access role does not have proper access to the input/output S3 URI.

如果我遗漏任何东西,任何指针。同样为澄清起见,这是在提供该服务的爱尔兰运行的。

4

1 回答 1

1

我试图重现这种情况并收到:

botocore.errorfactory.InvalidRequestException:调用 StartTextTranslationJob 操作时发生错误 (InvalidRequestException):OUTPUT_S3_URI_INVALID:提供的输出 S3 URI 无效或不存在。

然后我将输出更改为纯粹指向存储桶(没有子目录)并且它有效!

然后我将一个文件复制到一个子目录(例如aws cp foo.txt s3://my-bucket/aws-translate/assets/output/)并重新运行该程序,它就可以工作了!

底线:确保输出目录已经存在(通过将文件放在该路径中,或者使用 S3 管理控制台中的“创建文件夹”来创建输出目录)。

作为记录,我的 IAM 角色具有以下AmazonS3FullAccess政策和信任政策:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "",
      "Effect": "Allow",
      "Principal": {
        "Service": "translate.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
于 2020-06-25T00:33:18.130 回答