-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Executing sagemaker.get_execution_role() locally #300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
sagemaker.get_execution_role()
locally
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 |
Correcting typos in deepar-synthetic text
This is really a pretty bad experience. |
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. |
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! |
Also having issues here, +1 to smoothing it out. |
same |
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 |
I think local mode should work offline, what need is there to check credentials when running locally? |
I have written this super hacky function to resolve the sagemaker execution role. it may fail miserably, and you should probably not use it at all. But, it may work in simple cases: def resolve_sm_role():
client = boto3.client('iam', region_name=region)
response_roles = client.list_roles(
PathPrefix='/',
# Marker='string',
MaxItems=999
)
for role in response_roles['Roles']:
if role['RoleName'].startswith('AmazonSageMaker-ExecutionRole-'):
print('Resolved SageMaker IAM Role to: ' + str(role))
return role['Arn']
raise Exception('Could not resolve what should be the SageMaker role to be used') |
|
Putting iluoyi's solution in code try:
role = sagemaker.get_execution_role()
except ValueError:
iam = boto3.client('iam')
role = iam.get_role(RoleName='AmazonSageMaker-ExecutionRole-20191205T100050')['Role']['Arn'] A SageMaker execution role exists if you ever ran a job before, if not:
Then use the name in A potential long term solution would be to create a function that checks for an existing execution service role, if it does not exist, then create the new role.....but service-role creation with managed policies through boto3 IAM requires......patience.... |
Any plans to fix this? This is very annoying if you want to execute notebooks locally. get_execution_role should create a default role with SM permissions when called out of a notebook. |
Nothing yet? |
Almost three years later and this is still an issue? |
Got today |
The above solution (#300 (comment)) is in docs now: |
No update there? This issue is 4 years old ... |
Just stumbled across this issue. Will this issue ever be solved? |
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.
|
It seems that sagemaker-python-sdk team does not care about the community issues. |
I got the same error. Tried everything, is it still an issue? |
I am getting around with: |
How is this not fixed and just closed? |
What secret free Facebook dating site |
Please fill out the form below.
System Information
Describe the problem
sagemaker.get_execution_role()
. Instead, I receive abotocore.errorfactory.NoSuchEntityException
.Minimal repro / logs
To reproduce the problem:
Script:
Credentials:
Error:
pip install sagemaker && python mwe.py
The text was updated successfully, but these errors were encountered: