From d42432bfefc75a3123ac43f471c69a56eccf5b55 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Wed, 18 Jan 2017 18:36:50 -0800 Subject: [PATCH] IAM: raise error if requiested instance profile does not exist (#802) Signed-off-by: Andrew Harris --- moto/iam/models.py | 2 ++ tests/test_iam/test_iam.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/moto/iam/models.py b/moto/iam/models.py index 60b9b743..d27722f3 100644 --- a/moto/iam/models.py +++ b/moto/iam/models.py @@ -501,6 +501,8 @@ class IAMBackend(BaseBackend): if profile.name == profile_name: return profile + raise IAMNotFoundException("Instance profile {0} not found".format(profile_name)) + def get_instance_profiles(self): return self.instance_profiles.values() diff --git a/tests/test_iam/test_iam.py b/tests/test_iam/test_iam.py index bedea4e0..de8f89a5 100644 --- a/tests/test_iam/test_iam.py +++ b/tests/test_iam/test_iam.py @@ -62,6 +62,14 @@ def test_get_role__should_throw__when_role_does_not_exist(): conn.get_role('unexisting_role') +@mock_iam() +@raises(BotoServerError) +def test_get_instance_profile__should_throw__when_instance_profile_does_not_exist(): + conn = boto.connect_iam() + + conn.get_instance_profile('unexisting_instance_profile') + + @mock_iam() def test_create_role_and_instance_profile(): conn = boto.connect_iam()