I am trying to run AWS Translate job on Batch data stored in S3 with the following python code
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'
]
)
I can confirm that role has full S3 access, However, when executing above code, I get following error
---------------------------------------------------------------------------
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.
Any pointer if I am missing anything. Also for clarification, this is running in Ireland where the service is available.
I tried to reproduce this situation and received:
I then changed my output to point purely to the bucket (with no sub-directory) and it worked!
I then copied a file to a sub-directory (eg
aws cp foo.txt s3://my-bucket/aws-translate/assets/output/
) and re-ran the program and it worked!Bottom line: Make sure that the output directory already exists (either by putting a file in that path, or using "Create Folder" in the S3 management console to create the output directory).
For the record, my IAM Role had the
AmazonS3FullAccess
policy and a trust policy of: