The current AWS identity is not a role for sagemaker?

Karan Nadagoudar picture Karan Nadagoudar · Dec 8, 2017 · Viewed 7.8k times · Source

I am getting error when i call get_execution_role() from sagemaker in python. I have attached the error for the same. enter image description here

I have added the SagemakerFullAccess Policy to role and user both.

Answer

Marcio dos Santos picture Marcio dos Santos · Jan 16, 2018

get_execution_role() is a function helper used in the Amazon SageMaker Examples GitHub repository.

These examples were made to be executed from the fully managed Jupyter notebooks that Amazon SageMaker provides.

From inside these notebooks, get_execution_role() will return the IAM role name that was passed in as part of the notebook creation. That allows the notebook examples to be executed without code changes.

From outside these notebooks, get_execution_role() will return an exception because it does not know what is the role name that SageMaker requires.

To solve this issue, pass the IAM role name instead of using get_execution_role().

Instead of:

role = get_execution_role()

kmeans = KMeans(role=role,
                train_instance_count=2,
                train_instance_type='ml.c4.8xlarge',
                output_path=output_location,
                k=10,
                data_location=data_location)

you need to do:

role = 'role_name_with_sagemaker_permissions'

kmeans = KMeans(role=role,
                train_instance_count=2,
                train_instance_type='ml.c4.8xlarge',
                output_path=output_location,
                k=10,
                data_location=data_location)