I am trying to use my own sickit-learn ML model with SageMaker using the github example.
The python code is below :
# Define IAM role import boto3
import re
import os
import numpy as np
import pandas as pd
from sagemaker import get_execution_role
import sagemaker as sage from time
import gmtime, strftime
role = get_execution_role()
ess = sage.Session()
account = sess.boto_session.client('sts').get_caller_identity()['Account']
region = sess.boto_session.region_name
image = '{}.dkr.ecr.{}.amazonaws.com/decision-trees-sample:latest'.format(account, region)
output_path="s3://output"
sess
tree = sage.estimator.Estimator(image,
role, 1, 'ml.c4.2xlarge',
output_path='s3-eu-west-1.amazonaws.com/output',
sagemaker_session=sess)
tree.fit("s3://output/iris.csv")
But I get this error :
INFO:sagemaker:Creating training-job with name: decision-trees-sample-2018-04-24-13-13-38-281
--------------------------------------------------------------------------- ClientError Traceback (most recent call last) in () 14 sagemaker_session=sess) 15 ---> 16 tree.fit("s3://inteldatastore-cyrine/iris.csv")
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/estimator.py in fit(self, inputs, wait, logs, job_name) 161 self.output_path = 's3://{}/'.format(self.sagemaker_session.default_bucket()) 162 --> 163 self.latest_training_job = _TrainingJob.start_new(self, inputs) 164 if wait: 165 self.latest_training_job.wait(logs=logs)
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/estimator.py in start_new(cls, estimator, inputs) 336 input_config=input_config, role=role, job_name=estimator._current_job_name, 337 output_config=output_config, resource_config=resource_config, --> 338 hyperparameters=hyperparameters, stop_condition=stop_condition) 339 340 return cls(estimator.sagemaker_session, estimator._current_job_name)
~/anaconda3/envs/python3/lib/python3.6/site-packages/sagemaker/session.py in train(self, image, input_mode, input_config, role, job_name, output_config, resource_config, hyperparameters, stop_condition) 242 LOGGER.info('Creating training-job with name: {}'.format(job_name)) 243 LOGGER.debug('train request: {}'.format(json.dumps(train_request, indent=4))) --> 244 self.sagemaker_client.create_training_job(**train_request) 245 246 def create_model(self, name, role, primary_container):
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _api_call(self, *args, **kwargs) 312 "%s() only accepts keyword arguments." % py_operation_name) 313 # The "self" in this scope is referring to the BaseClient. --> 314 return self._make_api_call(operation_name, kwargs) 315 316 _api_call.name = str(py_operation_name)
~/anaconda3/envs/python3/lib/python3.6/site-packages/botocore/client.py in _make_api_call(self, operation_name, api_params) 610 error_code = parsed_response.get("Error", {}).get("Code") 611 error_class = self.exceptions.from_code(error_code) --> 612 raise error_class(parsed_response, operation_name) 613 else: 614 return parsed_response
ClientError: An error occurred (AccessDeniedException) when calling the CreateTrainingJob operation: User: arn:aws:sts::307504647302:assumed-role/default/SageMaker is not authorized to perform: sagemaker:CreateTrainingJob on resource: arn:aws:sagemaker:eu-west-1:307504647302:training-job/decision-trees-sample-2018-04-24-13-13-38-281
Can you help me to resolve the problem?
Thank you