[autoscaler] Fix Error Handling for botocore (#3534)

Unfortunately Boto generates error classes dynamically, so this catches
the expected error and raises the error if it is the wrong class.

Closes #3533.
This commit is contained in:
Richard Liaw
2018-12-14 00:20:49 -08:00
committed by GitHub
parent 2a4685a08b
commit de3fdeb5b5
+10 -4
View File
@@ -273,8 +273,11 @@ def _get_role(role_name, config):
try:
role.load()
return role
except botocore.errorfactory.NoSuchEntityException:
return None
except botocore.exceptions.ClientError as exc:
if exc.response.get("Error", {}).get("Code") == "NoSuchEntity":
return None
else:
raise exc
def _get_instance_profile(profile_name, config):
@@ -283,8 +286,11 @@ def _get_instance_profile(profile_name, config):
try:
profile.load()
return profile
except botocore.errorfactory.NoSuchEntityException:
return None
except botocore.exceptions.ClientError as exc:
if exc.response.get("Error", {}).get("Code") == "NoSuchEntity":
return None
else:
raise exc
def _get_key(key_name, config):