File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -763,7 +763,10 @@ def get_caller_identity_arn(self):
763
763
764
764
# Call IAM to get the role's path
765
765
role_name = role [role .rfind ('/' ) + 1 :]
766
- role = self .boto_session .client ('iam' ).get_role (RoleName = role_name )['Role' ]['Arn' ]
766
+ try :
767
+ role = self .boto_session .client ('iam' ).get_role (RoleName = role_name )['Role' ]['Arn' ]
768
+ except ClientError :
769
+ LOGGER .warning ("Couldn't call 'get_role' to get Role ARN from role name {}." .format (role_name ))
767
770
768
771
return role
769
772
Original file line number Diff line number Diff line change @@ -69,6 +69,16 @@ def test_get_caller_identity_arn_from_an_user(boto_session):
69
69
assert actual == 'arn:aws:iam::369233609183:user/mia'
70
70
71
71
72
+ def test_get_caller_identity_arn_from_an_user_without_permissions (boto_session ):
73
+ sess = Session (boto_session )
74
+ arn = 'arn:aws:iam::369233609183:user/mia'
75
+ sess .boto_session .client ('sts' ).get_caller_identity .return_value = {'Arn' : arn }
76
+ sess .boto_session .client ('iam' ).get_role .side_effect = ClientError ('Bad permissions!' , {})
77
+
78
+ actual = sess .get_caller_identity_arn ()
79
+ assert actual == 'arn:aws:iam::369233609183:user/mia'
80
+
81
+
72
82
def test_get_caller_identity_arn_from_a_role (boto_session ):
73
83
sess = Session (boto_session )
74
84
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