"""Lambda create_contributor function module.""" from config import graphql_gateway from config import GRAPHQL_HEADERS from config import app_logger as logger from src.constants import queries KNR_SOURCE = 'event.knrAccountCreation' def handler(event, context): """Lambda entry point.""" input_data = event or {} if ( input_data['source'] == KNR_SOURCE and not input_data['forename'] and not input_data['middlename'] and not input_data['surname'] ): logger.info('Contributor info not detected...skipping step.') return { 'create_contributor': 'skipped' } try: vendor_id = input_data.get('vendor_id') forename = input_data.get('forename') middle_names = input_data.get('middlename') surname = input_data.get('surname') payload = { 'vendorId': vendor_id, 'forename': forename, 'middleNames': middle_names, 'surname': surname } graphql_gateway.set_headers(GRAPHQL_HEADERS) logger.info('Creating NrContributor...') result = graphql_gateway.execute( queries.create_contributor, {'nrContributorInput': payload} )['data']['createNrContributor'] logger.info(f'Created NrContributor: {result}') return result except Exception as e: logger.exception(str(e)) raise e