The "Snowflake External Stage Data Pipeline" project automates the data ingestion process from a MySQL database to Snowflake using an External Stage. This project leverages AWS S3 as an intermediary storage solution, showcasing two distinct pipelines for loading data into Snowflake: one utilizing AWS Lambda and the other using Apache Airflow. Incremental loading is a critical feature for efficiently managing data pipelines, as it ensures that only new or modified data is transferred, saving on both processing time and costs. This approach allows for flexibility and demonstrates various methods of leveraging cloud services for efficient data management.
- External Staging on AWS S3: Data is initially moved from MySQL to an S3 bucket, serving as an external stage for Snowflake.
- Lambda-Based Pipeline: Utilizes AWS Lambda for serverless data loading from S3 to Snowflake, optimizing for efficiency and cost.
- Airflow-Based Pipeline: Leverages Apache Airflow for orchestrated data transfer, providing robust scheduling and monitoring capabilities.
- Incremental Data Loading: Implements an incremental loading approach, ensuring only new or updated records are transferred, optimizing the data ingestion process.
- Metadata-Driven Ingestion: Uses metadata to dynamically manage data flows, enhancing the flexibility and scalability of the pipeline.
- MySQL: Source database for data ingestion.
- Snowflake: Cloud data warehouse for data storage and analysis.
- AWS S3: Used as external staging for data before loading into Snowflake.
- AWS Lambda: Serverless computing service for executing data loading scripts.
- Apache Airflow: Workflow automation and scheduling tool that orchestrates the data pipeline.
- Python: Primary programming language for scripting and automation.
- Data is extracted incrementally from MySQL and loaded into an S3 bucket.
- Two separate pipelines are defined for data loading into Snowflake:
- Lambda Pipeline: Triggered upon new data arrival in S3, executing a script to load data into Snowflake.
- Airflow Pipeline: Scheduled tasks for data extraction, loading to S3, and subsequent loading into Snowflake using External Stage.
- Metadata-driven approach allows for dynamic adaptation of the data ingestion process as source data evolves.
- Explore additional optimizations for handling larger datasets.
- Implement error handling and retry mechanisms for increased reliability.
- Enhance monitoring and alerting for pipeline operations.
There are 2 tables which are getting ingested to Snowflake.
Dedicated Dags are developed for each Table
- amazone_books
- amazonebook_reviews
CREATE TABLE amazone_books ( book_id INT NOT NULL AUTO_INCREMENT ,book_title TEXT ,book_amount FLOAT ,book_author TEXT ,book_rating FLOAT ,book_link TEXT ,business_date DATE DEFAULT(CURRENT_DATE) ,PRIMARY KEY (book_id) );CREATE TABLE amazonebook_reviews ( book_id INT NOT NULL ,reviewer_name TEXT ,rating FLOAT ,review_title TEXT ,review_content TEXT ,reviewed_on DATE ,business_date DATE DEFAULT(CURRENT_DATE) );
For the Incremental load. Primary Keys are required in the Tables. Respective Primary key for the Table are
- amazone_books
- book_id
- amazonebook_reviews
- book_id
- reviewer_name
- business_date
Note: This Source Data is from another Project. To know more about how source data is generated please refer AmazonBooks_DataPipeline
The Airflow Dag Ids for respective Tables are
- amazone_books
- Snowflake_ExternalStage_amazone_books_Dag
- amazonebook_reviews
- Snowflake_ExternalStage_source_amazonebook_review_Dag
- Snowflake_ExternalStage_destination_amazonebook_review_Dag
For Detail Understanding Data Ingestion Using AWS Lambda Services Please refer amazone_books.md
For Detail Understanding Data Ingestion Using Airflow Services Please refer amazonebook_review.md
![image](https://private-user-images.githubusercontent.com/25386607/312163187-0f4df5d8-d40f-4c9e-9aa5-1d0380733607.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3NzY1MzksIm5iZiI6MTcyNTc3NjIzOSwicGF0aCI6Ii8yNTM4NjYwNy8zMTIxNjMxODctMGY0ZGY1ZDgtZDQwZi00YzllLTlhYTUtMWQwMzgwNzMzNjA3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA4VDA2MTcxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc0N2Y0YWJmNGNiMDMzMGQ0NzM3NjY5NWE2ZjgxZDk0ZGI5ZDJjMmFkZjhkNTEzMDEyNTJhNjY1M2I5MmM1NTImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.PhQFWKBTQ4nRcf8DAou3xKYMwBT3rIIU0HzpdAD9Iiw)
![image](https://private-user-images.githubusercontent.com/25386607/312162209-8e0e1578-4591-42ee-9968-5d9083b6e0c9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU3NzY1MzksIm5iZiI6MTcyNTc3NjIzOSwicGF0aCI6Ii8yNTM4NjYwNy8zMTIxNjIyMDktOGUwZTE1NzgtNDU5MS00MmVlLTk5NjgtNWQ5MDgzYjZlMGM5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA4VDA2MTcxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg5ZjQzZjE2ZGE5NzdiYjFjMWMwNmVlNjdjZmVmMTk2Yjg2MWNmZGU5Y2U4ZDgyYWIxZGUxYmMwNjUzM2IzOWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.NZhYNEN2I1IjwDp0z_59uElbqHksOGXIzORVmmZiYxg)
![image](https://private-user-images.githubusercontent.com/25386607/312171106-467923ef-d087-4014-affb-7e7be3223baa.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWI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