changed print to log

and added some doc about exception raised
This commit is contained in:
Shay Nehmad 2019-04-16 10:58:56 +03:00
parent 5bfff88325
commit ce633af3d1
1 changed files with 7 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import logging
import boto3
import botocore
from botocore.exceptions import ClientError
@ -13,6 +15,9 @@ PLATFORM_TYPE_KEY = 'PlatformType'
IP_ADDRESS_KEY = 'IPAddress'
logger = logging.getLogger(__name__)
def filter_instance_data_from_aws_response(response):
return [{
'instance_id': x[INSTANCE_ID_KEY],
@ -74,6 +79,7 @@ class AwsService(object):
This function will assume that it's running on an EC2 instance with the correct IAM role.
See https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#iam-role for details.
:raises: botocore.exceptions.ClientError if can't describe local instance information.
:return: All visible instances from this instance
"""
current_instance = AwsInstance()
@ -84,5 +90,5 @@ class AwsService(object):
filtered_instances_data = filter_instance_data_from_aws_response(response)
return filtered_instances_data
except botocore.exceptions.ClientError as e:
print e.response + " " + e.message + " ... " + e.operation_name
logger.info("AWS client error while trying to get instances: " + e.message)
raise e