diff --git a/awscli/customizations/assumerole.py b/awscli/customizations/assumerole.py index cd704dcff524..8b0417edec44 100644 --- a/awscli/customizations/assumerole.py +++ b/awscli/customizations/assumerole.py @@ -32,8 +32,14 @@ def inject_assume_role_provider(session, event_name, **kwargs): # before we start injecting things into the session. return provider = create_assume_role_provider(session) - session.get_component('credential_provider').insert_before( - 'config-file', provider) + try: + session.get_component('credential_provider').insert_before( + 'config-file', provider) + except Exception: + # This is ok, it just means that we couldn't create the credential + # provider object. + LOG.debug("Not registering assume-role provider, credential " + "provider from session could not be created.") def create_assume_role_provider(session): diff --git a/tests/unit/customizations/test_assumerole.py b/tests/unit/customizations/test_assumerole.py index bb1a26510194..ce7196125376 100644 --- a/tests/unit/customizations/test_assumerole.py +++ b/tests/unit/customizations/test_assumerole.py @@ -55,6 +55,15 @@ def test_assume_role_provider_registration(self): # be registered. session.get_component.assert_called_with('credential_provider') + def test_provider_not_registered_on_error(self): + session = mock.Mock() + session.get_component.side_effect = Exception( + "Couldn't get credential_provider.") + assumerole.inject_assume_role_provider( + session, event_name='building-command-table.foo') + self.assertFalse( + session.get_component.return_value.insert_before.called) + class TestAssumeRoleCredentialProvider(unittest.TestCase):