"""Lambda create_artist function module.""" from config import graphql_gateway from config import GRAPHQL_HEADERS from config import app_logger as logger from constants import queries from src import spotify_parser def handler(event, context): """Lambda entry point.""" try: input_data = event or {} vendor_id = input_data.get('vendor_id') spotify_url = input_data.get('spotify_url', None) if spotify_url: artist_name = spotify_parser.get_artist_name(spotify_url) payload = { 'name': artist_name, } graphql_gateway.set_headers(GRAPHQL_HEADERS) logger.info(f'Creating artist for {artist_name}') return graphql_gateway.execute( queries.create_label_participant, {'labelParticipant': payload, 'vendorId': vendor_id} )['data']['createLabelParticipant'] else: # If a Spotify URL is not supplied # we should skip the artist creation functionality # other parts of the step function can proceed. logger.info( f'Creating artist for vendor_id {vendor_id}:' f' spotify_url not found' ) return {} except Exception as e: logger.exception(str(e)) raise e