Skip to main content

Ingestion Workflows as a Python Virtualenv Operator

PROs

  • Installation does not clash with existing libraries
  • Simpler than ECS

CONs

  • We need to install an additional plugin in MWAA
  • DAGs take longer to run due to needing to set up the virtualenv from scratch for each run.
We need to update the requirements.txt file from the MWAA environment to add the following line:
Then, we need to set up a custom plugin in MWAA. Create a file named virtual_python_plugin.py. Note that you may need to update the python version (eg, python3.7 -> python3.10) depending on what your MWAA environment is running.
This is modified from the AWS sample. Next, create the plugins.zip file and upload it according to AWS docs. You will also need to disable lazy plugin loading in MWAA. A DAG deployed using the PythonVirtualenvOperator would then look like:
Where you can update the YAML configuration and workflow classes accordingly. Further examples on how to run the ingestion can be found on the documentation (e.g., Snowflake). You will also need to determine the OpenMetadata ingestion extras and Airflow providers you need. The OpenMetadata ingestion package should match your server minor version. For example, use a 1.13.x ingestion package with a 1.13.x server, and include the connector extras required by your YAML, such as openmetadata-ingestion[mysql,snowflake,s3]~=1.13.0. For Airflow providers, you will want to pull the provider versions from the matching constraints file. Since this example installs Airflow Providers v2.4.3 on Python 3.7, we use that constraints file. Also note that the ingestion workflow function must be entirely self-contained as it will run by itself in the virtualenv. Any imports it needs, including the configuration, must exist within the function itself.

Ingestion Workflow classes

We have different classes for different types of workflows. The logic is always the same, but you will need to change your import path. The rest of the method calls will remain the same. For example, for the Metadata workflow we’ll use:
The classes for each workflow type are:
  • Metadata: from metadata.workflow.metadata import MetadataWorkflow
  • Lineage: from metadata.workflow.metadata import MetadataWorkflow (same as metadata)
  • Usage: from metadata.workflow.usage import UsageWorkflow
  • dbt: from metadata.workflow.metadata import MetadataWorkflow
  • Profiler: from metadata.workflow.profiler import ProfilerWorkflow
  • Data Quality: from metadata.workflow.data_quality import TestSuiteWorkflow
  • Data Insights: from metadata.workflow.data_insight import DataInsightWorkflow
  • Elasticsearch Reindex: from metadata.workflow.metadata import MetadataWorkflow (same as metadata)