Build a full data stack that creates a table snapshot from a database and stores it in an Amazon S3 bucket as a JSONL file using Airbyte and then loads the snapshot file to a preferred data warehouse.
Download our free guide and discover the best approach for your needs, whether it's building your ELT solution in-house or opting for Airbyte Open Source or Airbyte Cloud.
Welcome to the "Database Snapshot" repository! This repo provides a quickstart template for building a full data stack that creates a table snapshot from a database and stores it in an Amazon S3 bucket as a JSONL file using Airbyte and then loads the snapshot file to a preferred data warehouse, also using Airbyte.
In this quickstart, we will easily snapshot a sample table from Postgres and then load the table snapshot into BigQuery. The snapshot creation from the database and snapshot loading into the data warehouse are scheduled as one time operations. While this template doesn't delve into specific data, its goal is to showcase the synergy of these tools.
Like other quickstarts, this is designed to minimize setup hassles and propel you forward.
Before you embark on this integration, ensure you have the following set up and ready:
Get the project up and running on your local machine by following these steps:
1. Clone the repository (Clone only this quickstart):
2. Navigate to the directory:
3. Set Up a Virtual Environment:
• For Mac:
• For Windows:
4. Install Dependencies:
Airbyte allows you to create connectors for sources and destinations, facilitating data synchronization between various platforms. In this project, we're harnessing the power of Terraform to automate the creation of these connectors and the connections between them. Here's how you can set this up:
1. Navigate to the Airbyte Configuration Directory:
Change to the relevant directory containing the Terraform configuration for Airbyte:
2. Modify Configuration Files:
Within the infra/airbyte
directory, you'll find three crucial Terraform files:
• provider.tf
: Defines the Airbyte provider.
• main.tf
: Contains the main configuration for creating Airbyte resources.
• variables.tf
: Holds various variables, including credentials.
You'll also find three crucial Terraform modules:
• connections
: Contains the configuration files for the Airbyte connections.
• destinations
: Contains the configuration files for the Airbyte destination connector(s).
• sources
: Contains the configuration files for the Airbyte source connector(s).
In each terraform module, you will find the following Terraform configuration files:
• provider.tf
: Defines the Airbyte provider.
• main.tf
: Contains the main configuration for creating Airbyte resources.
• variables.tf
: Holds various variables, including credentials.
• outputs.tf
: Defines exported data or metadata about your resources.
Adjust the configurations in these files to suit your project's needs. Specifically, provide credentials for your Postgres, S3 (source and destination) and BigQuery connections. You can utilize the variables.tf
files to manage these credentials.
3. Initialize Terraform:
This step prepares Terraform to create the resources defined in your configuration files.
4. Review the Plan:
Before applying any changes, review the plan to understand what Terraform will do.
Apply Configuration:
After reviewing and confirming the plan, apply the Terraform configurations to create the necessary Airbyte resources. A few things to note:
Fixing the first issue (if you encounter it) is straightforward - just create a new bucket with a unique name. However, since you will be snapshotting the database table for the first time, you will definitely have to fix the second issue before you proceed. There are 2 options for this:
Now proceed to create the Airbyte resources.
You will get an error that the S3 to BigQuery
connection cannot be created. Ignore this and proceed. You should now have 5 resources (4 connectors and 1 connection) created in you Airbyte environment;
Confirm this by running the command below
6. Verify in Airbyte UI:
Once Terraform completes its tasks, navigate to the Airbyte UI. Here, you should see your source and destination connectors, as well as the connection between them, set up and ready to go.
After verifying that the 4 connectors and 1 connection have been created, you can proceed to run the snapshot operation.
1. Run the Database Snapshot:
Navigate to the Postgres to S3
connection and click Sync now
to snapshot the database table and save it to your S3.
2. Create the Loading Connection:
Once the snapshot has successfully completed, navigate back to your terraform home directory and create the second connection.
Now you should not see an error since the JSONL files are now present in the S3 bucket. Verify that the connection was created in the Airbyte UI and proceed to Sync now
.
You should now have your table snapshot loaded to your data warehouse.
Once you've set up and launched this initial integration, the real power lies in its adaptability and extensibility. Here’s a roadmap to help you customize and harness this project tailored to your specific data needs:
Download our free guide and discover the best approach for your needs, whether it's building your ELT solution in-house or opting for Airbyte Open Source or Airbyte Cloud.