19 C
Canberra
Wednesday, March 4, 2026

Construct end-to-end Apache Spark pipelines with Amazon MWAA, Batch Processing Gateway, and Amazon EMR on EKS clusters


Apache Spark workloads operating on Amazon EMR on EKS type the muse of many trendy information platforms. EMR on EKS affords advantages by offering managed Spark that integrates seamlessly with different AWS providers and your group’s current Kubernetes-based deployment patterns.

Information platforms processing large-scale information volumes typically require a number of EMR on EKS clusters. Within the publish Use Batch Processing Gateway to automate job administration in multi-cluster Amazon EMR on EKS environments, we launched Batch Processing Gateway (BPG) as an answer for managing Spark workloads throughout these clusters. Though BPG gives foundational performance to distribute workloads and help routing for Spark jobs in multi-cluster environments, enterprise information platforms require extra options for a complete information processing pipeline.

This publish reveals learn how to improve the multi-cluster answer by integrating Amazon Managed Workflows for Apache Airflow (Amazon MWAA) with BPG. By utilizing Amazon MWAA, we add job scheduling and orchestration capabilities, enabling you to construct a complete end-to-end Spark-based information processing pipeline.

Overview of answer

Take into account HealthTech Analytics, a healthcare analytics firm managing two distinct information processing workloads. Their Medical Insights Information Science group processes delicate affected person consequence information requiring HIPAA compliance and devoted assets, and their Digital Analytics group handles web site interplay information with extra versatile necessities. As their operation grows, they face growing challenges in managing these numerous workloads effectively.

The corporate wants to take care of strict separation between protected well being info (PHI) and non-PHI information processing, whereas additionally addressing totally different price middle necessities. The Medical Insights Information Science group runs important end-of-day batch processes that want assured assets, whereas the Digital Analytics group can use cost-optimized spot situations for his or her variable workloads. Moreover, information scientists from each groups require environments for experimentation and prototyping as wanted.

This situation presents a great use case for implementing an information pipeline utilizing Amazon MWAA, BPG, and a number of EMR on EKS clusters. The answer must route totally different Spark workloads to acceptable clusters based mostly on safety necessities and price profiles, whereas sustaining the mandatory isolation and compliance controls. To successfully handle such an surroundings, we want an answer that maintains clear separation between software and infrastructure administration considerations and stitching collectively a number of parts into a sturdy pipeline.

Our answer consists of integrating Amazon MWAA with BPG by way of an Airflow customized operator for BPG known as BPGOperator. This operator encapsulates the infrastructure administration logic wanted to work together with BPG. BPGOperator gives a clear interface for job submission by way of Amazon MWAA. When executed, the operator communicates with BPG, which then routes the Spark workloads to obtainable EMR on EKS clusters based mostly on predefined routing guidelines.

The next structure diagram illustrates the parts and their interactions.

Image showing the end to end architecture for end-to-end pipeline

The answer works by way of the next steps:

  • Amazon MWAA executes scheduled DAGs utilizing BPGOperator. Information engineers create DAGs utilizing this operator, requiring solely the Spark software configuration file and primary scheduling parameters.
  • BPGOperator authenticates and submits jobs to the BPG submit endpoint POST:/apiv2/spark. It handles all HTTP communication particulars, manages authentication tokens, and gives safe transmission of job configurations.
  • BPG routes submitted jobs to EMR on EKS clusters based mostly on predefined routing guidelines. These routing guidelines are managed centrally by way of BPG configuration, permitting rules-based distribution of workloads throughout a number of clusters.
  • BPGOperator displays job standing, captures logs, and handles execution retries. It polls the BPG job standing endpoint GET:/apiv2/spark/{subID}/standing and streams logs to Airflow by polling the GET:/apiv2/log endpoint each second. The BPG log endpoint retrieves probably the most present log info immediately from the Spark Driver Pod.
  • The DAG execution progresses to subsequent duties based mostly on job completion standing and outlined dependencies. BPGOperator communicates the job standing by way of Airflow’s built-in job communication system, enabling advanced workflow orchestration.

Seek advice from the BPG REST API interface documentation for extra particulars.

This structure gives a number of key advantages:

  • Separation of duties – Information Engineering and Platform Engineering groups in enterprise organizations sometimes keep distinct duties. The modular design on this answer allows platform engineers to configure BPGOperator and handle EMR on EKS clusters, whereas information engineers keep DAGs.
  • Centralized code administration – BPGOperator encapsulates all core functionalities required for Amazon MWAA DAGs to submit Spark jobs by way of BPG right into a single, reusable Python module. This centralization minimizes code duplication throughout DAGs and improves maintainability by offering a standardized interface for job submissions.

Airflow customized operator for BPG

An Airflow Operator is a template for a predefined Job which you can outline declaratively inside your DAGs. Airflow gives a number of built-in operators akin to BashOperator, which executes bash instructions, PythonOperator, which executes Python features, and EmrContainerOperator, which submits new jobs to an EMR on EKS cluster. Nevertheless, no built-in operators exist to implement all of the steps required for the Amazon MWAA integration with BPG.

Airflow means that you can create new operators to fit your particular necessities. This operator sort is called a customized operator. A customized operator encapsulates the customized infrastructure-related logic in a single, maintainable part. Customized operators are created by extending the airflow.fashions.baseoperator.BaseOperator class. We’ve developed and open sourced an Airflow customized operator for BPG known as BPGOperator, which implements the mandatory steps to supply a seamless integration of Amazon MWAA with BPG.

The next class diagram gives an in depth view of the BPGOperator implementation.

Image showing class diagram for BPGOperator implementation

When a DAG features a BPGOperator job, the Amazon MWAA occasion triggers the operator to ship a job request to BPG. The operator sometimes performs the next steps:

  • Initialize job – BPGOperator prepares the job payload, together with enter parameters, configurations, connection particulars, and different metadata required by BPG.
  • Submit job – BPGOperator handles HTTP POST requests to submit jobs to BPG endpoints with the supplied configurations.
  • Monitor job execution – BPGOperator checks the job standing, polling BPG till the job completes efficiently or fails. The monitoring course of consists of dealing with varied job states, managing timeout situations, and responding to errors that happen throughout job execution.
  • Deal with job completion – Upon completion, BPGOperator captures the job outcomes, logs related particulars, and might set off downstream duties based mostly on the execution consequence.

The next sequence diagram illustrates the interplay move between the Airflow DAG, BPGOperator, and BPG.

Image showing sequence diagram for the interaction between the Airflow DAG, BPGOperator, and BPG.

Deploying the answer

Within the the rest of this publish, you’ll implement the end-to-end pipeline to run Spark jobs on a number of EMR on EKS clusters. You’ll start by deploying the widespread parts that function the muse for constructing the pipelines. Subsequent, you’ll deploy and configure BPG on an EKS cluster, adopted by deploying and configuring BPGOperator on Amazon MWAA. Lastly, you’ll execute Spark jobs on a number of EMR on EKS clusters from Amazon MWAA.

To streamline the setup course of, we’ve automated the deployment of all infrastructure parts required for this publish, so you may give attention to the important facets of job submission to construct an end-to-end pipeline. We offer detailed info that can assist you perceive every step, simplifying the setup whereas preserving the training expertise.

To showcase the answer, you’ll create three clusters and an Amazon MWAA surroundings:

  • Two EMR on EKS clusters: analytics-cluster and datascience-cluster
  • An EKS cluster: gateway-cluster
  • An Amazon MWAA surroundings: airflow-environment

analytics-cluster and datascience-cluster function information processing clusters that run Spark workloads, gateway-cluster hosts BPG, and airflow-environment hosts Airflow for job orchestration and scheduling.

You could find the code base within the GitHub repo.

Conditions

Earlier than you deploy this answer, ensure that the next stipulations are in place:

Arrange widespread infrastructure

This step handles the setup of networking infrastructure, together with digital non-public cloud (VPC) and subnets, together with the configuration of AWS Id and Entry Administration (IAM) roles, Amazon Easy Storage Service (Amazon S3) storage, Amazon Elastic Container Registry (Amazon ECR) repository for BPG pictures, Amazon Aurora PostgreSQL-Appropriate Version database, Amazon MWAA surroundings, and each EKS and EMR on EKS clusters with a preconfigured Spark operator. With this infrastructure mechanically provisioned, you may consider the following steps with out getting caught up in primary setup duties.

  1. Clone the repository to your native machine and set the 2 surroundings variables. Change with the AWS Area the place you need to deploy these assets.
    git clone https://github.com/aws-samples/sample-mwaa-bpg-emr-on-eks-spark-pipeline.git
    cd sample-mwaa-bpg-emr-on-eks-spark-pipeline
    			
    export REPO_DIR=$(pwd)
    export AWS_REGION=

  2. Execute the next script to create the widespread infrastructure:
    cd ${REPO_DIR}/infra
    ./setup.sh

  3. To confirm profitable infrastructure deployment, navigate to the AWS CloudFormation console, open your stack, and verify the Occasions, Sources, and Outputs tabs for completion standing, particulars, and checklist of assets created.

You may have accomplished the setup of the widespread parts that function the muse for remainder of the implementation.

Arrange Batch Processing Gateway

This part builds the Docker picture for BPG, deploys the helm chart on the gateway-cluster EKS cluster, and exposes the BPG endpoint utilizing Kubernetes service of sort LoadBalancer. Full the next steps:

  1. Deploy BPG on the gateway-cluster EKS cluster:
    cd ${REPO_DIR}/infra/bpg
    ./configure_bpg.sh

  2. Confirm the deployment by itemizing the pods and viewing the pod logs:
    kubectl get pods --namespace bpg
    kubectl logs  --namespace bpg

    Evaluation the logs and make sure there aren’t any errors or exceptions.

  3. Exec into the BPG pod and confirm the well being verify:
    kubectl exec -it  -n bpg -- bash
    curl -u admin:admin localhost:8080/skatev2/healthcheck/standing

    The healthcheck API ought to return a profitable response of {"standing":"OK"}, confirming profitable deployment of BPG on the gateway-cluster EKS cluster.

We’ve efficiently configured BPG on gateway-cluster and arrange EMR on EKS for each datascience-cluster and analytics-cluster. That is the place we left off within the earlier weblog publish. Within the subsequent steps, we are going to configure Amazon MWAA with BPGOperator, after which write and submit DAGs to show an end-to-end Spark-based information pipeline.

Configure the Airflow operator for BPG on Amazon MWAA

This part configures the BPGOperator plugin on the Amazon MWAA surroundings airflow-environment. Full the next steps:

  1. Configure BPGOperator on Amazon MWAA:
    cd ${REPO_DIR}/bpg_operator
    ./configure_bpg_operator.sh

  2. On the Amazon MWAA console, navigate to the airflow-environment surroundings.
  3. Select Open Airflow UI, and within the Airflow UI, select the Admin dropdown menu and select Plugins.
    You will notice the BPGOperator plugin listed within the Airflow UI.
    Image showing BPGOperator plugin listed in the Airflow UI

Configure Airflow connections for BPG integration

This part guides you thru establishing the Airflow connections that allow safe communication between your Amazon MWAA surroundings and BPG. BPGOperator makes use of the configured connection to authenticate and work together with BPG endpoints.

Execute the next script to configure the Airflow connection bpg_connection.

cd $REPO_DIR/airflow
./configure_connections.sh

Within the Airflow UI, select the Admin dropdown menu and select Connections. You will notice the bpg_connection listed within the Airflow UI.

Image showing Airflow Connections page with bpg_connection configured.

Configure the Airflow DAG to execute Spark jobs

This step configures an Airflow DAG to run a pattern software. On this case, we are going to submit a DAG containing a number of pattern Spark jobs utilizing Amazon MWAA to EMR on EKS clusters utilizing BPG. Please look forward to couple of minutes for the DAG to seem within the Airflow UI.

cd $REPO_DIR/jobs
./configure_job.sh

Set off the Amazon MWAA DAG

On this step, we set off the Airflow DAG and observe the job execution habits, together with reviewing the Spark logs within the Airflow UI:

  1. Within the Airflow UI, evaluation the MWAASparkPipelineDemoJob DAG and select the play icon set off the DAG.
    Image showing sample Airflow Job, highlighting the play button to trigger the job
  2. Await DAG to finish efficiently.
    Upon profitable completion of the DAG, you need to see Success:1 beneath the Runs column.
  3. Within the Airflow UI, find and select the MWAASparkPipelineDemoJob DAG.
  4. On the Graph tab, select any job (on this instance, we choose the calculate_pi job) after which select the Logs
    Image showing the MWAASparkPipelineDemoJob's graph view
  5. View the Spark logs within the Airflow UI.
    Image showing the MWAASparkPipelineDemoJob calculate_pi task logs

Migrate current Airflow DAGs to make use of BPG

In enterprise information platforms, a typical information pipeline consists of Amazon MWAA submitting Spark jobs to a number of EMR on EKS clusters utilizing the SparkKubernetesOperator and an Airflow Connection of sort Kubernetes. An Airflow Connection is a set of parameters and credentials used to ascertain communication between Amazon MWAA and exterior methods or providers. A DAG refers back to the connection identify and connects to the exterior system.

The next diagram reveals the standard structure.
Image showing the existing job execution workflows not using BPG

On this setup, Airflow DAGs sometimes makes use of SparkKubernetesOperator and SparkKubernetesSensor to submit Spark jobs to a distant EMR on EKS cluster utilizing kubernetes_conn_id=.

The next code snippet reveals the related particulars:

# Submit Spark-Pi job utilizing Kubernetes connection
submit_spark_pi = SparkKubernetesOperator(
	task_id='submit_spark_pi',
	namespace="default",
	application_file=spark_pi_yaml,
	kubernetes_conn_id='emr_on_eks_connection_[1|2]',  # Connection ID outlined in Airflow
	dag=dag
)

Emigrate the infrastructure to a BPG-based infrastructure with out impacting the continuity of the surroundings, we are able to deploy a parallel infrastructure utilizing BPG, create a brand new Airflow Connection for BPG, and incrementally migrate the DAGs to make use of the brand new connection. By doing so, we received’t disrupt the present infrastructure till the BPG-based infrastructure is totally operational, together with the migration of all current DAGs.

The next diagram showcases the interim state the place each the Kubernetes connection and BPG connection are operational. Blue arrows point out the present workflow paths, and pink arrows signify the brand new BPG-based migration paths.

Image showing the existing workflow paths and the new bpg based migration path

The modified code snippet for the DAG is as follows:

# Submit Spark-Pi job utilizing BPG connection
submit_spark_pi = BPGOperator(
	task_id='submit_spark_pi',
	application_file=spark_pi_yaml,
	application_file_type="yaml"
	connection_id='bpg_connection',  # Connection ID outlined in Airflow
	dag=dag
)

Lastly, when all of the DAGs have been modified to make use of BPGOperator as a substitute of SparkKubernetesOperator, you may decommission any remnants of the outdated workflow. The ultimate state of the infrastructure will appear to be the next diagram.

Image showing the final state of the infrastructure after all the job migrations are complete.

Utilizing this method, we are able to seamlessly introduce BPG into an surroundings that presently makes use of solely Amazon MWAA and EMR on EKS clusters.

Clear up

To keep away from incurring future fees from the assets created on this tutorial, clear up your surroundings after you’ve accomplished the steps. You are able to do this by operating the cleanup.sh script, which can safely take away all of the assets provisioned through the setup:

cd ${REPO_DIR}/setup
./cleanup.sh

Conclusion

Within the publish Use Batch Processing Gateway to automate job administration in multi-cluster Amazon EMR on EKS environments, we launched Batch Processing Gateway as an answer for routing Spark workloads throughout a number of EMR on EKS clusters. On this publish, we demonstrated learn how to improve this basis by integrating BPG with Amazon MWAA. By way of our customized BPGOperator, we’ve proven learn how to construct sturdy end-to-end Spark-based information processing pipelines whereas sustaining clear separation of duties and centralized code administration. Lastly, we demonstrated learn how to seamlessly incorporate the answer into your current Amazon MWAA and EMR on EKS information platform with out impacting operational continuity.

We encourage you to experiment with this structure in your personal surroundings, adapting it to suit your distinctive workloads and operational necessities. By implementing this answer, you may construct environment friendly and scalable information processing pipelines that use the complete potential of EMR on EKS and Amazon MWAA. Discover additional by deploying the answer in your AWS account whereas adhering to your organizational safety finest practices and share your experiences with the AWS Large Information group.


Concerning the Authors

Suvojit DasguptaSuvojit Dasgupta is a Principal Information Architect at AWS. He leads a group of expert engineers in designing and constructing scalable information options for AWS prospects. He makes a speciality of creating and implementing modern information architectures to handle advanced enterprise challenges.

Avinash DesireddyAvinash Desireddy is a Cloud Infrastructure Architect at AWS, obsessed with constructing safe functions and information platforms. He has intensive expertise in Kubernetes, DevOps, and enterprise structure, serving to prospects containerize functions, streamline deployments, and optimize cloud-native environments.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles