1
votes

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

3
what attempts have you tried to resolve the error? - Patrick

3 Answers

0
votes

Looks like you don't have access to the resource

arn:aws:sagemaker:eu-west-1:307504647302:training-job/decision-trees-sample-2018-04-24-13-13-38-281

Can you check if the resource url is correct and the proper permissions are set in the security group.

1
votes

Maybe you are using AWS Educate account.

At this time you cannot use SageMaker service to create a training or modeling job with an AWS Educate Starter Account.

At the present time, you can use your own personal AWS account if you'd like to use/deploy a training job with SageMaker service.

You can however continue to use Jupyter notebooks via SageMaker through AWS Educate account.

0
votes

I was experiencing similar problems when I started using SageMaker so I developed this open source project https://github.com/Kenza-AI/sagify (sagify), it's a CLI tool that can help you train and deploy your own Machine Learning/Deep Learning models on SageMaker in a very easy way. I managed to train and deploy all of my ML models whatever library I was using (Keras, Tensorflow, scikit-learn, LightFM, spacy, etc). Essentially, you can specify all your dependencies in the classic pythonic way, i.e. in a requiments.txt, and sagify will read them and install them on a Docker image. Then, this Docker image can be executed on SageMaker for training and deployment.

Additionally, I specify in the sagify docs (https://kenza-ai.github.io/sagify/) a one-off process on how to setup your AWS account in order to avoid permissions related issues.