from internal.endpoints import make_internal_endpoints, exec_endpoint from internal.commons import DP_URL from internal.helpers import DataProcessorError from management.endpoints import make_management_endpoints from integration import make_integration_endpoints import logging log = logging.getLogger() log.setLevel(logging.INFO) # DP_URL = "http://172.31.36.151:12345/" # for "live" local testing through test-thing. # DP_URL = "http://172.31.36.151:22345/" # for "live" local testing through test-thing. - Aleks # DP_URL = "http://172.31.36.151:32345/" # for "live" local testing through test-thing. - Dima endpoints = {} endpoints.update(make_internal_endpoints(DP_URL)) endpoints.update(make_management_endpoints(DP_URL)) endpoints.update(make_integration_endpoints(DP_URL)) def lambda_handler(event, context): endpoint_name = 'unknown' internal_request = {} try: if 'endpoint' in event: endpoint_name = event["endpoint"] if endpoint_name in endpoints: internal_request = {} result = exec_endpoint(endpoints[endpoint_name], event, internal_request) log.info(f'EP[{endpoint_name}]: {internal_request}') return result else: raise RuntimeError('Unknown endpoint') else: raise RuntimeError('No endpoint defined') except DataProcessorError as e: log.exception(f'EP[{endpoint_name}]: {internal_request}', exc_info=e) return e.args[0] except Exception as e: log.exception(f'EP[{endpoint_name}]: {internal_request}', exc_info=e) return {"error": ', '.join([str(arg) for arg in e.args]), "type": e.__class__.__name__, "info": None}