From de3fdeb5b5e4b5e48b3c83b6f48dba022859c6c5 Mon Sep 17 00:00:00 2001 From: Richard Liaw Date: Fri, 14 Dec 2018 00:20:49 -0800 Subject: [PATCH] [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. --- python/ray/autoscaler/aws/config.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/ray/autoscaler/aws/config.py b/python/ray/autoscaler/aws/config.py index 62e0b25ee2e2..c0493df0d658 100644 --- a/python/ray/autoscaler/aws/config.py +++ b/python/ray/autoscaler/aws/config.py @@ -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):