File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ CHANGELOG
3
3
=========
4
4
5
5
1.7.1dev
6
- ========
6
+ =====
7
7
8
+ * bug-fix: get_execution_role no longer fails if user can't call get_role
8
9
* bug-fix: Session: use existing model instead of failing during ``create_model() ``
9
10
* deprecate enable_cloudwatch_metrics from Framework Estimators.
10
11
Original file line number Diff line number Diff line change @@ -760,7 +760,7 @@ def expand_role(self, role):
760
760
def get_caller_identity_arn (self ):
761
761
"""Returns the ARN user or role whose credentials are used to call the API.
762
762
Returns:
763
- (str): The ARN uer or role
763
+ (str): The ARN user or role
764
764
"""
765
765
assumed_role = self .boto_session .client ('sts' ).get_caller_identity ()['Arn' ]
766
766
@@ -772,7 +772,11 @@ def get_caller_identity_arn(self):
772
772
773
773
# Call IAM to get the role's path
774
774
role_name = role [role .rfind ('/' ) + 1 :]
775
- role = self .boto_session .client ('iam' ).get_role (RoleName = role_name )['Role' ]['Arn' ]
775
+ try :
776
+ role = self .boto_session .client ('iam' ).get_role (RoleName = role_name )['Role' ]['Arn' ]
777
+ except ClientError :
778
+ LOGGER .warning ("Couldn't call 'get_role' to get Role ARN from role name {} to get Role path."
779
+ .format (role_name ))
776
780
777
781
return role
778
782
Original file line number Diff line number Diff line change @@ -70,6 +70,18 @@ def test_get_caller_identity_arn_from_an_user(boto_session):
70
70
assert actual == 'arn:aws:iam::369233609183:user/mia'
71
71
72
72
73
+ def test_get_caller_identity_arn_from_an_user_without_permissions (boto_session ):
74
+ sess = Session (boto_session )
75
+ arn = 'arn:aws:iam::369233609183:user/mia'
76
+ sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : arn }
77
+ sess .boto_session .client ('iam' ).get_role .side_effect = ClientError ({}, {})
78
+
79
+ with patch ('logging.Logger.warning' ) as mock_logger :
80
+ actual = sess .get_caller_identity_arn ()
81
+ assert actual == 'arn:aws:iam::369233609183:user/mia'
82
+ mock_logger .assert_called_once ()
83
+
84
+
73
85
def test_get_caller_identity_arn_from_a_role (boto_session ):
74
86
sess = Session (boto_session )
75
87
arn = 'arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122'
You can’t perform that action at this time.
0 commit comments