def __init__(self): """Class constructor.""" try: client_id = os.environ[EnvironmentVariables.IOT - CLIENT - ID] port_no = int(os.environ[EnvironmentVariables.PORT]) iot_endpoint = os.environ[EnvironmentVariables.IOT_ENDPOINT] except KeyError as port_not_configured: # Use default port if environment variable is not set LoggerUtility.log_warning( str(port_not_configured) + " not configured, using default port!") port_no = Constants.IOT_DEFAULT_PORT_NO
def __init__(self): """Class constructor.""" try: port_no = int(os.environ[ EnvironmentVariables.ELASTICACHE_REDIS_PORT_ENV_VAR]) except KeyError as port_not_configured: # Use default port if environment variable is not set LoggerUtility.log_warning( str(port_not_configured) + " not configured, using default port!") port_no = Constants.REDIS_CACHE_DEFAULT_PORT_NO self.__redis_client = redis.StrictRedis(host=os.environ[ EnvironmentVariables.ELASTICACHE_REDIS_ENDPOINT_ENV_VAR], port=port_no, db=0)
def delete_objects(bucket_name, object_list): """Delete objects from S3 bucket from an object list.""" s3_delete_object_list = [] for s3_key in object_list: s3_delete_object_list.append({ReferenceKeys.KEY_REFERENCE: s3_key}) s3_client = boto3.client(ReferenceKeys.S3_REFERENCE) deletion_response = s3_client.delete_objects( Bucket=bucket_name, Delete={ReferenceKeys.OBJECTS_REFERENCE: s3_delete_object_list}) if 'Deleted' in deletion_response: LoggerUtility.log_debug("Deleted '" + str(len(deletion_response['Deleted'])) + "' objects from '" + bucket_name + "' bucket successfully!") else: LoggerUtility.log_debug("Deleted '" + str(s3_delete_object_list[0]) + "' object from '" + bucket_name + "' bucket successfully!") if 'Errors' in deletion_response: LoggerUtility.log_warning("Failed to delete '" + str(len(deletion_response['Errors'])) + "' objects from '" + bucket_name + "' bucket!")
def create_connection(): """Create connection to RDS.""" try: port_no = int(os.environ[EnvironmentVariables.RDS_DB_PORT_ENV_VAR]) except KeyError as key_error: # Use default port if environment variable is not set LoggerUtility.log_warning( str(key_error) + " not configured, using default port!") port_no = Constants.RDS_AURORA_DEFAULT_PORT_NO try: rds_connection = pymysql.connect( host=os.environ[EnvironmentVariables.RDS_DB_ENDPOINT_ENV_VAR], user=os.environ[EnvironmentVariables.RDS_DB_USER_ENV_VAR], passwd=os.environ[ EnvironmentVariables.RDS_DB_PASSWORD_ENV_VAR], db=os.environ[EnvironmentVariables.RDS_DB_NAME_ENV_VAR], port=port_no, connect_timeout=10, cursorclass=pymysql.cursors.DictCursor) return rds_connection except pymysql.InternalError as connection_error: LoggerUtility.log_error(str(connection_error)) LoggerUtility.log_error( "FATAL: Failed to create connection to RDS!")