Repository navigation
Closed
Labels
Description
Please fill out the form below.
System Information
- Framework (e.g. TensorFlow) / Algorithm (e.g. KMeans): MXNet/None
- Framework Version: 1.1.0
- Python Version: 3.5
- CPU or GPU: CPU
- Python SDK Version: 1.7.0
- Are you using a custom image: No
Describe the problem
- I want to run SageMaker without a notebook instance, from a script on my local machine, for various reasons.
- I can successfully start SageMaker jobs by passing the ARN string from my AWS role to my script
- However, I cannot retrieve the ARN string programatically using
sagemaker.get_execution_role(). Instead, I receive abotocore.errorfactory.NoSuchEntityException.
Minimal repro / logs
To reproduce the problem:
Script:
import sagemaker
import boto3
session = boto3.Session(profile_name='personal')
sagemaker_session = sagemaker.Session(boto_session=session)
role = sagemaker.get_execution_role(sagemaker_session=sagemaker_session)Credentials:
[personal]
aws_secret_access_key = ******************
aws_access_key_id = *******************
region = us-west-2
Error:
Traceback (most recent call last):
File "mwe.py", line 8, in <module>
role = sagemaker.get_execution_role(sagemaker_session=sagemaker_session)
File "/Users/opringle/.virtualenvs/vdcnn/lib/python3.6/site-packages/sagemaker/session.py", line 936, in get_execution_role
arn = sagemaker_session.get_caller_identity_arn()
File "/Users/opringle/.virtualenvs/vdcnn/lib/python3.6/site-packages/sagemaker/session.py", line 766, in get_caller_identity_arn
role = self.boto_session.client('iam').get_role(RoleName=role_name)['Role']['Arn']
File "/Users/opringle/.virtualenvs/vdcnn/lib/python3.6/site-packages/botocore/client.py", line 314, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/Users/opringle/.virtualenvs/vdcnn/lib/python3.6/site-packages/botocore/client.py", line 612, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.NoSuchEntityException: An error occurred (NoSuchEntity) when calling the GetRole operation: The user with name oliver_pringle cannot be found.
- Exact command to reproduce:
pip install sagemaker && python mwe.py
Reacted by Josh Peng, Thom Lane, kvm108, Elgin Beloy, Jared Porter, Kiran Sanjeevan Cabeza, durandg12, OMARI FAAKYE, Mengxin Zhu, Max Reis and 7 more
Activity
[-]Executing `sagemaker.get_execution_role()` locally[/-][+]Executing sagemaker.get_execution_role() locally[/+]yangaws commentedon Jul 30, 2018
Hi @opringle ,
The problem is, the get_execution_role() method is only used on AWS SageMaker notebook instances. So if you use it locally, it won't correctly parse your credential (from your stacktrace, I think you are using IAM user credential).
So if you want to use sagemaker locally, you can create an IAM role with enough SageMaker access permission. Then just directly use that role in your code.
Feel free to reopen this if you have more questions.
Thanks
Merge pull request aws#300 from JonathanTaws/patch-3
leopd commentedon Nov 15, 2018
This is really a pretty bad experience.
get_execution_role()sounds like it's going to just figure out all the IAM/role/confusion/whatever to make SageMaker work. And on a notebook instance it does. But if you run that same code on your laptop it fails, sending customers into IAM/role/confusion limbo.leopd commentedon Nov 15, 2018
Without this it's basically impossible to write a simple set of code that works both on a SageMaker notebook instance and anywhere else. Which is a real barrier to people who want to build the SageMaker ecosystem.
laurenyu commentedon Nov 16, 2018
understood. definitely agree that the SDK can do better here. I'll leave this issue open as a feature request, and hopefully we can prioritize this work in the near future. Thanks @leopd!
thomelane commentedon Nov 21, 2018
Also having issues here, +1 to smoothing it out.
Soypete commentedon Dec 19, 2018
same
iluoyi commentedon Dec 21, 2018
A temp solution is re-use the IAM role attached to your notebook (when you create the notebook, you had one there). You can get its
arnfrom IAM console.stevehawley commentedon Mar 18, 2019
I think local mode should work offline, what need is there to check credentials when running locally?
fix: correct AutoML imports and expose current_job_name (aws#300)
fix: correct AutoML imports and expose current_job_name (#300)
7 remaining items
rapuckett commentedon Apr 26, 2021
Almost three years later and this is still an issue?
TanjaNY commentedon Apr 29, 2021
Got today
"The current AWS identity is not a role: arn:aws:iam::XXXXXXXXXX:user/xxxxxxxx, therefore it cannot be used as a SageMaker execution role."
changjonathanc commentedon May 9, 2021
The above solution (#300 (comment)) is in docs now:
https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html
tchaton commentedon Jun 30, 2022
No update there? This issue is 4 years old ...
ioanfr commentedon Feb 15, 2023
Inside SageMaker we can have multiple notebook instances and each notebook instance can have a different IAM role. When running your code locally get_execution_role will not work since there might be several roles dedicated to different SageMaker notebook instances. Therefore, you have to choose which is the right role to use.
In order to make your code work in both local and remote modes, you could instantiate a variable containing the specific value of IAM role, and implement a try block like here below.
celsofranssa commentedon Oct 13, 2023
It seems that sagemaker-python-sdk team does not care about the community issues.
variable-ad commentedon Apr 3, 2024
I got the same error. Tried everything, is it still an issue?
TanjaNY commentedon Apr 4, 2024
I am getting around with:
Created Sagemaker All Access Role and define role as the arn of this role, works for me.
role = 'arn:aws:iam::ACCTNMRXXXX:role/SageMakerAllAccess'
liambolling commentedon Oct 17, 2024
How is this not fixed and just closed?
RAHIM444-creator commentedon Apr 13, 2025
What secret free Facebook dating site
fix: correct AutoML imports and expose current_job_name (aws#300)