NoSuchEntityException:调用GetRole操作时发生错误(NoSuchEntity):找不到名称为<name>的用户

时间:2018-07-14 16:02:32

标签: amazon-sagemaker

从笔记本实例调用get_execution_role()失败,并显示错误消息NoSuchEntityException: An error occurred (NoSuchEntity) when calling the GetRole operation: The user with name <name> cannot be found.

堆栈跟踪:

NoSuchEntityExceptionTraceback (most recent call last)
<ipython-input-1-1e2d3f162cfe> in <module>()
      5 sagemaker_session = sagemaker.Session()
      6 
----> 7 role = get_execution_role()

/home/ec2-user/anaconda3/envs/tensorflow_p27/lib/python2.7/site-packages/sagemaker/session.pyc in get_execution_role(sagemaker_session)
    871     if not sagemaker_session:
    872         sagemaker_session = Session()
--> 873     arn = sagemaker_session.get_caller_identity_arn()
    874 
    875     if 'role' in arn:

/home/ec2-user/anaconda3/envs/tensorflow_p27/lib/python2.7/site-packages/sagemaker/session.pyc in get_caller_identity_arn(self)
    701         # Call IAM to get the role's path
    702         role_name = role[role.rfind('/') + 1:]
--> 703         role = self.boto_session.client('iam').get_role(RoleName=role_name)['Role']['Arn']
    704 
    705         return role

/home/ec2-user/anaconda3/envs/tensorflow_p27/lib/python2.7/site-packages/botocore/client.pyc 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)

/home/ec2-user/anaconda3/envs/tensorflow_p27/lib/python2.7/site-packages/botocore/client.pyc 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

NoSuchEntityException: An error occurred (NoSuchEntity) when calling the GetRole operation: The user with name <name> cannot be found.

但是,直接使用boto客户端获取有关角色的信息成功。效果很好:

response = client.get_role(
    RoleName='role-name',
)['Role']['Arn']

2 个答案:

答案 0 :(得分:0)

事实证明,如果您停止并启动笔记本实例,这是一个奇怪的错误。

答案 1 :(得分:0)

我已经关闭并再次运行笔记本计算机,它可以正常工作。

PD:我必须再次运行代码才能生效。