def produce_error_stream_callables(): """Produces filter/mapper callables for error stream.""" if utils.in_aws_lambda(): try: globs = dict(import_string=import_string, error=None) exec( """ {% set callables = ['mapper', 'filter', 'partition_key'] %} {% if meta_error %} error = { {% for k, v in meta_error.items() %} {% if k in callables %} '{{k}}': '{{v or ''}}' and import_string('{{v}}'), {% else %} '{{k}}': '{{v}}', {% endif %} {% endfor %} } {% endif %} """, globs) return globs["error"] except: logger.error("Unable to produce error callables") dsn = utils.get_secret("sentry.dsn", environment="{{_env.name}}", stage="{{_env.stage}}") if not dsn: logger.error("Unable to retrieve Sentry DSN") else: client = raven.Client(dsn) client.captureException() # This is a critical error: must re-raise raise
def produce_error_stream_callables(): """Produces filter/mapper callables for error stream.""" if utils.in_aws_lambda(): try: globs = dict(import_string=import_string, error=None) exec( """ {% set callables = ['batch_mapper', 'mapper', 'filter', 'partition_key'] %} {% if meta_error %} error = { {% for k, v in meta_error.items() %} {% if k in callables %} '{{k}}': '{{v or ''}}' and import_string('{{v}}'), {% else %} '{{k}}': '{{v}}', {% endif %} {% endfor %} } {% endif %} """, globs) return globs["error"] except: logger.error("Unable to produce error callables") dsn = utils.get_secret("sentry.dsn", environment="{{_env.name}}", stage="{{_env.stage}}") if not dsn: logger.error("Unable to retrieve Sentry DSN") else: client = raven.Client(dsn) client.captureException() # This is a critical error: must re-raise raise
def produce_fct_callables(): """Produces function callables for each endpoint.""" if utils.in_aws_lambda(): try: globs = dict(import_string=import_string, fct=None) exec( """ fct = [ {% for f in meta_functions %} { {% for k, v in f.items() %} {% if k == 'fct' %} '{{k}}': '{{v or ''}}' and import_string('{{v}}'), {% else %} '{{k}}': '{{v or ''}}', {% endif %} {% endfor %} }, {% endfor %} ] """, globs) return globs["fct"] except Exception as principal: logger.error("Unable to produce fct callables") try: dsn = utils.get_secret("sentry.dsn", environment="{{_env.name}}", stage="{{_env.stage}}") except Exception as inner: dsn = "" if not dsn: logger.error("Unable to retrieve Sentry DSN") else: client = raven.Client(dsn) client.captureException() # This is a critical error: must re-raise raise principal
def produce_io_stream_callables(): """Produces filter/mapper callables for the input and output streams.""" if utils.in_aws_lambda(): try: globs = dict(import_string=import_string, input=None, output=None) exec( """ {% set callables = ['batch_mapper', 'mapper', 'filter', 'partition_key'] %} {% if meta_input %} input = { {% for k, v in meta_input.items() %} {% if k in callables %} '{{k}}': '{{v or ''}}' and import_string('{{v}}'), {% else %} {% if v is mapping %} '{{k}}': { {% for k1, v1 in v.items() %} '{{k1}}': '{{v1}}', {% endfor %} }, {% elif v|is_list %} '{{k}}': [ {% for vl in v %} {% if vl is mapping %} { {% for k2, v2 in vl.items() %} {% if k2 in callables %} '{{k2}}': '{{v2 or ''}}' and import_string('{{v2}}'), {% else %} '{{k2}}': '{{v2}}', {% endif %} {% endfor %} }, {% else %} '{{vl}}', {% endif %} {% endfor %} ], {% else %} '{{k}}': '{{v or ''}}', {% endif %} {% endif %} {% endfor %} } {% endif %} {% if meta_output %} output = [ {% for o in meta_output %} { {% for k, v in o.items() %} {% if k in callables %} '{{k}}': '{{v or ''}}' and import_string('{{v}}'), {% else %} {% if v is mapping %} '{{k}}': { {% for k1, v1 in v.items() %} '{{k1}}': '{{v1}}', {% endfor %} }, {% elif v|is_list %} '{{k}}': [ {% for vl in v %} {% if vl is mapping %} { {% for k2, v2 in vl.items() %} {% if k2 in callables %} '{{k2}}': '{{v2 or ''}}' and import_string('{{v2}}'), {% else %} '{{k2}}': '{{v2}}', {% endif %} {% endfor %} }, {% else %} '{{vl}}', {% endif %} {% endfor %} ], {% else %} '{{k}}': '{{v or ''}}', {% endif %} {% endif %} {% endfor %} }, {% endfor %} ] {% endif %} """, globs) return globs["input"], globs["output"] except: logger.error("Unable to produce I/O callables") dsn = utils.get_secret("sentry.dsn", environment="{{_env.name}}", stage="{{_env.stage}}") if not dsn: logger.error("Unable to retrieve Sentry DSN") else: client = raven.Client(dsn) client.captureException() # This is a critical error: must re-raise raise