<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paul Nwosu on Medium]]></title>
        <description><![CDATA[Stories by Paul Nwosu on Medium]]></description>
        <link>https://medium.com/@nwosupaul141?source=rss-1d15f1032400------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*U_yvuBoXMB-HLs3t.jpg</url>
            <title>Stories by Paul Nwosu on Medium</title>
            <link>https://medium.com/@nwosupaul141?source=rss-1d15f1032400------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:41:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nwosupaul141/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Adding Observability and Monitoring to Your Prefect Dataflows.]]></title>
            <link>https://medium.com/@nwosupaul141/adding-observability-and-monitoring-to-your-prefect-dataflows-4e1df6fc6c04?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/4e1df6fc6c04</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 12 May 2023 08:59:29 GMT</pubDate>
            <atom:updated>2023-05-12T08:59:29.702Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Jsv5UA6b5ZfFuPZSnT1CA.png" /></figure><p>DataOps represents a fundamental aspect of the Data Engineering Lifecycle, characterized by three key principles: Automation, Observability and Monitoring, and Incident Response. Prefect happens to be a modern data orchestration tool that can do all these for you seamlessly. I have written about how to get started with Prefect in some of my articles, and in this article, we will be exploring how to use Prefect to monitor your dataflow pipelines.</p><h3>Why Monitor Your Pipelines?</h3><p>Even with a well-developed data pipeline that performs its intended tasks, you still need to factor in the possibility of failure. The goal of every data engineer is to build a scalable pipeline, deploy it, and ensure it functions as expected. However, scheduled pipelines can encounter errors such as out-of-memory or file not found issues. To promptly detect any pipeline disruptions, it is crucial to set up alerts.</p><p>Datadog and New Relic offer robust observability and alerting capabilities, making them valuable assets in this field. It’s important to note that leveraging these tools requires a certain level of technical proficiency, as they involve additional skills and configuration requirements.</p><p>With Prefect Automation, the process is simplified. All you need to do is create a block representing your desired alerting system (Slack/Email), select a conditional trigger, and choose the necessary action. This allows you to establish an event-driven, fully robust monitoring pipeline without much effort.</p><p>By embracing Prefect Automation, you can streamline your monitoring process and focus on ensuring the resilience and reliability of your data pipeline.</p><h3>Getting Started</h3><p>In this mini-guide, we will utilize both Slack and Email as our alerting systems. An alerting system refers to the platform through which we receive notifications if our pipeline encounters any issues. To get started, make sure you have the following:</p><ul><li>An Email/Gmail address: This will be used to receive email alerts regarding pipeline breakages.</li><li>A Slack Account and Workspace with admin access: Ensure you have a Slack account and access to a workspace where you can configure and receive alerts.</li><li>A Slack webhook: Generate a Slack webhook, which will enable communication between Prefect and your desired Slack channel.</li><li>A Prefect Cloud account: Sign up for a Prefect Cloud account, which will provide the necessary infrastructure for managing and monitoring your dataflow pipelines.</li><li>Familiarity with Prefect: Understand how to use Prefect to create dataflow pipelines. This knowledge will be essential for writing and testing your Prefect Flow.</li><li>A Python script: Prepare a Python script that you can utilize to test your Prefect Flow and ensure its proper functioning.</li></ul><p>For the last three requirements, check out my previous article on how to get started with Prefect:</p><p><a href="https://medium.com/@nwosupaul141/orchestrating-data-pipelines-with-prefect-on-gcp-infrastructure-cdc7aaf42250">Orchestrating Data Pipelines with Prefect on GCP Infrastructure</a></p><h3>Setting up a Slack Webhook to Monitor Your Dataflow</h3><p>In the realm of event-driven architecture, webhooks have become a familiar and valuable concept for capturing logs from external systems. Webhooks operate on a straightforward event-based data transmission pattern. The data source can range from an application backend to a web page or a mobile app. When specific events occur in the source system, it triggers a call to an HTTP endpoint hosted by the data consumer.</p><p>This endpoint can perform various actions with the received POST event data, such as initiating downstream processes or storing the data for future use. In our case, we’re interested in collecting logs from our Prefect flows in the event of a failure or breakage.</p><p>Here are three key aspects to consider:</p><ul><li>Event Triggering: We need to establish an event trigger, specifically focusing on detecting when our pipeline breaks. This trigger will initiate subsequent actions to capture the necessary logs.</li><li>Request with Payload: When a pipeline break occurs, we aim to capture essential details such as the error message, event time, and flow name. This information is typically captured as a POST action and sent back as messages to the data consumer, in this case, a Slack channel.</li><li>HTTP Endpoint: The Slack webhook URL serves as the API endpoint hosted by the data consumer (Slack channel). It is the target to which the data provider (Prefect) makes API calls, facilitating the transmission of captured logs and triggering the desired actions within the Slack channel.</li></ul><p>Before we get started, ensure you have a Slack account, and create a personal workspace that you can use for testing.</p><h4>Create a Slack App</h4><p>Navigate to <a href="https://api.slack.com/apps/">https://api.slack.com/apps/</a> and click on the Create New App , you will be presented with two options: From Scratch , From an App Manifest , select the former.</p><p>Select a name for the app, and choose the workspace you just created. Create the app. You will be redirected to the app page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*clgkwf5XBZoDtd4f1nH1SQ.png" /></figure><p>Find OAuth &amp; Permissions under Features, navigate to User Token Scopes and add the admin oauth scope .</p><p>Navigate back to Install App under Settings and click on Install App , follow-up instructions.</p><p>Navigate to Incoming Webhooks under Features and activate the toggle button. You will see a pop-up above, follow all necessary instructions, and add the channel you want to post messages to.</p><p>Scroll down to copy your Webhook Url, you will need this to connect your to Prefect account.</p><h4>Test that the Slack App Works</h4><p>On the Incoming Webhooks page you should see a curl request, copy this command, and paste it on your command line. Check your Slack channel to confirm that you got the message. The curl request should look like this:</p><pre>curl -X POST -H &#39;Content-type: application/json&#39; --data &#39;{&quot;text&quot;:&quot;Hello, World!&quot;}&#39; https://hooks.slack.com/services/TFQEB/B052C/4Dl5uOKWXzM</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZZG_HplVabkqxYqRqVZ3JA.png" /></figure><h4>Create a Prefect Block</h4><p>Blocks are a primitive within Prefect that enable the storage of configuration and provide an interface for interacting with external systems.</p><p>With blocks, you can securely store credentials for authenticating with services like AWS, GitHub, Slack, and any other system you’d like to orchestrate with Prefect.</p><p>Blocks expose methods that provide pre-built functionality for performing actions against an external system. They can be used to download data from or upload data to an S3 bucket, query data from or write data to a database, or send a message to a Slack channel.</p><p>To create a Slack Block:</p><ul><li>Navigate to your Prefect Cloud Workspace</li><li>Click on the Name of your Workspace</li><li>Navigate to the Blocks Tab, and click on the + icon to create a new block</li><li>Search for the Slack Webhook block; ensure you choose this one, as you might see other blocks such as Slack Credentials and Slack Incoming Webhook</li><li>Create a name for the clock and add the Slack webhook.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZ1o_O6RkYmP-Tu9qII1Zg.png" /></figure><p>You should also create an Email Block since we would also love to be alerted via mail; follow the steps above, look for the Email block, give the block a name, and add your email address as seen in the format below. You can always add more than one email address.</p><pre>[&quot;dfgurrgri@gmail.com&quot;]</pre><h3>Create an Automation</h3><p>Prefect Automations introduce a powerful combination of triggers and actions, empowering users to define conditional logic using the “if/then” paradigm. By leveraging Prefect Automation, you can surpass traditional proactive scheduling methods. Instead, your dataflow gains the ability to automatically and dynamically respond to observed events within your environment.</p><p>To create an automation, navigate to the Automations Plane;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DEHXjbIiymglQ6OeLTkD-Q.png" /></figure><h4>Create a Trigger</h4><p>Users can configure automations with triggers that detect in real-time when flows or work queues enter or stay in various states. You can target specific flows, or create broader SLAs for your dataflow based on tags. The trigger for the workflow would be to capture any flow that fails.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JN6ylnPtNEXuCFyie8maBg.png" /></figure><h4>Create the Actions</h4><p>Users can configure one or more actions to execute when their trigger criteria are met, including starting or stopping flow runs, work queues, deployment schedules, or sending notifications. Actions are highly parameterizable with Jinja templating, and can even infer their inputs at runtime based on context. Our specific actions would be to:</p><ul><li>Send a notification to the Slack channel we created.</li><li>Send an alert via the mail address we provided</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AFol_DlHmhpCabiUra1Wpw.png" /></figure><h4>Test that your Automation Works</h4><p>Now that you have created automation, you can run a faulty pipeline and confirm if you will get alerted on the Slack channel and via mail.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0XX05B_92Hn9zz5fNfcT_g.png" /></figure><p>While running my pipeline, I run into a file not found error ; this is because I used the wrong bucket when creating my google cloud storage block.</p><p>Here is a snippet of the code, you can check out the full code <a href="https://github.com/paulonye/prefect_gcp/blob/main/prefect_gcp_local/etl_gcs_bq.py">here</a></p><pre>@task(retries=3, tags=[&quot;extract&quot;])<br>def extract_from_gcs(color: str, year: int, month: int) -&gt; Path:<br>    &quot;&quot;&quot;Download trip data from GCS&quot;&quot;&quot;<br>    gcs_path = f&quot;data/{color}/{color}_tripdata_{year}-{month:02}.parquet&quot;<br>    gcs_block = GcsBucket.load(&quot;zoom-gcs&quot;)<br>    local_path = Path(f&quot;.&quot;)<br>    gcs_block.get_directory(from_path=gcs_path, local_path=local_path)<br>    return Path(gcs_path)</pre><h3>Conclusion</h3><p>The ability to capture flow failures as triggers exemplify the power of Prefect Automation. By promptly detecting and responding to pipeline failures, data engineers can ensure the integrity and reliability of their data processing workflows.</p><p>With Prefect Automations, data engineers can transcend static scheduling and proactively address issues, providing a more responsive and adaptive dataflow environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4e1df6fc6c04" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Serverless ELT Pipeline with DBT Cloud and Google Bigquery]]></title>
            <link>https://medium.com/@nwosupaul141/building-a-serverless-elt-pipeline-with-dbt-cloud-and-google-bigquery-e781607655d8?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/e781607655d8</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 31 Mar 2023 09:47:55 GMT</pubDate>
            <atom:updated>2023-03-31T09:47:55.256Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BgGeOgLSFO105Baqu7yIHg.png" /></figure><p>DBT, short for Data Build Tool, is a widely-used tool for data transformation in the industry. With DBT, you can easily build, test, and run models on the data stored in your data warehouse. DBT enables you to create an ELT (extract, load, and transform) data pipeline and store the transformation queries in your GitHub repository, providing you with the benefits of version control.</p><h3>Project Structure</h3><ul><li>Introduction</li><li>Set up of Environment and Configuration</li><li>Getting Started with DBT Core and DBT Cloud</li><li>Extracting Data from Google Cloud Storage into Bigquery using External Tables</li><li>Extracting Data from Google Cloud Storage into Bigquery using Google Cloud Functions</li><li>Extracting Data from Google CloudSQL into Bigquery using Federated Queries</li><li>Conclusion</li></ul><h3>Introduction</h3><p>In the seventh part of my series on Building Data Applications on Google Cloud, we explore the use of DBT in the world of analytics. DBT is a popular tool used extensively in Analytics Engineering. It enables you to write SQL queries and store them in .sqlfiles which are called models. With DBT, you can establish a connection to your database or data warehouse and execute queries on top of it. It should be noted that DBT operates using the computing infrastructure of your database or data warehouse when running its models. Typically, DBT uses the selectcommand to build models, not the createcommand.</p><p>In this project, we will start by installing DBT and its dependencies, setting up the necessary configurations, and then building a data platform that allows us to run our pipeline effortlessly.</p><h3>Set up of Environment and Configuration</h3><p>We need to follow a couple of steps to ensure that we set up our environment.</p><h4>Install DBT</h4><p>DBT can be installed using pip, either on its own or along with a database or data warehouse adapter. For this project, we will install DBT using the BigQuery adapter. To get started, you can activate a virtual Python environment.</p><pre>python -m venev env<br><br>source env/bin/activate<br><br>pip install dbt-bigquery</pre><p>Once you have installed the dbt-bigquery adapter, you can check the version using dbt --version . You should see:</p><pre>Core:<br>  - installed: 1.4.5<br>  - latest:    1.4.5 - Up to date!<br><br>Plugins:<br>  - bigquery: 1.4.3 - Up to date!</pre><p>Every adapter you install comes with DBT Core. Another crucial step is initializing your DBT project, but we will discuss this later.</p><h4>Set up your Database/Datawarehouse Schema</h4><p>DBT doesn’t have its own computing infrastructure; it utilizes the computing resources of the machine where your database is installed or, in most cases, uses the computing resources of the data warehouse itself. Since our goal is to create a serverless solution, we will be using BigQuery, which is Google’s Serverless Data Warehouse Solution. In this case, we need to create datasets that will host our tables. Datasets are similar to schemas in Snowflake’s Data Warehouse and Postgres Database.</p><p>To create a dataset, navigate to your Google Cloud Console and search for BigQuery. On the SQL Workspace tab, locate and click on the three dots behind your project ID, then select Create Dataset.</p><p>Fill in the necessary details as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HkzsdQ8bAj4HlJ51c5622w.png" /></figure><p>As seen above, we created a dataset called test_staging. We also need to create another dataset called test_analytics. We are creating two different datasets so that we can develop and test our models on test_staging before running them on test_analytics. This concept allows us to follow best engineering practices, ensuring that we don’t load incorrect data.</p><p>Please take note of the name of the dataset and the region where they are stored. You will need this information in other configuration settings.</p><h4>Set up and Download a Service Account Key</h4><p>Navigate to your google cloud environment and create a service account key (assign necessary permissions such as big query admin), and download this key. If you are working on a remote machine, as expected if you have been following this tutorial, use sftp to log into the remote machine and use the put command to copy this key into your remote machine.</p><p>That’s all the authentication you need to do for now!</p><h3>Getting Started with DBT Core and DBT Cloud</h3><p>DBT has two main components: dbt core and dbt cloud. Dbt core is an open-source project that can be used locally, while dbt cloud is a SaaS application that can be used to run dbt models.</p><p>Generally, I prefer using dbt cloud because, like any SaaS tool, the level of configuration needed is abstracted to a high level. However, learning dbt core allows you to understand how dbt works, and for that reason, we will cover how to set up both dbt core and dbt cloud in this project.</p><h4>Setting up DBT Core</h4><p>In the previous section, we installed dbt-bigquery, which is the dbt adapter for BigQuery. Recall that dbt core was also installed. With dbt core, we can do the following:</p><ul><li>Build and run dbt models using .sqland .yamlfiles</li><li>Use the CLI to run dbt commands</li><li>Develop and test your models locally with Docker containers</li><li>Set up multiple profiles that you can use to run different dbt projects and for different environments.</li></ul><p>One of the most important steps when installing a dbt project is to tie it to a GitHub repository.</p><p>To create a dbt project and tie it to a GitHub repo, follow these steps:</p><ol><li>Create a GitHub repository and clone it in your local development environment.</li><li>Navigate to the directory of the repository you created and initialize dbt using the command dbt init.</li><li>During initialization, you’ll be prompted to enter the following details:</li></ol><ul><li>Enter a name for your dbt project.</li><li>Select the database you want to use (this depends on the adapter you have installed). In our case, we are using BigQuery.</li><li>Select the authentication method and input the location where you stored your service account key.</li><li>Input your Google Cloud Project ID and the name of the dataset that you created (use the “test_staging” schema that you created).</li><li>Select the number of threads (input 4; if you are dealing with a large dataset, you can increase this).</li><li>Input the job execution time in seconds (input 300).</li><li>Input the region where you created the dataset and select “US” since we created the dataset in the “us-east1” region.</li></ul><p>After following the steps above, two things are created for you:</p><ul><li>A profile.yml file is located in .dbt folder in your home directory. Navigate to this directory, and open the profile.yml file so that you can change the region of your dataset from US to us-east1. It is important you do this unless you will get an error that the dataset can’t be found. Save and close the file.</li><li>A dbt project within the GitHub repo directory that you created. This folder contains everything you need to get started with dbt. Navigate into the folder and run the dbt debug command to confirm that all credentials are set correctly.</li></ul><p>That’s all you need to get started with dbt core for now! Let’s proceed to dbt cloud.</p><h4>Setting up DBT Cloud</h4><p>Starting with DBT cloud can be a simpler option than using dbt core, as it provides several benefits:</p><ul><li>A web-based integrated development environment (IDE) for creating, running, and testing dbt projects.</li><li>Jobs orchestration to automate workflows.</li><li>Logging and alerting to keep track of project progress and issues.</li><li>Integrated documentation to keep track of project changes and details.</li><li>It is free for individuals with one developer seat.</li></ul><p>To get started with dbt cloud, navigate to <a href="https://cloud.getdbt.com/login">https://cloud.getdbt.com/login</a> to create your account, and follow the necessary steps.</p><ul><li>The first step will be to create a connection to your data warehouse or data platform such as data bricks. For this project, we will create a connection to big query.</li><li>Upload your service account key; all the default information will be filled in automatically.</li><li>Scroll down to development credentials and change the dataset name to the one you created.</li><li>Set up a connection to your GitHub repository; you will need to make a connection to your repository; select the repository you created.</li><li>Once you are done with all the necessary authentication, you will be redirected to your development environment, where you can initialize your environment and start developing your models.</li></ul><p>DBT is what enables the T in the ELT process, now let’s look at some ways in which we can extract and load our data into a big query.</p><h3>Extracting Data into Big Query Using External Tables</h3><p>BigQuery offers two ways to query data from Cloud Storage: External Tables and Native Tables. External Tables source the data directly from Cloud Storage, which means that they always query the latest data. However, although you can limit the amount of data scanned, external tables do not leverage caching, and queries can be slower as a result. For this project, we will create an External Table from a CSV file stored in a Google Cloud Storage Bucket. The BigQuery table will be updated as the data in the CSV file is updated since the data is not stored in BigQuery.</p><p>Here is how to create an external table from Cloud Storage in Big Query:</p><ul><li>Open the BigQuery console.</li><li>Select the dataset where you want to create the external table. In our case, we will use the test_staging dataset that we created earlier.</li><li>Click “Create Table” to create a new table.</li><li>Select “External Table” as the table type.</li><li>Choose a unique name for your table, and select the options for your external data source, such as CSV format, Cloud Storage location, and schema.</li><li>Click “Create Table” to create the external table.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*myCShfGFC86_Zb_J7tJORw.png" /></figure><p>It is important that you create an external table as this will be up to date in near-real-time. A native table would not update the data in the table unless you override it by running a new query.</p><p>Once the data has been loaded, we are good to go, and can then connect it to our DBT project.</p><h3>Extracting Data into Big Query Using Cloud Functions</h3><p>In the previous section, we discussed loading data from a cloud storage bucket by creating an external table. However, we can also accomplish this task by using a native table, but this requires automating the table update process whenever the base dataset in the cloud storage bucket changes. This is where cloud functions become essential.</p><p>By using a cloud function, you can automatically update your BigQuery native table with new data from a CSV file stored in Cloud Storage, without the need for manual queries or table updates. You might wonder why you should bother with setting up a cloud function when an external table would suffice. While external tables are suitable for certain needs, native tables provide more functionality, particularly in terms of query optimization, speed, and cost.</p><p>Here is how you can create a cloud function that updates your big query table whenever a change is made to the base dataset in your cloud storage bucket.</p><ul><li>Follow the Steps in the previous section, and create a table, instead of selecting an external table, select a native table.</li><li>Open the Cloud Functions console.</li><li>Click “Create Function” to create a new function.</li><li>Select the 1st gen environment</li><li>Choose a unique name for your function, and select your preferred runtime, memory, and trigger options.</li><li>In the “Trigger” section, select “Cloud Storage” as the trigger type, and choose the bucket and event type that you want to trigger the function. For this project, you can choose <em>On (finalizing/creating) file in the selected bucket. </em>Click save, and then next.</li><li>In the “Source code” section, write the code for your Cloud Function. Choose a python runtime, and paste the code below into the main.py file.</li></ul><pre># Import the required libraries<br>from io import BytesIO<br>from google.cloud import bigquery<br>from google.cloud import storage<br>import pandas as pd<br><br># Create the Cloud Function<br>def update_external_table(data, context):<br>    # Get the file name and bucket from the event<br>    file_name = data[&#39;name&#39;]<br>    bucket_name = data[&#39;bucket&#39;]<br>    <br>    # Create a BigQuery client<br>    bq_client = bigquery.Client()<br>    <br>    # Create a Storage client<br>    storage_client = storage.Client()<br>    <br>    # Read the CSV file from Cloud Storage<br>    bucket = storage_client.bucket(bucket_name)<br>    blob = bucket.blob(file_name)<br>    file_contents = blob.download_as_string()<br>    <br>    # Read the CSV file into a Pandas Dataframe<br>    df = pd.read_csv(BytesIO(file_contents))<br>    print(len(df))<br>    <br>    #change the necessary details below<br>    df.to_gbq(<br>    destination_table=&quot;dataset_name.table_name&quot;,<br>    project_id=&quot;project_id&quot;,<br>    chunksize=500_000,<br>    if_exists=&quot;append&quot;,<br>    )<br>  <br>    </pre><ul><li>Copy the following into the requirements.txt file</li></ul><pre>google-cloud-bigquery<br>google-cloud-storage<br>pandas<br>pandas-gbq</pre><ul><li>Copy and paste the name of the function update_external_table as the entry point.</li><li>Deploy the function, and then load data into the cloud storage bucket.</li></ul><p>With this, you are all set to go, and anytime the CSV file in the cloud storage bucket is updated, the cloud function will be triggered and your big query table will be updated.</p><h3>Extracting Data into Big Query Using Federated Queries</h3><p>Federated queries allow you to retrieve data from Cloud Spanner or Cloud SQL databases by sending a query statement and receiving the result as a temporary table. This is achieved using the BigQuery Connection API, which establishes a connection between BigQuery and Spanner or Cloud SQL. To send a query statement to the external database using its SQL dialect, you need to use the EXTERNAL_QUERY function in your query.</p><p>For this project, we will establish a connection between a Postgres Managed Database and BigQuery. It is crucial to ensure that both the BigQuery dataset and the Postgres database are in the same region. Therefore, when creating the managed Postgres database using Google Cloud SQL, be sure to create it in the us-east1 region.</p><p>Here is how to get started:</p><ul><li>Create your Postgres-managed database using CloudSQL and set up your public connections to receive requests from your BigQuery API, there are numerous ways this can be done, but for this tutorial, we will keep it simple and allow our database instance to receive requests from the public.</li><li>Ensure you enable BigQuery Connection API.</li><li>Navigate to BigQuery, click “Add Data” and select “External Data Source”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/0*ooFO2d8qhe_jDi34.png" /></figure><ul><li>Enter the right information within the appropriate fields. You can copy <strong>Cloud SQL Instance ID</strong> from the SQL instance page. Look for the <strong>Connection name.</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gcPHhMGcPPrR2DB_TRzag.png" /></figure><ul><li>Once you create the instance, it appears under external connections within the pinned projects.</li></ul><p>You need to check if the service account that is automatically created when a connection to Cloud SQL is created has the Cloud SQL Client (roles/cloudsql.client) role. In my case, I had to create the role manually.</p><ul><li>Click on the external connection that was created and check the connection details, you should see the service account id. Copy the id</li><li>Navigate over to IAM &amp; Admin, Click the <strong>Grant Access</strong> option</li><li>In the <strong>New principals</strong> field, enter the service account name <strong>BigQuery Connection Service Agent</strong> or the service account ID you copied.</li><li>In the <strong>Select a role</strong> field, select <strong>Cloud SQL</strong>, and then select <strong>Cloud SQL Client</strong>.</li></ul><p>With this, you can now run federated queries</p><pre>SELECT count(*) <br>FROM EXTERNAL_QUERY(&quot;projectid.us-east1.test-db&quot;, &quot;SELECT * FROM tablename;&quot;);</pre><h3>Summary</h3><p>In this project, we covered how to get started with DBT Cloud — We talked about the benefits of using DBT Cloud and the necessary steps to create a connection to your data warehouse or data platform, set up a connection to your GitHub repository, and start developing your models.</p><p>We covered two ways of loading data into BigQuery: External Tables and Native Tables. We discussed the advantages of using an external table and how to create one from a CSV file stored in a Google Cloud Storage Bucket. We also talked about the benefits of using a native table and how to update it automatically using Cloud Functions.</p><p>We also introduced federated queries, which allow you to send a query statement to Cloud Spanner or Cloud SQL databases and get the result back as a temporary table. We discussed how to set up a connection between a Postgres Managed Database and Big Query using the BigQuery Connection API and the EXTERNAL_QUERY function.</p><p>Depending on your need, you can easily build a serverless data pipeline with a simple architecture design on Google Cloud.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e781607655d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring your Local Dev Environment for Google Cloud Resources]]></title>
            <link>https://medium.com/@nwosupaul141/configuring-your-local-dev-environment-for-google-cloud-resources-7f2f71adcc21?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f2f71adcc21</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 10 Mar 2023 10:08:27 GMT</pubDate>
            <atom:updated>2023-03-10T10:08:27.390Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLkD02671SMLMmr9rDG87g.png" /></figure><p><em>There are various ways to authenticate your local development environment with your Google Cloud Resources. In this article, we will discuss a couple of them and how you can get started.</em></p><h3><strong>Introduction</strong></h3><p>When it comes to building data pipelines, authentication is critical not only for security reasons but also to ensure a smooth flow of data between different points. But that’s not all — you also need to consider how easily you can set up or replicate the authentication for all environments where your pipeline will run.</p><p>Fortunately, Google Cloud offers several methods to authenticate your environment, and in this article, I’ll discuss some of the most popular ones and show you how to get started. By the end, you’ll have a better understanding of the importance of authentication in data pipeline development, and you’ll be equipped with the knowledge you need to choose the right authentication method for your specific needs and requirements.</p><h3>Using Google Cloud SDK</h3><p>The Cloud SDK is a powerful toolset that lets you connect with Google Cloud from your command line. By installing the SDK, you’ll gain access to a range of libraries and utilities that make it easy to interact with your cloud resources. Best of all, you can authenticate your development environment in just a few simple steps using the gcloud auth login command.</p><p>Once you run this command and follow the authentication flow, you’ll be ready to start building and testing your applications on Google Cloud. With the Cloud SDK in your toolkit, you’ll have everything you need to streamline your development workflow and unleash the full potential of the cloud.</p><p>To Install Google Cloud SDK on Linux, use the ff commands:</p><pre>#Download the Linux Version<br>curl -O https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-cli-421.0.0-linux-arm.tar.gz<br><br>#Extract the content of the file you downloaded<br>tar -xf google-cloud-cli-421.0.0-linux-x86.tar.gz<br><br>#Run the Installation script from the root folder<br>./google-cloud-sdk/install.sh<br><br>#Initialize the Google Cloud CLI<br>gcloud init<br><br>#Follw the instructions carefully and authenticate your environment<br>#make sure you select yes when you are asked if you want to add gcloud to your Path<br><br>#Activate gcloud commands<br>source .bashrc</pre><p>Here is the Installation Guide Reference for more details:</p><p><a href="https://cloud.google.com/sdk/docs/install-sdk#linux">Quickstart: Install the Google Cloud CLI | Google Cloud CLI Documentation</a></p><p>If you’re already using Google Cloud, the Cloud SDK is the ideal tool to authenticate your development environment. With the SDK installed, you can easily connect to your cloud resources using your Google user account, giving you instant access to all your resources, including your personal Google Cloud Storage bucket.</p><p>And that’s just the beginning — with the Cloud SDK, you can also create and manage multiple accounts, switch between projects, and even spin up instances, shut them down, and write configuration scripts for any of your resources, all with the power of a single command: gcloud.</p><p>If you’re serious about developing applications on Google Cloud, the Cloud SDK is an essential part of your toolkit.</p><h3>Using <strong>Application Default Credentials (ADC)</strong></h3><p>If you’re developing applications that require programmatic access to Google Cloud APIs, cloud client libraries are the way to go. These libraries provide a seamless developer experience by leveraging the natural conventions and styles of each supported language.</p><p>For instance, if you’re using Python, you can easily interact with your Google Cloud resources using the Google Cloud client libraries. And if you want to use the same credentials locally on your development environment as on Google Cloud, you can take advantage of the application_default_credentials.json keys.</p><p>To use application_default_credentials, you’ll need to have the Google SDK installed on your laptop, as you’ll use gcloud commands to switch between projects. Before you can use ADC, you’ll need to configure your account and project ID using the gcloud initcommand. Once that’s done, you’ll be able to use the following command to authenticate your environment and start developing:</p><pre>gcloud auth application-default login</pre><p>To authenticate your environment and start developing with ADC, simply run the command mentioned above. Depending on your setup, the command will either redirect you to a browser or provide you with a link that you’ll need to open manually.</p><p>Once you’re in your browser, make sure you’re signed in with the account you used to configure your Google Cloud SDK (this account must also have access to the project you want to access). The command will then download a key and store it in a directory for you to use. The application_default_credentials.json file is usually found in /home/user/.config/gcloud path.</p><h3><strong>Using Service Account Keys</strong></h3><p>When it comes to authenticating your Google Cloud resources with other platforms, service account keys are a top choice for many developers. Simply put, a service account is an account used by an application or virtual machine instance to access your Google Cloud resources. By creating a service account and downloading its private key file, you can easily authenticate your application and get started in no time.</p><p>One of the best things about service account keys is that you don’t need to install the Google SDK, especially if you’re developing programmatically. Instead, you can simply install the Google Cloud client libraries that you want to use in your project and you’re good to go</p><p>There are multiple ways you can use a service account key to authenticate, here are some:</p><h4>Method 1: Accessing the Key from the GOOGLE_APPLICATION_CREDENTIALS environment variable</h4><ul><li>Set up a Service Account and download the key from Google Cloud.</li><li>Export the key as an environment variable</li></ul><pre>export GOOGLE_APPLICATION_CREDENTIALS=keypath<br><br>#You can also add this command in the .bashrc file found in the home directory</pre><p>You will have to install the Google Cloud Client Libraries for Python that you need. Take for instance, if you need to use or access your big query and cloud storage resources, you need to install those libraries.</p><p>pip install google-cloud-bigquery google-cloud-storage</p><p>This method is similar to using ADC but in this case, you have already provided the credential that you configured yourself and you don’t need to use any gcloudcommands.</p><p>Here is a reference to the list of Python Client Libraries:</p><p><a href="https://cloud.google.com/python/docs/reference">Python Cloud Client Libraries | Google Cloud</a></p><h4><strong>Method 2 — Using Oauth and reading the key from the script</strong></h4><ul><li>Set up a Service Account and download the key from Google Cloud.</li><li>Install the important libraries you need.</li><li>In your script, use google.oauth2.service_account library</li></ul><pre>from google.oauth2.service_account import Credentials<br><br>creds = Credentials.from_service_account_file(&#39;key.json&#39;)</pre><p>This method allows you to utilize your credential key without setting it as the default credential. Ensure that you don’t expose or push the key to public platforms like GitHub. Just like the previous method, it is also only useful for programmatic access, and you will not have access to use gcloud commands.</p><h4>Method 3— Activate the Service Account as a User</h4><p>For this method, you need to have the Google Cloud SDK installed because you would need to activate the service account as a user account. This method can be a little tricky, but here is how you can get started.</p><pre>#Install the Google Cloud SDK and ensure your gcloud commands are working<br>source .bashrc<br><br>#Activate the service account using the key.json<br>gcloud auth activate-service-account --key-file key.json<br><br>#Initialize your account and select a project, the default project will be the one assocaited with the key while you were creating it<br>gcloud init<br><br>#set your application_default credentials using<br>export GOOGLE_APPLICATION_CREDENTIALS=&quot;&lt;path/to/key.json&quot;<br><br>#you can add the above command to the .bashrc file if you will be using the key frequently</pre><p>This method is useful if you need to give access to someone in your team, and also want to limit the access they have to the resources. You can easily create a key with the required permissions, and give them the key for them to use. They will be able to access some of the resources using the gcloud command and also programmatically using cloud client libraries.</p><h3>Summary</h3><p>We have now seen multiple ways we can authenticate our local development environment. These methods have different use cases and can be applied in various ways. For example, the Cloud SDK allows you to authenticate your development environment with your Google Cloud resources using your Google user account. With access to all your resources and the ability to spin up instances, shut them down, and write configuration bash scripts with just one command, the Cloud SDK is definitely the most advised method for long-term development with Google Cloud.</p><p>If you’re developing programmatically, Cloud Client Libraries provide an optimized developer experience by using each supported language’s natural conventions and styles. And with service account keys you can easily start developing without having to install the Google SDK. Service accounts also allow you to authenticate your Google Cloud resources with other platforms.</p><p>So whether you’re a developer, a data engineer, or just interested in Google Cloud, check out these authentication methods to streamline your workflow and ensure secure, efficient access to your resources!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f2f71adcc21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Serverless Deployment of a Prefect Data Pipeline on Google Cloud Run]]></title>
            <link>https://medium.com/@nwosupaul141/serverless-deployment-of-a-prefect-data-pipeline-on-google-cloud-run-8c48765f2480?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c48765f2480</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 03 Mar 2023 09:13:44 GMT</pubDate>
            <atom:updated>2023-03-03T09:13:44.657Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y7yYIa2G09Mqq78LBlNnAg.png" /></figure><p>Data engineering is one of the most rewarding fields because it lets you automate, orchestrate, and deploy data pipelines across various computing environments. In the 6th installment of my Google Cloud Series for Data Professionals, I demonstrate how to orchestrate a data pipeline using Prefect and deploy it on one of Google’s serverless technologies, Cloud Run.</p><p>Before proceeding with the article, check out the previous articles below to get an understanding of how Prefect and Google Cloud work independently.</p><ul><li><a href="https://medium.com/@nwosupaul141/deployment-of-containerized-data-applications-on-google-cloud-run-pt1-80750dce02f8">Deployment of Containerized Data Applications on Google Cloud Run (pt1)</a></li><li><a href="https://medium.com/@nwosupaul141/orchestrating-data-pipelines-with-prefect-on-gcp-infrastructure-cdc7aaf42250">Orchestrating Data Pipelines with Prefect on GCP Infrastructure</a></li></ul><h3>Project Structure</h3><ul><li>Background</li><li>Setting up the Environment</li><li>Building the Prefect Blocks</li><li>Building and Pushing the Docker Image to Artifact Registry</li><li>Deployment on Prefect Cloud</li><li>Setting up the Prefect Agent and Testing</li><li>Conclusion</li></ul><h4>GitHub Repo:</h4><p><a href="https://github.com/paulonye/Cloudrunjobs">GitHub - paulonye/Cloudrunjobs: This repo contains the code used to generate docker images for my Google Cloud Run Jobs.</a></p><h3>Background</h3><p>In our previous project, we built and orchestrated a data pipeline that scraped data from the web and loaded it into a Postgres database on the Google Platform using Prefect. In this new project, we’ll be tweaking that pipeline to scrape data from the web and save it as CSV files in a Google Cloud Storage bucket. Then, we’ll create external tables using Bigquery.</p><p>The two main tools we’ll be using in this project are Prefect and Google Cloud Run. We’ve covered how to use these tools in the articles referenced above. Additionally, it’s crucial to read this <a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">article</a> to properly configure the computing environment for this project.</p><h3>Setting up the Environment</h3><h4>Clone the repo</h4><pre>$ git clone https://github.com/paulonye/Cloudrunjobs.git</pre><p>To get started, navigate to the prefectXcloudrun folder. I recommend using a virtual environment. You can create one using python -m venv envand activate it with source env/bin/activate. Then, install the required libraries from the requirements.txtfile.</p><p>Be sure to check the file, as you’ll notice that “prefect-gcp[cloud storage]” needs to be installed. This module is crucial because it allows Prefect to connect to your Google Cloud Storage bucket.</p><h4><strong>Create a Service Account</strong></h4><p>Google Service Accounts are a way for applications to authenticate to the Google Cloud Platform (GCP) APIs and services, using a set of predefined credentials. These credentials are managed by an associated project and can be used for a variety of purposes, such as granting permissions to specific resources and services, or for application-to-application communication within a GCP project. We are going to be using a service account to allow Prefect to interact with your cloud storage bucket.</p><p>To create a service account, click the <strong>Navigation menu &gt; IAM &amp; Admin &gt; Service Accounts. </strong>Click on create a service account. Select a name for the service account, grant the service account an editor role (From Basic), click on continue, and DONE.</p><p>Now that the service account has been created, click on the triple dots at the end of the row, and then select Manage keys. Select ADD KEY &gt;Create a new key, select JSON, and then create. Once this key has been created, it automatically downloads to your local machine. Keep the key in a safe place as we will be using it later.</p><h4>Building the Script</h4><p>The data pipeline we’ll be using is called pipeline.py. Take a moment to open the code and read through it; it’s well-documented. The goal of the pipeline is to perform the following tasks on a daily basis:</p><ol><li>Scrape data from Yahoo Finance.</li><li>Save the data as a CSV file in a local directory, with the current date added as a suffix to the filename.</li><li>Create and load the CSV file into a Google Cloud Storage bucket.</li></ol><p>Note that you won’t be able to test the script unless you have all the dependencies and requirements installed on your remote machine.</p><h4><strong>Authentication with Prefect Cloud</strong></h4><p>The final step in setting up your environment is to log into your Prefect Cloud account right from the command line. In the last article, I demonstrated how to do this using the following command:</p><pre>$ prefect cloud login -k API-key</pre><h3>Building the Prefect Blocks</h3><p>In simple terms, Prefect blocks are like modules or functions that let you use third-party applications in your Prefect pipeline. For example, in this project, we’ll be using three blocks:</p><ol><li>GCP Credential Block</li><li>GCP Cloud Storage Block</li><li>GCP Cloud Run Job</li></ol><p>These blocks enable you to interact with your Google Cloud environment with little to no additional configuration. This is just a basic introduction to Prefect blocks; there are many other capabilities as well.</p><h4>Creating the GCP Credential Block</h4><ul><li>Navigate to your Prefect Cloud Workspace.</li><li>Click on the Name of your Workspace.</li><li>Navigate to the Blocks Tab, and click on the + icon to create a new block</li><li>Look for the GCP Credential Block and click on it to create the Block.</li><li>Open the service account JSON key, copy the details, and paste it into the Service Account Info block.</li><li>Add a block name and the name of the GCP project.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xoeFuZZSw1x1X2dOvHRPfQ.png" /></figure><p>It is important that you create the credentials block first because you will use it in other blocks that you will use.</p><h4>Creating the GCP Cloud Storage Block</h4><ul><li>From the Blocks Tab, click on the + icon to create a new block</li><li>Look for the GCS Bucket block and fill out the necessary details such as Block Name, Bucket Name, and add the GCP Credentials that you created earlier.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j7F7H7LFZZ0LRfOpr2OyTw.png" /></figure><h4>Creating the GCP Cloud Run Job Block</h4><ul><li>From the Blocks Tab, click on the + icon to create a new block</li><li>Look for the GCP Cloud Run Job and fill out the necessary details such as block name, CPU (select 2), name, type, image name (the artifact registry path where you pushed the docker image), memory (select 4), region (the region where the docker image resides), keep job after completion (false), Gcpcredentials (the name of the credentials you created), Memory units (Gi).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LCtnXu0rcR1KIPaYqDvujw.png" /></figure><h4>Note</h4><p>The pipeline.pyfile references both the GCP Credential and Cloud Storage blocks since they are part of the tasks for the flow.</p><p>In contrast, the GCP Cloud Run Job block is used to set up the infrastructure that will be used to deploy the pipeline. We’ll discuss this in more detail later.</p><h3>Building and Pushing the Docker Image to Artifact Registry</h3><p>When creating a serverless deployment, it’s important to store your code and all of its dependencies in a remote repository for easy accessibility. Google Artifact Registry is Google’s in-house solution for this. Artifact Registry allows you to securely store Docker containers and deploy them on any of Google’s computing solutions. I covered how to get started with Artifact Registry in this <a href="https://medium.com/@nwosupaul141/deployment-of-containerized-data-applications-on-google-cloud-run-pt1-80750dce02f8">post</a>.</p><p>To get started, navigate to the cloned repo and open the Dockerfile. Make any necessary changes to the file. Then, create the Artifact Registry, build the Docker image, and push it to the Artifact Registry.</p><h4>Note</h4><p>For this project, we chose to build the data pipeline’s code into a Docker container. However, another alternative would be to host the code and its dependencies in an S3 or Cloud Storage bucket.</p><h3>Deployment on Prefect Cloud</h3><p>Great! It seems like you have followed all the necessary steps to set up your environment and prepare your data pipeline for deployment. The next step is to deploy a prefect agent that will keep on polling the Prefect API for flow runs on a computing instance. This can be a TMUX instance on the remote machine you are working on. You can also use a micro instance or a spot instance, as the machine does not have to be powerful. Just make sure that the prefect agent is authenticated with your workspace where you deployed the flow and runs continuously on a computing environment.</p><p>Once you have the prefect agent running in the background and ready to pick up your work queues, you can test-run the pipeline. Prefect orchestrates the entire process by creating the cloud-run job based on the parameters you defined and then destroys all resources created when the job is completed. This not only helps save costs but also takes away the stress of having to create and destroy these resources by ourselves.</p><p>To create a deployment; use the command below:</p><pre>$ prefect deployment build pipeline.py:main -n test-dev -ib cloud-run-job/dev -q dev -o dev.yaml</pre><p>The above command creates a yml file named dev.yaml , open this file, and add the URL variable in your code as a parameter. Save the file and then use the command below to push the deployment to prefect cloud.</p><pre>$ prefect deployment apply dev.yaml</pre><p>Check your prefect workspace for the deployment. Once the deployment has been seen, deploy your prefect agent on your compute environment to pick up work queues from dev which is the name of the work queue we defined for our deployment to send its flows.</p><pre>$ prefect agent start -q dev</pre><p>The Prefect agent will pick up the flow run and orchestrate the entire process. This includes creating the necessary infrastructure on Google Cloud Run, submitting the flow to the cloud-run job, monitoring the run, and cleaning up resources once the job is completed.</p><p>You can monitor the logs in the Prefect Cloud UI to see the progress of the flow run and any errors that might occur. Once the flow run is completed, you should see the results in your Google Cloud Storage bucket as a CSV file.</p><h3>Conclusion</h3><p>The beauty of serverless deployments is that you can run your flow from any computing environment that has a prefect agent that picks your work queues and is authenticated with your prefect cloud workspace. You can use GitHub codespaces to test this, just configure and log into your prefect cloud workspace, start the prefect agent, and then run your workflow.</p><p>It is nice to see how the powerful combination of Prefect and Google Cloud Run can be used to orchestrate your data pipeline and set up the computing infrastructure. The use of Prefect blocks made it easy to interact with the Google Cloud environment without additional configuration, while Google Artifact Registry provided a secure way to store and deploy the Docker container.</p><p>Overall, this project has demonstrated how to build a robust and scalable data pipeline using modern technologies and best practices.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c48765f2480" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Orchestrating Data Pipelines with Prefect on GCP Infrastructure]]></title>
            <link>https://medium.com/@nwosupaul141/orchestrating-data-pipelines-with-prefect-on-gcp-infrastructure-cdc7aaf42250?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/cdc7aaf42250</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 08:38:42 GMT</pubDate>
            <atom:updated>2023-02-17T08:38:42.357Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JtiiY15-QTXUoU4xxhu_rg.png" /></figure><p>So far, we have explored a variety of tools and methods for building data pipelines, allowing us to learn the fundamental principles of this important process. For the fifth installment of my “Building Data Applications on Google Cloud” series, I delved into the world of Prefect — a data orchestration tool that is rapidly gaining popularity in the industry.</p><p>In this project, we will be using Prefect to orchestrate the data pipeline that we built in our previous project, we will then build the pipeline into a Docker image and deploy it on Google’s Compute Engine infrastructure.</p><h3>Project Structure</h3><ul><li>Introduction to Orchestration</li><li>Introduction to Prefect</li><li>Setting up your Prefect Cloud Environment</li><li>Writing your First Flow</li><li>Deploying the Flow on Google Cloud Environment</li><li>Summary</li></ul><h4>Previous Articles</h4><ul><li><a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">Optimizing Google’s Cloud Infrastructure for Data Engineering and Analytics</a></li><li><a href="https://medium.com/@nwosupaul141/building-an-etl-pipeline-using-google-service-accounts-85e2a6cfd94d">Building an ETL Pipeline Using Google Service Accounts</a></li><li><a href="https://medium.com/@nwosupaul141/deployment-of-containerized-data-applications-on-google-cloud-run-pt1-80750dce02f8">Deployment of Containerized Data Applications on Google Cloud Run (pt1)</a></li><li><a href="https://medium.com/@nwosupaul141/batching-web-data-into-a-postgres-database-hosted-on-google-cloud-15af1674cdb3">Batching Web Data into a Postgres Database Hosted on Google Cloud</a></li></ul><h3>Introduction to Orchestration</h3><p>In the context of data pipelines, orchestration refers to the process of managing and coordinating the various tasks and dependencies required to move data from source to destination. Orchestration involves designing, scheduling, and executing a series of automated data processing steps to ensure that the data is transformed, enriched, and delivered to the desired destination in a timely and reliable manner. Data orchestration involves integrating different technologies, platforms, and tools into a cohesive workflow to streamline data processing, increase efficiency, and reduce errors.</p><p>Here are some tools commonly used for data orchestration and a brief description of each:</p><ol><li>Apache Airflow: A popular open-source platform for creating, scheduling, and monitoring complex workflows. Airflow is highly customizable and integrates with a wide range of data processing and storage technologies.</li><li>Apache NiFi: An easy-to-use, open-source platform for building data pipelines. NiFi features a visual interface for designing and monitoring data flows, as well as support for data enrichment, filtering, and routing.</li><li>Apache Beam: An open-source platform for building batch and streaming data processing pipelines. Beam provides a unified programming model for processing data in different languages and on different execution engines, including Apache Spark, Google Cloud Dataflow, and Apache Flink.</li><li>AWS Step Functions: A fully managed service for building serverless workflows. Step Functions lets you design, test, and deploy workflows that integrate with a wide range of AWS services, including AWS Lambda, AWS Batch, and Amazon SageMaker.</li><li>Azkaban: An open-source workflow manager for Hadoop. Azkaban provides a web-based interface for creating and managing workflows, as well as support for scheduling and parallel execution.</li><li>Luigi: An open-source Python framework for building data pipelines. Luigi provides a simple interface for defining dependencies between tasks, as well as support for scheduling and error handling.</li></ol><h3>Introduction to Prefect</h3><p>Prefect is another tool for data orchestration that has gained popularity in recent years. It is an open-source workflow automation system that enables users to build, schedule, and monitor complex data pipelines. Prefect is designed to be flexible and easy to use, with a focus on developer productivity.</p><p>One of the key features of Prefect is its ability to define workflows as code, using a simple and intuitive Python-based API. This makes it easy to version control, test workflows, and enables developers to quickly iterate and make changes. Prefect also provides a web-based dashboard for monitoring and managing workflows, with detailed logging and visualization capabilities.</p><p>Prefect supports a wide range of data processing and storage technologies, including databases, messaging systems, cloud storage, and more. It also has built-in support for distributed computing, allowing workflows to be executed across multiple machines or cloud instances.</p><p>In addition to the open-source version, Prefect offers a commercial platform with additional features such as advanced monitoring, collaboration tools, and enterprise-level support. Overall, Prefect is a powerful and flexible tool for data orchestration, suitable for organizations of all sizes and industries.</p><p>You can read more on Prefect here: <a href="https://docs.prefect.io/">https://docs.prefect.io/</a></p><h3>Setting up your Prefect Cloud Environment</h3><p>Before we can begin using Prefect, it’s important to first understand what Prefect Cloud is. Prefect Cloud is a platform that provides an easy, powerful, and scalable way to automate and monitor managed workflows built with Prefect, without the need to worry about moving your data. Essentially, it’s an Orchestration as a Service tool that enables you to deploy your pipelines and monitor their progress in real-time.</p><p>To prepare your environment for Prefect workloads, follow these steps:</p><p><strong>Create a Workspace</strong></p><p>Log into <a href="https://app.prefect.cloud/">https://app.prefect.cloud/</a> preferably with your Google Account. A workspace is an isolated environment within Prefect Cloud for your flows and deployments. You can use workspaces to organize or compartmentalize your workflows.</p><p><a href="https://docs.prefect.io/ui/cloud-quickstart/">Prefect Cloud Quickstart - Prefect 2 - Coordinating the world&#39;s dataflows</a></p><p>The above link will help you get started in no time.</p><h4><strong>Installing Prefect</strong></h4><p>To get started with Prefect, you can follow the installation instructions provided in the link above. It’s worth noting that this is part of my Google Cloud Series, and we’ll be working with a virtual machine hosted on Google Cloud.</p><p>For the purpose of this tutorial, I’ll be installing Prefect within a virtual environment on my remote machine, as the tool can be easily installed using pip.</p><p>To begin, simply git clone the project repository using the following command:</p><pre>$ git clone https://github.com/paulonye/prefect_gcp.git</pre><p>Navigate into the directory of the folder and create a virtual environment using python -m venv env. This will create a env/ folder.</p><p>To activate the virtual environment, use:</p><pre>$ source env/bin/activate</pre><p>To confirm that the virtual environment is working, you should see the name of the virtual environment you set in front of your terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*4A5rZeo9liwbpes-0XrDsw.png" /></figure><p>Install the libraries and modules (including Prefect and all of its dependencies) in the virtual environment using:</p><pre>$ pip install -r requirements.txt</pre><p>To confirm that Prefect has been installed in the virtual environment, run the command prefect --version .</p><h4>Log into Prefect Cloud from the Terminal</h4><p>Use the prefect cloud login Prefect CLI command to log into Prefect Cloud from your environment.</p><pre>$ prefect cloud login</pre><p>The prefect cloud login command, used on its own, provides an interactive login experience. Using this command, you may log in with either an API key or through a browser. Select the API key.</p><p>To set an API key:</p><ul><li>Log into your Prefect cloud account</li><li>Click on the icon found in the lower left corner, and select the settings symbol.</li><li>Click on the API Key tab and follow the instructions to create a key.</li></ul><p>Once you have gotten the API key, go back to your terminal and paste the key. Prefect automatically saves this key in the .prefect folder located in the home directory so that you can log into your Prefect workspace anytime.</p><h3>Writing your First Flow</h3><p>A flow is the most basic Prefect object that is a container for workflow logic and allows you to interact and understand the state of the workflow. Flows are like functions, they take inputs, perform work, and return an output. We can start by using the @flow decorator to a main_flow function.</p><pre>from prefect import flow, task</pre><p>Flows contain tasks, which can be added by adding the @task decorator. Tasks are not required for flows but tasks are special because they receive metadata about upstream dependencies and the state of those dependencies before the function is run, which gives you the opportunity to have a task wait on the completion of another task before executing.</p><pre>@flow(name=&#39;Flow-Postgres-ETL&#39;)<br>def main(url: str, tablename: str):<br><br>    url = url<br><br>    tablename = tablename<br><br>    data = capture_data(url)<br><br>    df = trans_df(data)<br><br>    batch(df, tablename)</pre><p>The code snippet above is taken from the pipeline.py file in the Git repository. The name of the flow in this file is “Flow-Postgres-ETL”, with the main function serving as its host.</p><p>In this file, there are three tasks defined as separate functions. By dividing the workflow into multiple functions, we can gain greater visibility into the tasks that are running and identify any that may be causing failures. This approach helps to simplify troubleshooting and debugging during the pipeline’s execution.</p><ul><li>Extract the Data from Yahoo Finance Website (task 1)</li><li>Transform the Data by cleaning up certain columns (task 2)</li><li>Load the Data into a Postgres Database (task 3)</li></ul><h4>Getting Started with Prefect Blocks</h4><p>The third task in our pipeline involves loading data into a Postgres database, which requires the integration of a Prefect Block.</p><p>Blocks are a fundamental component of Prefect, they enable the storage of configurations and provide an interface for interacting with external systems. There are several types of blocks available, and users can even create their own. Block names are immutable, which allows them to be reused across multiple flows. Additionally, blocks can be built upon or installed as part of integration collections, which are pre-built tasks and blocks that can be installed via pip.</p><p>For our project, we’ll be using the SqlAlchemy block to set our database configuration. This block allows us to set up the configuration for our database without having to input the details directly into our code or as environment variables, as we did in our previous tasks.</p><p>To create a SqlAlchemy block, you need to do the following:</p><ul><li>Navigate to your Prefect Cloud Workspace</li><li>Click on the Name of your Workspace</li><li>Navigate to the Blocks Tab, and click on the + icon to create a new block</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DBgRyk7T7Xgq7VfwjB5NYQ.png" /></figure><ul><li>Prefect provides a list of blocks available for use, scroll down to find the SqlAlchemy block.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FuZk6gg_p3tTwVTbrTlYmA.png" /></figure><ul><li>Click on Add +, and input the necessary details such as the external IP address of the database, port, username, password, and database name. Other details include setting a postgres+psycopg2 sync driver. The name of the block should be postgres-connector as it will be referenced in the pipeline.py .</li></ul><p>The final configuration should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ab2Y8e3VtNDEb5ykAuRZ-w.png" /></figure><p><strong>Note:</strong> You should not expose your Postgres credentials to anyone to prevent unwanted access to your database.</p><p>You can also create a block from a python file using code. Prefect provides you with a lot of documentation that you can use to facilitate your data pipeline and integrate it with other tools.</p><p>In case you don’t find the SqlAlchemy block on the blocks page, you can create it from the terminal by running:</p><pre>prefect block register -m prefect_sqlalchemy</pre><p>Check out this <a href="https://orion-docs.prefect.io/collections/catalog/">link</a> to understand how to utilize more Prefect blocks.</p><p>Go through the pipeline.py script in detail to understand how the code works. It’s pretty straightforward to read and understand.</p><p>Test that the code works by running python pipeline.py script on the terminal.</p><h3>Deploying the Flow on Google Cloud Environment</h3><p>In Prefect, a deployment is a server-side concept that encapsulates a flow, enabling it to be scheduled and triggered via API. The deployment stores metadata about the location of your flow’s code and how it should be executed.</p><p>There are several methods to create a deployment. You can build the deployment on the command line or deploy using a Python file. For our project, we’ll be using the latter approach.</p><p>You should be able to find a deployment.py file in the Git repository. This file contains the code we’ll use to create a deployment. Here’s a snippet:</p><pre>from prefect.deployments import Deployment<br>from pipeline import main<br>from prefect.infrastructure.docker import DockerContainer<br><br>docker_block = DockerContainer.load(&quot;zoom&quot;)<br><br>docker_dep = Deployment.build_from_flow(<br>    flow=main,<br>    name=&quot;docker-flow&quot;,<br>    infrastructure=docker_block,<br>)<br><br>if __name__ == &quot;__main__&quot;:<br>    docker_dep.apply()</pre><p>Before running the deployment file, we need to configure how we want our deployment to look.</p><h4>Setting up the Infrastructure</h4><p>Prefect uses infrastructure to create the environment for a user’s flow to execute. Infrastructure can only be used with a Deployment.</p><p>There are various tools we can use as our Prefect infrastructure, for this project, we are going to be using a docker container to host our code and its dependencies.</p><p>A) Build the docker image using the Dockerfile :</p><pre>docker build -t prefectdocker:tag1 .</pre><p>B) Create a block for your docker container: Go to your Prefect cloud workflow user interface and navigate to the blocks tab to create a block for your docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uzw0pgMC4tgpLpR9otwCiA.png" /></figure><p>C) Set the configuration details for the docker-container block; set the block name to ‘zoom’, and then add the name of the docker image you built in the image row. Leave all other settings as default and create the block.</p><p>Your Final block should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Szhyw8wEUrX3NlYTcCsf8A.png" /></figure><h4>Build the Deployment</h4><p>You can review the deployment.py file to gain a better understanding of how the Docker block is used. Once you&#39;re ready to deploy, simply run the command python deployment.py in your terminal.</p><p>To check your deployment, navigate to the “Deployments” tab in your Prefect workspace. If you haven’t made any changes to the deployment.py file, you should see a deployment named &quot;Flow-postgres-ETL:docker-flow&quot;. Click on the &quot;docker-flow&quot; portion to access the details.</p><p>To configure the deployment, click the three dots at the top-right corner of the UI and select “Edit”. Scroll down to the “Parameters” section and enter the default URL and table name found in the pipeline.py file. Note that this parameter can be updated at any time. Finally, save your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HYA-neeu9L8otTagcseQOA.png" /></figure><p>To start the deployment, you will need to configure a Prefect agent and it will automatically pick up the scheduled deployment. You should see the deployment status change from &quot;Scheduled&quot; to &quot;Running&quot; in the Flow runs tab.</p><h4>Running the Deployment</h4><p>When it comes to running a deployment, it’s quite different from running a flow from a Python script. In order to run a deployment, you’ll need to launch a Prefect agent on your environment. This agent will then pick work queues from your Prefect workspace and execute the flow in your terminal.</p><p>In other to run our deployment conveniently, we could create a TMUX session. TMUX is a terminal multiplexer that allows you to manage multiple terminal sessions within a single window or SSH session. With TMUX, you can also detach from a session and reattach later, which makes it possible to start a long-running process in a TMUX window, detach from the session, and later reattach to the same session to check on the progress of the process.</p><p>Once you’ve created a TMUX session, you can deploy your Prefect agent on the terminal. Follow the commands below to get started with TMUX.</p><pre>tmux<br>#this opens a new terminal window<br><br>source emv/bin/activate<br>#activate the virtual environment where you installed prefect<br><br>prefect agent start -q &quot;default&quot;<br>#deploy the prefect agent to pickup workqueues using the default tag<br><br>ctrl+D, B<br>#detach from the tmux window<br><br>tmux ls<br>#list the tmux sessions currently running<br><br>tmux attach -t 0<br>#reattach to the tmux session<br><br>tmux kill-session -t 0<br>#kill the session<br></pre><p>Once you have configured your agent in your running environment, go back to your Prefect workspace to monitor the workflow.</p><p><strong>Note: </strong>Tmux usually comes preinstalled with your remote instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qpcHlIma9GTBI_vb4Ueskw.png" /></figure><p>For more information on deployments, ensure to check out the Prefect docs <a href="https://docs.prefect.io/concepts/deployments/">here</a>.</p><p><strong>Note</strong>: <em>Authentication is a crucial aspect of your workflows for both Prefect Cloud and Google Cloud Environments, and it is essential to ensure that your environments are authenticated properly.</em></p><p><em>For Prefect, you will need to configure agents and work pools that can create flow runs for deployments in remote environments. To achieve this, you must ensure that the PREFECT_API_URL is correctly set for the environment in which your agent is running. If you want the agent to communicate with Prefect Cloud from a remote execution environment such as a VM or Docker container, it is crucial to configure the PREFECT_API_URL in that environment. Use the </em><em>prefect config view command to view your credentials.</em></p><p><em>For your Google Cloud environment, you need to make sure that you can access your cloud resources from your terminal. You can confirm that you are in the correct project by using the </em><em>gcloud config listcommand. You might also need to authenticate to allow access from third party applications like python using the </em><em>gcloud auth application-default login .</em></p><h4>Scheduling the Deployment</h4><p>Go to your Prefect workspace and navigate to the Deployment tab to check your deployment. Click on the “docker-flow” portion and locate the three dots at the upper right corner of the UI, then select “Edit”.</p><p>Scroll down to the “Schedule” section, click on “Add”, select the “Cron” tab, and set your cron job according to your desired schedule. After setting your cron job, remember to save your changes.</p><h3>Summary</h3><p>In this project, we set up an ETL pipeline using Prefect, a workflow management system. We created a Prefect project, defined a flow in a Python file, and deployed it to a Docker container in a remote environment. We then authenticated our environment to ensure secure access to both our Prefect Cloud and Google Cloud resources. Finally, we scheduled our deployment to run at specific intervals using a cron job in the Prefect UI. This project provides a good starting point for building more complex data pipelines using Prefect.</p><p>In conclusion, building automated ETL pipelines is essential for efficient and effective data analysis. Prefect and Docker provide powerful tools to simplify the creation of such pipelines. With Prefect, you can create, schedule, and monitor your workflows with ease, while Docker enables you to package your code and its dependencies into standardized units for easy deployment. By combining Prefect and Docker, you can build robust, reliable, and scalable ETL pipelines that can handle a wide range of data sources and transformations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cdc7aaf42250" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Batching Web Data into a Postgres Database Hosted on Google Cloud]]></title>
            <link>https://medium.com/@nwosupaul141/batching-web-data-into-a-postgres-database-hosted-on-google-cloud-15af1674cdb3?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/15af1674cdb3</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 10 Feb 2023 10:30:34 GMT</pubDate>
            <atom:updated>2023-02-10T10:30:34.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QOATcma1AhLxFnEiMtkB0w.png" /></figure><p>It’s important to read the <a href="https://medium.com/@nwosupaul141/configuration-of-a-postgres-database-on-google-cloud-763f2f8dee6e">previous article</a> before diving into this one as it serves as a direct sequel. In the previous article, I explained how to set up and configure a Postgres database by using a locally hosted Docker image and a managed database service provided by Google Cloud SQL. In this article, I’ll guide you through the process of setting up a pipeline that batches data into the Postgres database.</p><h3>Project Structure</h3><ul><li>Introduction</li><li>Setting up the Environment</li><li>Setting up PGADMIN</li><li>Building the Docker Image</li><li>Deploying the Container on Cloud Run</li><li>Conclusion</li></ul><h4>Previous Article:</h4><ul><li><a href="https://medium.com/@nwosupaul141/configuration-of-a-postgres-database-on-google-cloud-763f2f8dee6e">Configuration of a Postgres Database on Google Cloud</a></li><li><a href="https://medium.com/@nwosupaul141/deployment-of-containerized-data-applications-on-google-cloud-run-pt1-80750dce02f8">Deployment of Containerized Data Applications on Google Cloud Run (pt1)</a></li></ul><h4>GitHub Repo:</h4><p><a href="https://github.com/paulonye/DockerXPostgres">GitHub - paulonye/DockerXPostgres: In this project, a postgres cloudsql is set up and connected to a docker pgadmin container. Scraped data is written into the database, and accessed via local machine and remote host</a></p><h3>Introduction</h3><p>Batching data into a database is a common task in the industry. The key to success is to have a good understanding of how to communicate with the database and access to appropriate computing and storage options. In the previous article, we created two databases, one locally and the other on Google Cloud SQL. We also confirmed and tested the connections to these databases using pgcli. Now, in this article, we will write data into the Postgres Cloud SQL database that you should have set up previously.</p><p>Before proceeding, it is important that you navigate to Navigation Menu &gt; SQL &gt; Instances. Click on the Instance Id you created. Ensure you get the following details: User, Database, Hostname (Public Ip Address), and Password.</p><p>You can test the connection again using:</p><pre>pgcli -hostname 34.453.456.34 -p 5432 -u user -d database_name</pre><h3>Setting up the Environment</h3><p>Now that the Postgres database has been configured, let’s dive into the Python scripts. We’ll be using four Python scripts in total, two of which will act as modules and the other two as main scripts to perform the necessary tasks. We’ll be conducting two jobs, a migration batch job, and a batch job that writes data into the Postgres database every hour. These two jobs will write data into the same table.</p><p>To get started clone this repo into your local:</p><pre>git clone https://github.com/paulonye/DockerXPostgres.git</pre><p>Navigate into the DockerXPostgres/ directory and install the required libraries using pip install -r requirements . Once this is done, you can then navigate into the app/ directory to view the python files.</p><p>Before proceeding to run the python files, you need to set up a .env file that contains the database credentials and also the service account key to read data out of your Google Sheets.</p><p>You can do this by creating a .env file using touch .env and adding the following to the file.</p><pre>PGUSER=user<br>PGPASS=******<br>HOST=**********<br>DB=database_name<br>key_file=key.json</pre><p>For you to be able to access the environmental variables from the .env file you need to install a python package called dotenvusing:</p><pre>pip install python-dotenv</pre><p>You don’t need to run this again because it was included in the requirements.txt file. You can examine the connect.py script to see how the package is used, and how you can use os.getenv to read your environmental variables from the .env file.</p><p>Then add this to the script that requires the environmental variable:</p><pre>import os<br>from dotenv import load_dotenv<br>load_dotenv()<br><br>#To get the hostname<br>host = os.getenv(&#39;PGUSER&#39;)</pre><h4>Migrating Google Sheets Data into the Postgres Database</h4><p>In the second part of this series, we constructed a data pipeline that scraped data from Yahoo Finance and loaded it into Google Sheets. If you completed that project, you should have accumulated around 5,000 rows of data by now. However, I have about 30,000 rows in my Google Sheets, and I want to transfer that data to a more secure storage location, specifically the Postgres database.</p><p><a href="https://medium.com/@nwosupaul141/building-an-etl-pipeline-using-google-service-accounts-85e2a6cfd94d">Building an ETL Pipeline Using Google Service Accounts</a></p><p>Navigate to the app/ directory in the repository and open the batch.py file to see the code. This script has two functions: (i) Reads the data from the Google Sheets and (ii) Loads the data into the database. The script uses the get_connection function in the connect.py file to connect to the database. Ensure that your .env file has been configured correctly. You will need to add the directory of your service account key and add it to the .env file you will create. I saved the service account key variable name as key_file and this is what I referenced in the batch.py file.</p><p>You can test the connect.py file is working by running it using:</p><pre>python connect.py</pre><p>Once you have confirmed the connection, you can then run the batch.py file. You will only need to run this once to migrate the data into the database.</p><h4>Setting up the Main Pipeline that scrapes Data into the Postgres Database</h4><p>Once the data in the Google Sheets has been batched, you can then proceed to set up the main pipeline script main.py . The script uses functions from connect.py and scrape.py . You can run the script using python main.py to test if the script works. And then confirm using pgcli to see if the number of rows in the table increased.</p><h3>Setting up PGADMIN</h3><p>In the <a href="https://medium.com/@nwosupaul141/configuration-of-a-postgres-database-on-google-cloud-763f2f8dee6e">previous article</a>, I talked about how to set up PGADMIN using a docker image. Pgadmin, unlike pgcli gives you access to a web interface that allows you to communicate with the database.</p><p>To get started with PGADMIN using docker, run the command below on your terminal:</p><pre>docker run -it \<br>    -e PGADMIN_DEFAULT_EMAIL=&quot;admin@admin.com&quot; \<br>    -e PGADMIN_DEFAULT_PASSWORD=&quot;root&quot; \<br>    -e PGADMIN_COOKIE_SECRET=53tegevd66efdvfff\<br>    -p 8080:80 \<br>    -d \<br>    dpage/pgadmin4</pre><p>To confirm that the container is running, try docker ps . The next step would be to launch the web interface of the PGADMIN, for this, you have to port forward using VScode as the bridge between your remote machine and your local machine.</p><p>Open your VScode and connect to the remote instance. Go to the port session and click on Forward a Port. Type in 8080, as this is the port the PGADMIN docker container is currently running on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*od0T72CIYQAbPBMmFB5u0Q.png" /></figure><p>Copy the local address link provided as seen above and paste it into your browser. This will load the PGADMIN login interface; input the email address and password you configured in your docker command. Once the page has loaded, follow the steps below:</p><ul><li>Right-click on ‘Servers’ at the upper left corner and select Register &gt; Server.</li><li>On the General Tab, create a Random Name of your choice.</li><li>On the Connection Tab, fill in the details as seen in the image below, also input the password.</li><li>Click on Save.</li><li>Navigate to Databases &gt; Database you created &gt; Schemas &gt; Tables to view the tables you created.</li><li>Right-click on the table you created and select the Query Tool.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cno-KkSgMTv5a9tzfMAeSw.png" /></figure><p>You can go ahead and play around with the query tool.</p><p><strong>Note</strong>: <em>We are able to connect to the database using its external Ip address only because we had initially created a firewall rule that allows any network to connect to the database. However, this is not the best practice. It’s usually better to specify the IP address that should have access to the database for security reasons.</em></p><h3>Deploying the Container on Cloud Run</h3><p>Now that we have tested the scripts and confirmed that the connection to the database is working, the next step is to deploy the application on Google Cloud Run. You should be familiar with the process, I covered the steps to deploy an application on Google Cloud Run extensively in my <a href="https://medium.com/@nwosupaul141/deployment-of-containerized-data-applications-on-google-cloud-run-pt1-80750dce02f8">third article</a>.</p><p>Here’s a summary of the steps for your reference:</p><ol><li>Build the Docker image — you can find the Dockerfile in the repository.</li><li>Push the Docker image to Google Artifact Registry.</li><li>Deploy the image using a Google Cloud Run job.</li><li>Set up a scheduler using Google Scheduler.</li></ol><h3>Conclusion</h3><p>In conclusion, we have covered the steps to build a data pipeline that batches data into a Postgres database. We started by setting up and configuring a Postgres database using a local docker image and Google CloudSQL. Then, we wrote Python scripts to perform two jobs: a migration batch job and a batch job that writes data into the Postgres database every hour. Finally, we deployed the application on Google Cloud Run and set up a scheduler using Google Scheduler.</p><p>By following these steps, you should now be able to transfer data from your Google Sheets into a secure storage location, the Postgres database, in an automated and efficient manner. This pipeline can serve as a starting point for you to build upon and customize according to your needs. The possibilities are endless, and with the power of cloud computing, you can take your data processing to new heights.</p><p><strong>Next Article::</strong> Using Prefect Cloud to Orchestrate your Data Pipelines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15af1674cdb3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuration of a Postgres Database on Google Cloud]]></title>
            <link>https://medium.com/@nwosupaul141/configuration-of-a-postgres-database-on-google-cloud-763f2f8dee6e?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/763f2f8dee6e</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 10:28:36 GMT</pubDate>
            <atom:updated>2023-02-19T11:39:09.116Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CtqQDOiPpiHMQVEBvQJSbA.png" /></figure><p>In this project, we will set up and connect to a Postgres database by setting it up locally (on the remote instance we <a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">created</a>), and also by using Google Platform as a service solution, Cloudsql. The major aim of this project is to show you the various options you can use to set up a database, and how to access the database both from internal and external networks.</p><p>This is the fourth part in a series I started called “Building your First Google Cloud Analytics Project.”</p><h3>Project Structure</h3><ul><li>Introduction</li><li>Set up of Docker Compose</li><li>Setting up pgcli for Connectivity test</li><li>Local Set Up of Postgres</li><li>Local Set Up for Pgadmin</li><li>Cloud SQL Set Up</li><li>Connecting to the Database — ports, firewall rules</li><li>Best Practices when Configuring a Database</li><li>Summary</li></ul><h3>Introduction</h3><p>PostgreSQL is a popular open-source relational database management system that provides powerful and flexible data storage and management capabilities. Connecting to a PostgreSQL database is a crucial step in accessing and utilizing the data stored in it. This article will provide a comprehensive guide on how to configure and connect to a PostgreSQL database, including the various methods and tools available for establishing a connection and interacting with the database. This part of the project will be more of a practical step on step guide rather than a complete code project.</p><h3>Set up of Docker Compose</h3><p>In the <a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">first article</a> in this series, we talked about how to install docker and set it up for use. Let’s now talk about docker-compose and see how it differs from docker. Docker-compose allows us to launch multiple containers using a single configuration file so that we don’t have to run multiple complex docker run commands separately.</p><p>Docker compose makes use of YAML files. YAML (YAML Ain’t Markup Language) is a human-readable data serialization format used for storing and exchanging data. It is often used for configuration files and data exchange between different systems and applications. YAML files use indentation to denote structure and data types, making them easy to read and write compared to other formats such as XML and JSON. Using a docker-compose yaml file we can do a lot of the things we do with docker and more.</p><p><strong>The basic difference between docker-compose and docker</strong></p><p>Docker is a platform for building, running, and managing containers. A container is a lightweight and portable software package that includes all the dependencies and libraries needed to run a specific application.</p><p>Docker Compose, on the other hand, is a tool for defining and running multi-container Docker applications. With Docker Compose, you can define your application’s services, networks, and volumes in a single file, then start and stop all services from this file. This makes it easier to manage and automate the deployment of multi-container applications. In other words, Docker Compose simplifies the process of managing multiple containers by allowing you to define and run all of your containers in a single place.</p><p>When building a container using docker, you need to set up the Dockerfile, but for docker-compose, you need to have the yaml configuration file. Although, you can always reference a Dockerfile from the docker-compose yaml file, and use a docker-compose command to build the image.</p><p>Here are some basic commands for docker-compose</p><p><strong>Building the Image:</strong></p><pre>docker-commpose build</pre><p><strong>Note:</strong> <em>Docker-compose is mainly used to run multiple docker containers and not build images. For you to build a docker image with docker-compose, you still need to reference the Dockerfile in the yaml configuration file.</em></p><p><strong>Running the container images:</strong></p><pre>docker-compose up -d</pre><ul><li>docker-compose up is the command used to start the services defined in the docker-compose.yml file.</li><li>-d (or --detach) is an optional flag that runs the services in the background and returns control of the terminal back to the user. This allows the services to continue running even after the terminal is closed.</li></ul><p>To shut down the services, you use docker-compose down . This command must be used in the same directory as the yaml file.</p><p>Those are the basic commands to help you get started with docker-compose. In the next project, we will be making use of docker-compose.</p><h3>Setting up pgcli for connectivity test</h3><p><em>pgcli</em> is a command-line interface (CLI) tool for PostgreSQL. It is designed to be a drop-in replacement for the standard psql client, with additional features and improved performance. No, you do not need to have PostgreSQL installed on your local machine to use pgcli. pgcli connects to a PostgreSQL database over a network, so as long as you have access to a remote PostgreSQL server and the necessary credentials, you can use pgcli to interact with the database. This makes it a convenient option for those who want to work with PostgreSQL databases but do not want to set up and maintain a local PostgreSQL installation.</p><p><strong>Installation</strong></p><p>To install pgcli on the Linux remote instance that we are working on, use the commands below:</p><pre>sudo apt-get install python-dev libpq-dev libevent-dev<br><br>sudo apt-get install pip<br><br>sudo pip install pgcli</pre><p>To test that the installation worked correctly, use pgcli --version</p><p>With pgcli installed on the remote machine, we have the ability to connect to any PostgreSQL database, provided we have the correct credentials and the server we are connecting from has been granted access to the database.</p><p>To use pgcli, you need the ff information about the database</p><p>pgcli -h hostname -p port -u user -d database_name</p><ul><li>h stands for the hostname which can be the internal/external ip address of the server hosting the database</li><li>p stands for port, this is usually 5432</li><li>u stands for the name of the user in which you have predefined</li><li>d stands for the name of the database in which you have predefined</li></ul><p>Once this goes through, you will be asked for the password, input it and press enter (Note: Nothing will show while you are typing the password)</p><h3><strong>Local setup for Postgres</strong></h3><p>This setup entails using a docker image to run a Postgres image as a container on your local machine (the remote instance). With docker, we don’t have to install postgres on our machine to start using it, we can just pull the image from docker hub and then run it on our local machine.</p><p>Here is a docker command that pulls a postgres image from docker hub and starts it up.</p><pre>docker run -it \<br> -e POSTGRES_USER=‘root’ \<br> -e POSTGRES_PASSWORD=‘root’ \<br> -e POSTGRES_DB=‘test_db’ \<br> -v $(pwd)/test_db_postgres_data:/var/lib/postgresql/data \<br> -p 5432:5432 \<br> postgres:13</pre><p>The container needs 3 environment variables:</p><ul><li>POSTGRES_USER is the username for logging into the database. We chose root as the username. [<em>Change to something else</em>]</li><li>POSTGRES_PASSWORD is the password for the database. We chose root as the password. [<em>Change to something else</em>]</li><li>POSTGRES_DB is the name that we will give the database. We chose test_db as the name of the database.</li></ul><p>-v points to the volume directory. The colon: separates the first part (path to the folder in the host computer) from the second part (path to the folder inside the container). This is useful because we need to link the part where the data is stored in the docker container to where it will be stored in the host computer.</p><ul><li>Path names must be absolute. If you’re in a UNIX-like system, you can use pwd to print your local folder as a shortcut; this example should work with both bash and zsh shells, but fish will require you to remove the $.</li><li>This command will only work if you run it from a directory that contains the test_db_postgres_data subdirectory you created above.</li></ul><p>The -p is for port mapping. We map the default Postgres port 5432 in the container to the same port 5432 in the host. In a case where you want to have two postgres databases running on your host machine at the same time, you can run another docker command but this time map the port to 5431 on your host machine because you can’t have multiple services running on the same port on your host machine.</p><p>The last argument is the image name and tag. We run the official Postgres image on version 13.</p><h3>Local Setup for Pgadmin</h3><p>PgAdmin is a free and open-source administration and management tool for the PostgreSQL database. Unlike pgcliit provides a graphical user interface for managing PostgreSQL databases, allowing users to interact with databases in an intuitive and user-friendly way. pgAdmin includes features such as a SQL editor, server management, backup and restore functionality, and a visual query builder.</p><p>Just like Postgres, you can also use docker to set up pgcli using the command below:</p><pre>docker run -it \<br>    -e PGADMIN_DEFAULT_EMAIL=&quot;admin@admin.com&quot; \<br>    -e PGADMIN_DEFAULT_PASSWORD=&quot;root&quot; \<br>    -e PGADMIN_COOKIE_SECRET=53tegevd66efdvfff<br>    -v &quot;./data_pgadmin:/var/lib/pgadmin&quot;<br>    -p 8080:80 \<br>    dpage/pgadmin4</pre><p>The container needs 3 environment variables:</p><ul><li>PGADMIN_DEFAULT_EMAIL is the email for logging into the pgadmin.</li><li>PGADMIN_DEFAULT_PASSWORD is the password for logging into pgadmin.</li><li>PGADMIN_COOKIE_SECRET is the secret key for the secure cookie used by pgAdmin to store session information.</li><li>v points to the volume directory. This is useful because we need to mount the storage location where the state of the pgadmin is stored in the host computer.</li></ul><p>The last argument is the image name dpage/pgadmin4.</p><p><strong>Note</strong>: We are going to be using pgadmin in the next project to interact with the database. We can also launch multiple instances of pgadmin by running them on diffrent ports on our host machine.</p><h3>Cloud SQL Set Up</h3><p>CloudSQL is a managed relational database service provided by Google, hosted on the cloud. With CloudSQL, you can create a database instance and connect it to your applications. CloudSQL offers three main database options: MySQL, Postgres, and SQL Server. In this project, we will create a Postgres database instance on CloudSQL and set up a connection to it. A CloudSQL instance is similar to a Compute Engine instance, but with a database already installed and no direct access to the underlying hosting machine. It is fully managed by Google.</p><p>In the previous section, we successfully set up Postgres using a Docker image on our remote host machine, showcasing the concept of building your core infrastructure. In contrast, Google CloudSQL eliminates the need for manual installation and management of the Postgres database on your instance by offering a managed platform for database management.</p><p>Here is a step-by-step guide on how to set up a postgres database on Google Cloud.</p><ol><li>Open the Cloud Console: Log in to the Google Cloud Console and select the project that contains your other resources.</li><li>Create a Cloud SQL instance: In the Cloud Console, go to the Cloud SQL instances page (<strong>Navigation Menu &gt; SQL</strong>). Click the Create instance button. This would take a while.</li><li>Configure your instance: Choose PostgreSQL as the database engine, select a region, and provide a name for your instance. You can also configure settings such as disk size, availability, and backups.</li><li>Create a database: In the Cloud Console, go to the Cloud SQL instances page and click on your instance’s name. On the instance’s details page, click on the “Databases” tab and then click on the “Create database” button.</li><li>Create a user: On the instance’s details page, click on the “Users” tab and then click on the “Add user account” button. Add a username and a password.</li></ol><p>Click on the overview tab to view the external ip address of the cloudsql instance. By the time you are done, you should have the following information:</p><ul><li>Private IP address which can serve as the hostname</li><li>Public IP address which can serve as the hostname</li><li>User Name</li><li>Password Name</li><li>Database Name</li><li>Port: By default, postgres runs on port 5432</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZB5E-s6XVhXVKFLxlsIXA.png" /></figure><h3><strong>Connecting to the Databases</strong></h3><p>Connecting to Databases relies heavily on communicating using IP addresses and ports. In this section, we are going to examine the various ways of connecting to our database both on the host machine (remote instance) and on the cloudsql instance.</p><h4>Connecting to a Postgres Docker Container Running on a Virtual Machine</h4><p>A docker Postgres image is used to run multiple containers on a virtual machine. This is similar to having postgres installed locally on the virtual machine.</p><p>We are going to review 3 basic ways of setting up a connection</p><ol><li><strong>Internal Connection within the host machine</strong></li></ol><p>Internal connections can be made on the host machine using local host and the port that is mapped to the postgres container when you run the docker command to start up the postgres container.</p><p>Take for instance, to test that a connection can be made to a postgres database running on port 5432 on your host machine as seen from the command below. Run the docker command below to spin up the postgres container. [The -d flag means run the command in detached mode].</p><pre>docker run -it \<br> -e POSTGRES_USER=‘root’ \<br> -e POSTGRES_PASSWORD=‘root’ \<br> -e POSTGRES_DB=‘test_db’ \<br> -p 5432:5432 \<br> -d \<br> postgres:13</pre><p>Test the connection:</p><pre>pgcli -h localhost -p 5432 -u root -d test_db</pre><p>If the command above works, you will be asked to input the password you initially set, which is root. You will then have access to the database. Press Ctrl + D to close the database and return back to your terminal.</p><p>Here is where the advantage of docker comes in, with docker, you can run multiple postgres database on your host machine without worrying about any form of interference or complex configurations.</p><p>Run the ff command on your host machine to spin up another postgres database.</p><pre>docker run -it \<br> -e POSTGRES_USER=&#39;root2&#39; \<br> -e POSTGRES_PASSWORD=&#39;root2&#39; \<br> -e POSTGRES_DB=&#39;test_db2&#39; \<br> -p 5431:5432 \<br> -d \<br> postgres:13</pre><p>Now, connect to it using the command below:</p><pre>pgcli -h localhost -p 5431 -u root2 -d test_db2</pre><p>Notice that I mapped the port of the 2nd database to 5431 on the host machine. This is because you cannot have multiple services running on the same port on your host machine.</p><p>2. <strong>Connections via Instances in the same VPC network as the Host Vm</strong></p><p>To better understand this, go to the Google Cloud Console &gt; Navigation Menu &gt; Compute Engine. Create a new instance (ensure this is in the same project as your other resources). Set up your ssh configuration on your local machine as shown in part 1 of this series and connect to the VM.</p><p>When you create a virtual machine (VM), it is assigned an internal IP address from the default VPC network. This enables internal communication among resources within your Google Cloud project. As a result, two remote instances can communicate with each other as they are within the same VPC network.</p><p><strong>Steps to Follow:</strong></p><ul><li>Ensure that you still have the two postgres containers running on the first remote instance (one running on port 5432, the other running on 5431</li><li>Log into the second remote instance, and run the ff command sudo apt-get update &amp;&amp; sudo apt-get install pgcli</li><li>Test connectivity from the second remote database to the two databases using the command below.</li></ul><pre>pgcli -h internal_ip_address -p 5432 -u root -d test_db<br><br>pgcli -h internal_ip_address -p 5431 -u root2 -d test_db2</pre><p>The internal IP address referred to in the command above is the internal IP address of the first remote instance that is hosting the Postgres database. To obtain the IP address, navigate to the Compute Engine tab in the Google Cloud Console, and copy the internal IP of the host virtual machine (VM). Additionally, make a note of the external IP address, as it will be used later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGv3DDgRIPewpHR89YrjqQ.png" /></figure><p>3. <strong>Connections via networks outside the VPC network of the Host VM</strong></p><p>Typically, you would want to connect to the database from a network outside the VPC network that hosts the Postgres database. In such scenarios, we need to update the firewall rules of the VPC network connected to the VM hosting the database to allow external connections.</p><p>Log in to the Google Cloud Console.</p><ol><li>Navigate to the VPC networks page by clicking on the “VPC network” option in the navigation menu.</li><li>Click on the “Firewall” tab, and then click on “Create a firewall rule”</li><li>In the “Name” field, enter a name for the firewall rule. Leave the network as default.</li><li>Under Targets, select All instances in the network. Leave Source filter as IPv4 ranges.</li><li>In the “Source IP ranges” field, enter “0.0.0.0/0” to allow connections from any IP address. (This is not best practice)</li><li>In the “Allowed protocols and ports” field, click on the TCP checkbox and enter “5432, 5431” to allow connections on both ports on your host machine.</li><li>Click on the “Save” button at the bottom of the page to create the firewall rule.</li></ol><p>With this all set, you can then connect to the database using the external address of the host VM.</p><pre>pgcli -h external_ip_address -p 5432 -u root -d test_db<br><br>pgcli -h external_ip_address -p 5431 -u root2 -d test_db2</pre><h4>Connecting to a Postgres Database Hosted on Google CloudSQL</h4><p>The cloudsql instance is just like a vm hosting the postgresDB without you having direct access to alter the configurations. This is what we refer to as a managed service.</p><ol><li><strong>Internal Connection within the VPC Network</strong></li></ol><p>Cloudsql just like a compute engine instance also has both an internal ip address and external ip address. With its internal ip address, you can connect to the cloudsql instance from any virtual machine on the same VPC network.</p><pre>pgcli -h internal_ip_address_of_cloudsql_instance -p 5432 -u user -d db</pre><p>You can view the internal(private) and external(public) ip address of your cloudsql instances on Google Cloud Console by navigating to the SQL tab on the Navigation Menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egZL8XkLm4rZMfxLWW4yog.png" /></figure><p>2. <strong>External</strong> <strong>Connections outside the VPC network of the Cloudsql Instance</strong></p><p>This also includes setting up firewall rules that allow external networks to connect to the cloudsql instance.</p><p>Navigate into the Cloudsql instance you just created by clicking on the Instance Id. Go to the “Connections” section of the Cloud SQL instance. Scroll down to Authorized networks. Click on Add Network. Add a name (Anything you want). Add 0.0.0.0/0 as the Network. This basically means any external connection now has access to the database provided they have the login credentials.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KJpaACX5IZEWTp4LHoiWlQ.png" /></figure><pre>pgcli -h external_ip_address_of_cloudsql_instance -p 5432 -u user -d db</pre><p><strong>Note:</strong></p><p>Even after you have added 0.0.0.0/0 as an allowed network. This prefix will allow any IPv4 client to pass the network firewall and make login attempts to your instance, including clients you did not intend to allow. Clients still need valid credentials to successfully log in to your instance.</p><p>In the previous setup, we were able to run multiple Postgres databases using Docker images on the same virtual machine without encountering any dependency issues because they were running on different ports (5432 and 5431). With CloudSQL, you can only run one Postgres database per instance, using port 5432, but you can have multiple CloudSQL instances and connect to each of them separately.</p><h3>Best Practices when Configuring a Database</h3><p>When configuring a database, there are certain things you should watch out for and best practices to follow to help you get started.</p><p><strong>Creation of Read Replicas</strong>: Read replicas are read-only copies of your database instance. When configuring your database, you have the option to set up a read replica, creating another instance of the database. This instance is assigned both an internal and external IP address, which can be used for connecting to it.</p><p>To create a read replica, navigate to the instance you have created, and then click on the “Replicas” tab. Select the “Create Read Replica” option at the top to initiate the process. Once the read replica is created, you can configure its own connection settings, which will be distinct from the original database that has both read and write access.</p><p><strong>Exposing the Database to External Connections</strong>: In the previous section, we explored a method for external networks to connect to your database instances by adding 0.0.0.0/0 as an authorized network. However, this is not considered a secure best practice. A more pragmatic approach is to add the specific IP address of the device you are using to access the database, such as another virtual machine that you have access to.</p><p>These are just two out of the many factors to consider when configuring a database, it is very important that you focus on building resilient systems that are reliable and can withstand zones failure.</p><h3>Summary</h3><p>In this article, we were able to set up multiple postgres databases using the Infrastructure as Code model (IaaS) and the Platform as a Service model (PaaS). The IaaS model requires us to install docker on the host machine, and run the container from a postgres image. With this method, you can spin up multiple postgres containers from a single image, and manage their configurations individually or with a docker-compose.yaml file.</p><p>We also utilized Google Cloud SQL, which is a PaaS solution, and used it to create a database to which you can connect. I made reference to some best practices on how to allow both internal and external networks to connect to the databases. Lastly, I referenced how you can use pgcli for connectivity tests to your database.</p><p>In the next project, which is a sequel to this, we will build a data pipeline that will read data from the web and write that data into our postgres database.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=763f2f8dee6e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deployment of Containerized Data Applications on Google Cloud Run (pt1)]]></title>
            <link>https://medium.com/@nwosupaul141/deployment-of-containerized-data-applications-on-google-cloud-run-pt1-80750dce02f8?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/80750dce02f8</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 27 Jan 2023 05:32:26 GMT</pubDate>
            <atom:updated>2023-01-27T05:32:26.799Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ufaYxH6hK9ehYE0cXsSpUw.png" /></figure><p>In this project, a yahoo finance web scraper is built using python, selenium, and beautiful soup. An image of this application is built using docker, this image is pushed to Google Artifact Registry, and then deployed on Google Cloud Run.</p><p>This is the 3rd part of a series I started called “Building your First Google Cloud Analytics Project.”</p><p>Check out <a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">Part 1</a>, <a href="https://medium.com/@nwosupaul141/building-an-etl-pipeline-using-google-service-accounts-85e2a6cfd94d">Part 2</a></p><p>Link to GitHub <a href="https://github.com/paulonye/Cloudrunjobs/tree/main/yahooscrape1">Repo</a></p><h3><strong>Project Structure</strong></h3><ul><li>Background of the Data Application</li><li>Basics of Docker</li><li>Building the Docker Image</li><li>Running the Docker image locally</li><li>Introduction to Artifact Registry</li><li>Introduction to Google Cloud Run Jobs</li><li>Configuration settings of Cloud Run</li><li>Setting up a scheduler for the Cloud Run Job</li></ul><h3><strong>Background of the Data Application</strong></h3><p>In the last project, we built a web scraper that collected data from Yahoo Finance and loaded it into a Google Sheets spreadsheet connected to a visualization dashboard. The application environment for the scraper and data pipeline were set up and are managed on a Compute Engine instance, which is Google’s primary Infrastructure as a Service (IaaS) solution.</p><p>The previous project clearly demonstrated what it means to build using the IaaS compute cloud model. In this project, we will use the same pipeline but deploy it on Google Cloud Run, which uses the Platform as a Service (PaaS) compute model and is serverless. More on that later.</p><h3><strong>Basics of Docker</strong></h3><p>Docker is a containerization tool that allows you to create containers on your machine. It helps you package your application and all its dependencies into a single container, which can be built, run, and deployed consistently. Some of the benefits of using Docker include:</p><ul><li>Containerization: Docker eliminates the need to worry about OS-type dependencies, environment variables, and interference between similar software when developing applications.</li><li>Virtualization &amp; Isolation: With Docker, you can have multiple versions of the same software installed on multiple containers without worrying about their interaction.</li><li>Reproducibility: Docker allows you to run applications on various platforms, eliminating the need to worry about OS-type dependencies and environment variables. Using a Docker image, which is like a snapshot of a container, you can easily deploy your application on any supporting computing environment.</li></ul><p>To use Docker, you can pull an image from the Docker Hub using the docker pull command. This image can then be used to run a container that can host the application and all its dependencies. For example, you can pull a Postgres:13 Docker image and configure it to run multiple Postgres applications simultaneously without them interfering with each other, as long as they are running on separate ports.</p><p>Let’s take a look at some docker commands to help you get started:</p><p>In the <a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">first article</a> in this series, I already showed you how to install docker on the remote instance that we will be using.</p><p><strong>Docker run</strong>: The docker run command is used to start a container from an image. Try the ff commands below:</p><pre>docker run hello-world</pre><p>hello-world is the name of the image, when you run the command, docker pulls that image from docker hub if it doesn’t already exist on your machine, and uses it to build, then runs the container.</p><p><strong>Docker images</strong>: This command is used to check all the images that you have available on your host machine. This generally includes images that you pulled from docker hub and does that you built yourself.</p><pre>docker images</pre><p><strong>Docker build</strong>: The command used to build a Docker image from a Dockerfile is docker build. A Dockerfile is a script that contains instructions for building a Docker image. It is a plain text file that specifies the steps required to create a specific image. Each instruction in the Dockerfile creates a new layer in the image, and these layers are combined to create the final image.</p><p>Here is an example of a simple Dockerfile that creates an image for a Python application:</p><pre>FROM python:3.8<br><br>COPY test.py /home/app/test.py<br><br>COPY requirements.txt /home/app/requirements.txt<br><br>RUN pip install -r requirements<br><br>WORKDIR /home/app<br><br>ENTRYPOINT [&quot;python&quot;, &quot;/home/app/test.py&quot;]</pre><p>A Dockerfile typically starts with a FROM instruction, which specifies the base image to use for the new image. Other instructions are used to configure the image, such as:</p><ul><li>RUN to run commands</li><li>COPY to copy files and directories</li><li>ENV to set environment variables</li><li>EXPOSE to specify the ports exposed by the image</li></ul><p>The above is an example of a simple Dockerfile that uses the Python 3.8 image as the base, copies the contents of the local directory test.py and requirements.txt to the container’s /home/app directory, runs the command pip install -r requirements.txt to install the required dependencies, sets the /home/app directory as the working directory, and sets an entrypoint to run the python script when the container is launched</p><p>It’s important to note that the order of the instructions in the Dockerfile is important as they are executed in the order they are written, and each instruction creates a new layer in the image.</p><p>Once you have a Dockerfile, you can use the docker build command to build an image from it. The docker build command creates an image from a Dockerfile and a context, which is the set of files in the directory where the Dockerfile is located and its subdirectories.</p><h3><strong>Building the Docker Image for the Yahoo Finance Scraper</strong></h3><p>In the last two projects, can you remember the steps we took to set up an environment to run the scripts of the Yahoo scrape? We are going to replicate those steps and document them in a Dockerfile. Some of the steps we took involved installing Google Chrome and the Chrome driver, importing the Selenium and Beautiful Soup libraries, and setting up the service account key as an environment variable.</p><p>Here is the guide to help you build your docker image for the Yahoo Scraper. To get started, create a Dockerfile using the command touch Dockerfile in the directory that contains the files that are required for your application to run successfully.</p><pre>FROM python:3.8<br><br>#Installtion of Google Chrome<br># Adding trusting keys to apt for repositories<br>RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -<br># Adding Google Chrome to the repositories<br>RUN sh -c &#39;echo &quot;deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main&quot; &gt;&gt; /etc/apt/sources.list.d/google-chrome.list&#39;<br># Updating apt to see and install Google Chrome<br>RUN apt-get -y update<br>RUN apt-get install -y google-chrome-stable<br># Installing Unzip<br>RUN apt-get install -yqq unzip<br><br># Download the Chrome Driver<br>RUN wget -O /tmp/chromedriver.zip\<br>http://chromedriver.storage.googleapis.com/\<br>curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE/\<br>chromedriver_linux64.zip<br><br>#Copies the service account key into the docker container<br>COPY key.json /home/app/key.json<br><br>#Sets the service account key.json as an environmental variable called key_file<br>ENV key_file key.json<br><br>#Copies the needed libraries <br>COPY requirements.txt /home/app/requirements.txt<br><br>#Installs the needed libraries<br>RUN pip install -r /home/app/requirements.txt<br><br>#Copies the ff scripts into the docker container<br>COPY connect.py /home/app/connect.py<br>COPY main.py /home/app/main.py<br>COPY scrape.py /home/app/scrape.py<br><br>#Sets the working directory<br>WORKDIR /home/app<br><br>ENTRYPOINT [&quot;python&quot;, &quot;/home/app/main.py&quot;]<br>CMD [&quot;--googlesheet&quot;, &quot;test_sheet&quot;, &quot;--sheetname&quot;, &quot;data4&quot;]</pre><p>Once this is done, it’s time to build the image using the command below:</p><pre>docker build -t name_of_image .</pre><p>The name_of_image refers to the name you want to give the image and the . means build the image from the current directory. Once you run this command, docker begins to build the image; this might take some time depending on the processes declared on the Dockerfile. You only have to build an image once for the first time, or anytime you make a change in any of the files required for the application to run.</p><h3><strong>Running the Docker Image Locally</strong></h3><p>Now the building process is over, and the image is on your local machine. Run the command docker images to view all the images you have available. It’s possible that you see some other images, this can be because of previous docker run commands that you used. Take for instance, if you had used docker run python:3.8 this downloads the python 3.8 image on your local machine and then uses it to build a container. The next time you run this command, it doesn’t need to download the image, because the image already exists on your local machine, so it just builds the container of the already existing image. To run the image you just built, use the ff:</p><pre>docker run -it runjob:tag1</pre><p>The above command uses the image name runjob:tag1 to build a container with all of the application dependencies. In our Dockerfile, we had specified ENTRYPOINT as python , and the absolute directory of the main python script. This basically means, that once our docker container starts running, it automatically runs the python script which in this case is the scraper that you built. Once the script has been run successfully, the docker container instance is killed.</p><p>To view the docker containers that are currently running, use docker ps . This command returns row(s) of the container(s) running. The first column shows the container id.</p><p>You can view the contents of a running container by using docker exec -it container_id bash , and also view the contents using the image name with the ff commands:</p><pre>docker run -it --entrypoint=bash runjob:tag1<br><br>docker run -it runjob:tag1 bash</pre><h3><strong>Introduction to Artifact Registry</strong></h3><p>Our docker image works, so it’s time to deploy it on cloud run, but before doing so, we need to push that image to Google Artifact Registry. Google Artifact Registry is a fully-managed, private artifact storage service that allows you to store, manage, and access your software packages. It provides a central location for your team to store and manage images, containers, and other artifacts. It supports common package management formats, such as Maven and npm, and it integrates with Google Cloud Build and other CI/CD systems. With Google Artifact Registry, you can easily manage access to your packages and artifacts, and you can also use it to build and deploy your applications on Google Cloud Platform.</p><p>When you build an image using docker, note that you are building it locally, so it is important to push that image to a remote location where Google Cloud Run can access it easily. In this case, that central location is the Artifact Registry.</p><p>Below are the steps needed to push an image to Artifact Registry:</p><p><strong>Enable the Artifact Registry API</strong>: Go to the <strong>Google Cloud Console &gt; Navigation Menu &gt; Artifact Registry &gt; Library. </strong>Search for artifact registry api and then enable it.</p><p><strong>Create the Repo</strong>: Go to the <strong>Google Cloud Console &gt; Navigation Menu &gt; Artifact Registry. </strong>Create the repo as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RqPV3qDf9Lq_EinlixNlzg.png" /></figure><p><strong>Configure Docker to authenticate to a Google Container Registry: </strong>When creating our repo, we chose the us-central1 region, so we need to authenticate to that repo using the command below:</p><pre>gcloud auth configure-docker us-central1-docker.pkg.dev</pre><p><strong>Build the docker image using the command below:</strong></p><pre>docker build -t us-central1-docker.pkg.dev/my-project/my-repo/my-image:tag1 .</pre><p>Set my-project to your current project id. To get/view your project id, use the gcloud config list project .</p><p>Set my-repo to the name of the repo you created.</p><p><strong>Push the docker image to Artifact Registry:</strong></p><pre>docker push us-central1-docker.pkg.dev/my-project/my-repo/my-image:tag1</pre><p>Check the Artifact Registry on the Goolgle Console to confirm that the push was successful.</p><h3><strong>Introduction to Google Cloud Run Jobs</strong></h3><p>Google Cloud Run allows you to easily deploy and run containerized applications on the Google Cloud Platform. It offers two main options for deploying your application: Cloud Run Service and Cloud Run Job.</p><p>Cloud Run Service is designed for long-running applications that need to be available continuously. With this option, your application is automatically scaled to handle incoming traffic and will continue running until it is manually stopped.</p><p>On the other hand, <em>Cloud Run Job</em> is intended for short-lived, scheduled tasks that need to be completed and then stopped. With this option, you can create a Cloud Run Job and trigger it to run at a specific time or on a schedule. This is useful for tasks such as data processing, backups, and other scheduled jobs that need to be performed on a regular basis.</p><p>Both options provided by Cloud Run, allows you to easily deploy your containerized applications on the Google Cloud Platform, without the need to manage the underlying infrastructure.</p><p>For our task, we will be using Cloud Run Jobs. Below are the steps required to help you get started:</p><p><strong>Enable the ff APIs</strong>: Compute Engine API, Cloud Run Admin API, Cloud Scheduler.</p><p><strong>Deploy the Image on Cloud Run: </strong>Once the image is in the artifact registry, deploy the image using the image name as stored in the artifact registry and also the selecting a region where you want the application to run.</p><pre>gcloud beta run jobs create &lt;name-of-job&gt; --image &lt;image_name:tag&gt; --region &lt;region&gt;</pre><p>Based one the image, <em>runjob:tag1</em>, that I created and the us-central1 region that I selected, my command looks like this:</p><pre>gcloud beta run jobs create scrapeyahoo --image us-central1-docker.pkg.dev/my-project/my-repo/my-image:tag1--region us-central1</pre><h3>Configurations Settings on Cloud Run</h3><p>Once the app has been deployed, you might need to make some configuration settings based on the size of the image which you can see in the directory of the artifact registry.</p><p>Go to <strong>Google Cloud Console &gt; Navigation Menu &gt; Cloud Run. </strong>Select the <em>JOBS </em>tab to view the job you just created.</p><p>Click on the name of the job you just created and select edit</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1avtRYYs7cNYp8JBFsKwA.png" /></figure><p>Change the memory and cpu configurations as seen below; for higher workloads, you might need to make more adjustments. Save the changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Um4_dT-3Gd8OHb_7uWqItw.png" /></figure><p>Click on execute, if it works, then you shoudld get something like this in front of the Execution ID ✅.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*brXiaXHyoujFFmhLlKBBfQ.png" /></figure><h3>Setting up a scheduler for the Cloud Run Job</h3><p>The final step in this project, will be to set up a trigger for the cloud run job to run at specific times using Google Cloud Scheduler.</p><p>Go to <strong>Google Cloud Console &gt; Navigation Menu &gt; Cloud Scheduler. </strong>Click on CREATE JOB.</p><p>Define the Schedule: You need to set a name for the job, select a region <em>(This should be the same with the region you selected for the cloud run job), </em>and also set a frequency you want to run the job <em>(it’s the same style as a cron job). </em>Lastly, select a timezone based on your country local time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXh5msXhaKBxGh8y3U03bQ.png" /></figure><p>Configure the Execution: Follow the configuration settings as seen in the image below.</p><p>For the URL, use this template:</p><pre>#Template to follow<br>https://&lt;REGION&gt;-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/&lt;PROJECT_ID&gt;/jobs/&lt;JOB_NAME&gt;:run<br><br>#This is how it looks like for me<br>https://us-central1-run.googleapis.com/apis/run.googleapis.com/v1/namespaces/gcpprojects-35734/jobs/yahooscrape:run</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bGhopt-BCemSAEbYdH9RZg.png" /></figure><p>Configure Optional Settings: Follow the template below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-q6SsmpUMJX389vyK83L1A.png" /></figure><p>Once this is done, select Create.</p><p>You can force a job by clicking the vertical dots and select <em>Force a job run </em>or you can just wait. If the job is successful, you will see a ✅.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kl2_lMCBjgDv7IXhhhfI0A.png" /></figure><p>You can also pause and delete jobs.</p><p>That’s the end of the 2nd project in my GCP series. Here is a summary of everything we did:</p><ul><li>Set up a Dockerfile to build our application as an image</li><li>Ran the image on our local machine (or remote instance) to ensure it works</li><li>Set up the Artifact Registry to store our image</li><li>Deployed the image on Cloud Run</li><li>Set up a scheduler to trigger the Cloud Run job</li></ul><p>In the next project, we will delve into setting up two types of databases: using a Docker container and using Google Managed Cloud SQL. We will explore the benefits and limitations of each approach and how to choose the right one for your use case. Additionally, we will also explore how to set up a pipeline to automatically backup data and how to scale and monitor your database. Overall, this series provides a comprehensive guide on how to set up and manage your infrastructure on GCP.</p><p>In conclusion, this project was a great opportunity to delve into the world of containerization and serverless computing with GCP and gave us a good understanding of how to use Docker and Cloud Run to build, run, and deploy our application in a consistent and efficient way. I hope you enjoyed reading this article and learned something new.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80750dce02f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building an ETL Pipeline Using Google Service Accounts]]></title>
            <link>https://medium.com/@nwosupaul141/building-an-etl-pipeline-using-google-service-accounts-85e2a6cfd94d?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/85e2a6cfd94d</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 20 Jan 2023 09:41:27 GMT</pubDate>
            <atom:updated>2023-01-20T09:41:27.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*e76lt1_9p1PwZ8hfwLxw-w.png" /></figure><p>In this project, financial data from Yahoo Finance is scraped using Selenium, transformed, and imported into a Google Sheets spreadsheet. The imported data will then be connected to Google Data Studio for visualization.</p><p>This is the second part of a series I started called “Building your First Google Cloud Analytics Project.” To fully understand the project, it’s important to read the first article on how to set your environment. Find the link below:</p><p><a href="https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6">https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6</a></p><p><strong>Project Structure</strong></p><ul><li>Connecting to your Remote Instance</li><li>Enabling the Google Sheet API</li><li>Setting up a service account and downloading the key</li><li>Basics of SFTP</li><li>Setting environment variables</li><li>Installing all the required libraries</li><li>Building the Scripts</li><li>Testing</li><li>Setting up a cron job</li><li>Loading the Google Sheet Data into Looker Studio</li></ul><p><strong>Connecting to your Remote Instance</strong></p><p>In my previous article, I demonstrated how to set up a cloud environment on Google Cloud for data-related projects. In this project, we will use the remote instance we created to build a data pipeline. To connect to the remote instance from the terminal of your local machine, type in the command ssh alias_name, where “alias_name” is the name you assigned to your remote instance when setting up your config file in the .ssh folder on your home directory. Once connected to the remote instance, the next step is to clone the repository for the project.</p><p>Cloning the repository is optional but it will make it easier for you to follow along as I explain the project.</p><pre>git clone https://github.com/paulonye/Smart_Sheet</pre><p><strong>Enabling the Google Sheet API</strong></p><p>In this project, we will be loading financial data from Yahoo Finance into Google Sheets. Google Sheets is a Software as a Service tool owned by Google, so as a Google Cloud user, you have access to its API. To get started, navigate to console.cloud.google.com. Please note that you must have selected the project in which you created your remote machine as all project resources are tied together. In the console, click the <strong>Navigation menu &gt; APIs &amp; Services</strong>. Click on Library and search for the Google Sheets API. Once you find it, click on it and enable it. You can also search for the Google Drive API and enable it.</p><p><strong>Setting up a service account and downloading the key</strong></p><p>Google Service Accounts are a way for applications to authenticate to the Google Cloud Platform (GCP) APIs and services, using a set of predefined credentials. These credentials are managed by an associated project and can be used for a variety of purposes, such as granting permissions to specific resources and services, or for application-to-application communication within a GCP project. The authentication process is based on JSON Web Tokens (JWT), which allow applications to access resources without user intervention. In this project, we are going to use a service account to grant us authenticate access between python and a google spreadsheet that we will create.</p><p>To create a service account, click the <strong>Navigation menu &gt; IAM &amp; Admin &gt; Service Accounts. </strong>Click on create a service account. Select a name for the service account, grant the service account an editor role (From Basic), click on continue, and DONE.</p><p>Now that the service account has been created, click on the triple dots at the end of the row, and then select Manage keys. Select ADD KEY &gt;Create a new key, select JSON, and then create. Once this key has been created, it automatically downloads to your local machine. Since we will be using our remote instance as our development environment, we need to transfer the key into our remote instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLS63e2AibAQKqsgn-WRVw.png" /><figcaption>Service Account Portal</figcaption></figure><p><strong>Basics of SFTP</strong></p><p>SFTP stands for Secure File Transfer Protocol. It uses SSH (Secure Shell) to provide secure authentication and encryption for data transferred over the network. SFTP can be used to transfer files between computers, servers, or even between different cloud platforms using simple commands like get and put. SFTP is very similar to the way SSH works. Recall that to log into a remote instance from your local machine, you need to first set up a config file with the external IP address of the remote instance. This allows you to use the command ssh alias_name and log into the remote instance. To connect to the remote instance using SFTP, you use the command sftp alias_name. Note that before running the command, you must be in the directory of the file you want to transfer to the remote instance. Once you are in that directory, you can sftp into your remote instance and use the command put filenameto copy the key file and place it in the home directory of the remote instance. To copy a file from the remote machine to your local machine, navigate to the directory of the file and then use the command get filename, this copies the file into your local machine.</p><p><strong>Setting Environment Variables</strong></p><p>Environmental variables are system variables that store information about the environment in which a computer program or process runs. They can be used to configure various aspects of the program, such as the location of files or settings that the program needs to access. Environmental variables can be set and accessed using the command line or through various programming APIs.</p><p>In this project, we will use an environmental variable to store the service account key. This is done for security reasons. It is important to note that in a professional setting, it is not best practice to give a service account editor role to a project, as the rule of least privilege should be employed.</p><p>Let’s assume that the name of the key is test_1324.json. To set this as an environmental variable, run the following bash commands:</p><pre>#create a hidden directory in the home directory and move my service account key there<br>mkdir .service_account_key &amp;&amp; mv test_1342.json ~/.service_account_key/test_1342.json<br><br>#navigate to the directory to confirm that the key is there<br>cd .service_account_key<br><br>#Return back to the home directory<br>cd ~<br><br>#Open the .bashrc to set your key as an environment variable that can be accessed from anywhere<br>#for linux, the .bashrc file is located in the home directory<br>nano .bashrc<br><br>#The above command opens the Nano editor, Scroll down and then edit the file by adding<br>export key_file=&#39;/home/macbook/.service_account_key/test-1342.json&#39; <br><br>#Note: macbook is the name of my user, so change this to reflect yours<br><br>#The command below is used to ensure that the changes take effect; restart your remote instance once you run the command<br>source .bashrc<br><br>#To confirm that your environment variable was set correctly; use the command below:<br>echo $key_file<br>#this should print out /home/macbook/.service_account_key/test-1342.json</pre><p><strong>Installing the Required Libraries</strong></p><p>For this project, we will be using some important libraries that are not pre-installed with Python. If you had cloned the git repo as I instructed earlier, you can navigate into the directory and run the command pip install -r requirements.txt. This will install all the necessary libraries including Selenium and Beautiful Soup.</p><p><strong>Building the Scripts</strong></p><p>In the current directory, you will find the following scripts main.py sheet_connect.py send_mail.py push.py &amp; push_append.py. The first four are used as modules to aid the last script push_append.py</p><p>main.py: This python script is used to extract the data from Yahoo Finance. It uses selenium and beautiful soup which are both web scraping tools to pull the data from the website and save it as a python data frame.</p><p>sheet_connect.py: This python script contains the functionality that sets up the connection from Python to Google Sheets.</p><p>send_mail.py: This python script was set up for logging and error management. It contains functionalities that inform us when the pipeline breaks, and what caused the break.</p><p>push.py: This python script was used to push the first batch of data from yahoo finance to Google Sheets. It is mainly used to test if the connection between Python and Google Sheets actually works. Before running the push_append.py script, it is important to run this script first so that you can test if the connection works.</p><p>push_append.py: This is the Python script that combines the functionality of all the other scripts. The other scripts are imported as modules and their various functionalities are combined to ensure that the data is scraped, transformed, and transferred to Google Sheets.</p><p><strong>Understanding how Selenium and Beautiful Soup</strong></p><p>Selenium and Beautiful Soup are tools that are both used for web scraping, I consider selenium to be more powerful than beautiful soup because it can interact with a web page just as a human would, such as clicking buttons, filling out forms, and navigating between pages. For example, if you wanted to scrape data from a website, you could use Selenium to open the website, navigate to the page where the data is located, and then extract the data from the page.</p><p>For Beautiful soup, the process is quite different. It allows you to parse HTML and XML documents, and extract useful information. The library creates parse trees from the HTML or XML documents, which can be used to extract data easily. You can use Beautiful Soup to find specific tags, navigate through the parse tree, and extract the data that you need.</p><p>For this project, both Selenium and Beautiful Soup were used for scraping data. Selenium was used to load the webpage and save it as a static page, which is then passed to a Beautiful Soup object. From the Beautiful Soup object, I then identified the tags that contained the data needed.</p><p>Here is a snap of the data we will use, see the link below: <a href="https://finance.yahoo.com/crypto/?.tsrc=fin-srch&amp;offset=0&amp;count=15">https://finance.yahoo.com/crypto/?.tsrc=fin-srch&amp;offset=0&amp;count=15</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Ule5W1AcIN9oVFMCkgD-g.png" /><figcaption>Yahoo Finance Website</figcaption></figure><p>It should be noted that the link used was adjusted to display only the top 15 companies based on Market Cap. That’s something to keep in mind when scraping, always try and see if you can manipulate the URL to your advantage. To find the tag of the data you want to scrape, right-click on the element and click on “inspect” in the browser’s developer tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1GAsJJ2H-d9WPGITSsk77Q.png" /><figcaption>Yahoo Finance Website</figcaption></figure><p>From the image you provided, after right-clicking on 410.19B and choosing “inspect”, we can see the details of that element. We can see that the element begins with the tag “td”, which stands for table data. There is also another unique identifier, the “aria-label”. Using these two elements, we can scrape that entire column. We will also do this for the price and symbol columns. You can refer to the main.pyscript to see the code.</p><p><strong>Error Management</strong></p><p>An important step when building pipelines is to account for failures. For this project, we will set up a script that informs us by sending an email to a Gmail account whenever our script breaks. The smtplib module is used to set this up. Refer to the send_mail.py to see the code. There are some things you need to do first.</p><ul><li>Navigate to the security settings of your Gmail account</li><li>Enable 2-step verification</li><li>Set your App password</li></ul><p>You will need the email address and the app password when setting up the function to send the mail.</p><p><strong>Note</strong>: You will need to replace the email address and the password on the send_mail.py script with yours.</p><p><strong>Testing the Script</strong></p><p>In this workflow, we are scraping data and loading it into Google Sheets using a service account as the connector, when you create a service account, it creates an email address associated with the service account. Go back to the google console <strong>Navigation &gt; IAM &amp; Admin &gt; Service Account</strong>, look for the service account you created, and copy the email address.</p><p>Follow these steps:</p><ul><li>Create a folder in your google drive</li><li>Create a random Google Sheet called ‘test_sheet’ (This is the name of the sheet I used in the code)</li><li>Once the sheet has been created, on the upper right corner, click on share, and add the email address of the service account, make sure you give it edit access to the sheet.</li><li>Rename the worksheet tab ‘data’</li></ul><p>To test that the connection is working, navigate to the directory that contains the script, and run python sheet_connect.py in the command line. This should give an output ‘data’.</p><p>If you review the sheet_connect.py script you will notice that the environmental variable containing the service account key was imported and used for authorization.</p><p>When you are sure that the connection between your environment and the Google Sheets has been established, run the ff command</p><pre>#Push the first batch to test<br>python push.py<br><br>#Append new batches <br>python push_append.py<br></pre><p><strong>Setting a cron job</strong></p><p>The final step in building this pipeline is to set up an automated way of scraping the data and appending it to your Google Sheet continuously. You can achieve this by opening the crontab and creating a new cronjob.</p><p>To open the crontab, use:</p><p>crontab -e</p><p>Navigate to the last line and write the cronjob</p><pre>* * * * * export key_file=/home/macbook/.service_account_key/test_1324.json; /home/macbook/anaconda3/bin/python3 ~/Smart_Sheet/push_append.py</pre><p>Save the crontab by pressing Ctrl+O and then closing it by pressing Ctrl+x.</p><p>The cronjob above does three things:</p><p>* * * * *: schedules the script to run every minute. You can use this website <a href="https://crontab.guru/">https://crontab.guru/</a> to schedule your cronjobs. I advise you to set this to every hour 0 * * * * .</p><p>export key_file=/home/macbook/.service_account_key/test_1324.json: sets the environmental variable before running the script because cronjobs operate on a different terminal and can’t read the environment variable from the .bashrc file.</p><p>/home/macbook/anaconda3/bin/python3 ~/Smart_Sheet/append.py: uses python from the anaconda directory because we didn&#39;t install python locally.<br>If we did then the command would have been:</p><p>python3 ~/Smart_Sheet/append.py</p><p>When setting cronjobs, it is important that you use the absolute directory of any file you will be using or referencing.</p><p><strong>Loading the Data into Google Data Studio</strong></p><p>Google Data Studio is a free data visualization tool that allows users to connect to various data sources, such as Google Sheets, Google Analytics, and BigQuery, and create interactive reports and dashboards. It has a wide range of features that allows users to easily create and customize charts, tables, and other visualizations. It also allows us to easily share the reports with others, and collaborate on the design and data. Additionally, Google Data Studio is fully integrated with the Google ecosystem and can be easily connected with other Google tools such as Google Analytics, Google BigQuery, and Google Ads. It’s a powerful tool that allows businesses to turn raw data into actionable insights and make data-driven decisions. It’s also a great tool for creating custom reports for clients or stakeholders.</p><ol><li>Open Google Data Studio and create a new report.</li><li>Click on the “Add a data source” button on the top right corner of the screen.</li><li>Select the “Google Sheets” option from the list of data sources.</li><li>Select the Google Sheet that contains the data you want to use in your report.</li><li>Click on the “Connect” button to connect the data source to the report.</li><li>Drag and drop the fields from the data source onto the report to create charts and tables.</li></ol><p>You can now use the data in your Google Sheets to create charts and tables in Google Data Studio, and share the report with others if you need to. In another medium article, I will delve deeply into creating dashboards in Google Data Studio.</p><p>That’s the end of the first project in this Building Data Projects On Google Cloud. Here is a brief summary of everything we did.</p><ul><li>We set up a service account and assigned it with appropriate permissions.</li><li>We scraped data from yahoo finance using selenium and beautiful soup and applied a little bit of transformation.</li><li>We authenticated our application to connect to Google Sheets using the service account key.</li><li>We set up a cronjob to allow us to scrape and batch the data to our Google Sheets on an hourly basis.</li><li>We set an error management and logging process to allow us to receive emails if the pipeline script breaks.</li><li>Lastly, we connected the Google Sheet to the Google Data Studio (Looker Studio) for data visualization.</li></ul><p>I hope you enjoyed this project and were able to follow along. Check out the git repository for more information.</p><p><a href="https://github.com/paulonye/Smart_Sheet">https://github.com/paulonye/Smart_Sheet</a></p><p>The next project is going to be more exciting as we delve into the world of containers and deployments. Stay tuned for further updates.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85e2a6cfd94d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimizing Google’s Cloud Infrastructure for Data Engineering and Analytics]]></title>
            <link>https://medium.com/@nwosupaul141/optimizing-googles-cloud-infrastructure-for-data-engineering-and-analytics-49d1d91fe7b6?source=rss-1d15f1032400------2</link>
            <guid isPermaLink="false">https://medium.com/p/49d1d91fe7b6</guid>
            <dc:creator><![CDATA[Paul Nwosu]]></dc:creator>
            <pubDate>Fri, 13 Jan 2023 09:31:42 GMT</pubDate>
            <atom:updated>2023-01-13T09:31:42.818Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DssdzNf9rUP_DOCNh1ukYg.jpeg" /><figcaption>Source: Freepik</figcaption></figure><p>In this article, as part of a series titled “Building your First Google Cloud Analytics Project”, I aim to guide data analysts and engineers in establishing a foundational understanding of utilizing cloud technology through the configuration of a Google Cloud Compute Engine Instance for data-related projects. The objective of this installment is to provide a comprehensive introduction to the Google Cloud Compute Engine and prepare readers for the subsequent projects to be covered in the series.</p><h4><strong>Prerequisite</strong></h4><ul><li>A Working Visa/Mastercard to set up your billing account</li><li>Vscode on your local machine</li><li>Access to the free 300 credits provided by Google Cloud</li><li>Google Cloud SDK on your Local Machine</li><li>Basic knowledge of Bash</li></ul><p><strong>Why Cloud Computing?</strong></p><p>As technology advancements continue to evolve, so do the requirements for computing and storage resources. The traditional limitations of personal and on-premise servers may no longer suffice for the demands of certain projects. Cloud technology presents a solution for this by providing scalable and easily accessible computing and storage resources. In this series, we will explore utilizing Google Cloud services to set up a project. This installment will not focus on the benefits of using cloud technology or Google Cloud specifically, but rather on the steps to set up your first project utilizing the platform.</p><p><strong>Creating a Project on Google Cloud</strong></p><p>In other to access Google Cloud resources, you have to set up a project. A project allows you to group all your resources together; this is useful for billing purposes, and also allows you to control who has access to what. Resources are the services you use on the Google Cloud platform. These resources can be grouped into three services.</p><ul><li>Infrastructure as a Service (IaaS): This is a type of cloud computing service that provides users with access to a virtualized computing infrastructure, including servers, storage, and networking resources. Users can deploy and run their own applications and operating systems on the infrastructure and are responsible for managing and maintaining the underlying infrastructure. An Example is Google Compute Engine.</li><li>Platform as a Service (PaaS): This is a type of cloud computing service that provides users with a platform for developing, testing, and deploying applications. The provider manages the underlying infrastructure, including servers, storage, and networking resources, and users are only responsible for developing and managing their applications. Examples include App Engine, Google Kubernetes Engine, and Cloud SQL.</li><li>Software as a Service (SaaS): This is a type of cloud computing service that provides users with access to a software application or suite of applications. The provider manages the underlying infrastructure, including servers, storage, and networking resources, and users access the software over the internet. An Example is Google Workspace.</li></ul><p>There is a fourth one that should be mentioned:</p><ul><li>Serverless: This is a type of cloud computing that allows users to run code without having to worry about the underlying infrastructure. Instead of running code on dedicated servers, users can run code in response to events or triggers, and the provider automatically allocates the necessary resources to execute the code. Examples include Bigquery, Cloud Run, Cloud Functions, and Cloud Scheduler.</li></ul><p>The main difference between these types of cloud computing services is the level of control and responsibility that users have over the underlying infrastructure and applications. IaaS gives users the most control, while PaaS provide more abstraction and relieve users of the responsibility of managing the underlying infrastructure. Serverless computing takes this one step further by automatically allocating resources to execute code as needed.</p><p><strong>A step-by-step guide to creating a Google Cloud Project</strong></p><p>Go to <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a> and log in with your Google account</p><p>You will need to set up billing in other to activate your free 300 credits. It is paramount that you activate these free credits because of the tasks we would be running.</p><p>On the upper left corner, click on the dropdown and create a new project, you can call this project anything you like, then take note of the project id, this is usually created automatically, and only be edited once upon creation.</p><p>Once you have set up the project, ensure that you select the project you just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xbV3qqXETQEhyU8iNQ4wew.png" /><figcaption>Selecting the Project you just Created</figcaption></figure><p>Now that you have created a project, we will go ahead and create a Virtual Machine using Google Compute Engine:</p><p><strong>Google Compute Engine</strong></p><p>In the previous discussion, we highlighted that IaaS, PaaS, SaaS, and Serverless differ in the level of control they offer to users. Among the services offered by Google Cloud, Compute Engine falls under the category of IaaS (Infrastructure as a Service). This allows users to run both public images provided by Google for Linux and Windows Server, as well as private custom images that can be created or imported from existing systems. This feature enables the creation of virtual computers on Google’s network. Each virtual machine is configured using a virtual private cloud, ensuring that the resources on the virtual machine are not publicly accessible.</p><p><strong>A step-by-step guide to creating a Compute Engine instance</strong></p><p>Open the Navigation menu, click on Compute Engine, and then Click on Create an Instance.</p><p>Set the following configurations as seen in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*357_1Gt9ueITmZZ5NojZLQ.png" /><figcaption>Creating a VM using Google Compute Engine</figcaption></figure><p>For the Boot disk configuration, click on change and make the ff adjustments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*25vNVI3Mqib8-Chuh49FKQ.png" /><figcaption>Setting the Boot Disk Configuration</figcaption></figure><p>Allow HTTP and HTTPS Traffic (Not really important for our projects though) and then click on CREATE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*baQFOfzhtpZwhqYyeIqV3Q.png" /><figcaption>Finalizing the Set up of the Virtual Machine</figcaption></figure><p>It will take a couple of minutes to set up, once this is done we need to SSH into the virtual machine (remote instance).</p><p><strong>What is SSH, and How to Set up a Direct Connection from your Local Machine to the Remote Instance</strong></p><p>SSH, also known as Secure Shell is a way to access a computer (in this case, the remote instance) over an unsecured network.</p><p>Before you proceed, please ensure that you have installed google cloud SDK on your local machine and that gcloud commands work on your terminal. If you have not, follow this link: <a href="https://cloud.google.com/sdk/docs/install-sdk">https://cloud.google.com/sdk/docs/install-sdk</a> to help you get started.</p><p>On the VM instances page, you will see a list of the virtual machines that you have created, click on the dropdown next to SSH on the <strong>Connect Column</strong>, and select the <strong><em>view gcloud command</em></strong>. Copy the command and go to the terminal of your local machine and paste it. Also, take note of the external Ip address of the virtual machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjUbgMeoo9IXt0yBOo_bTQ.png" /><figcaption>Logging into the Virtual Machine (Remote Instance)</figcaption></figure><p>When logging into a remote instance from your local machine for the first time, the above command creates two SSH keys, a private key, and a public key. It uses the local user to configure access and stores them in the .ssh directory of your home directory. It is unclear whether the keys are automatically stored in the .ssh directory for Windows users, but it is confirmed for Mac and Linux users. This public key will be used for any future SSH connections with that user.</p><p>From your home directory, move into the .ssh directory;</p><pre>cd ~/.ssh</pre><p>You should see two files named google_compute_engine and google_compute_engine.pub. The former is the private key, the latter is the public key.</p><p>Create and open a config file in the .ssh folder:</p><pre>touch config<br><br>nano config</pre><p>Copy and paste the ff commands on the config file:</p><pre>Host “alias_name” (Pick anything that&#39;s easy to remember)<br>    HostName “external_ip_address_of_instance” (This will if you restart the instance)<br>    User “name of user” (This is usually the name of your pc)<br>    IdentifyFile ~/.ssh/private_key_name (This should be the absolute path of the ssh key)</pre><p>Here is what your config file should look like:</p><pre>Host gcp_instance<br>    HostName 23.354.76.134<br>    User macbook<br>    IdentifyFile ~/.ssh/google_compute_engine</pre><p>The external IP address of a virtual machine is subject to change, such as upon manual upgrade or when the instance is shut down and restarted. This is similar to how a local machine’s external IP address changes when it is shut down or restarted. It is possible to set the IP address to be static, but that is outside the scope of this guide.</p><p>Now, log into your instance from any directory on the command line using:</p><pre>ssh gcp_instance</pre><p>We have successfully logged into our remote instance, now to set it up for our data-related projects</p><p><strong>Installation of Anaconda, Docker, Google Chrome, and Chrome Driver on our Remote Instance</strong></p><p><strong><em>Anaconda Installation</em></strong></p><p>Before installing any components, you are required to update the package index. On the terminal of your remote machine, type in the command:</p><pre>sudo apt update<br>sudo apt upgrade</pre><p>To install Anaconda go to the anaconda’s download page, look for the Linux version, and then copy the link address. On the terminal of the instance, you can then use wget ‘link address’to download anaconda just as seen in the command below. The installation of anaconda would automatically lead to the installation of python 3 as well as jupyter notebook.</p><p>Note: You can always install python 3 as a standalone application.</p><pre> wget https://repo.anaconda.com/archive/Anaconda3-2022.10-Linux-x86_64.sh</pre><p>The above command installs anaconda on the virtual machine; the ff command is then used to install it:</p><pre> bash Anaconda3-2022.10-Linux-x86_64.sh</pre><p>After the installation, you will be asked if you want the installer to initialize Anaconda3, type yes. You might need to restart the instance before. To test that anaconda was installed properly use conda --version</p><p>You can then try running jupyter notebook using the command jupyter notebookand python using the command python3</p><p><strong><em>Google Chrome and Chrome Driver Installation</em></strong></p><p>Most of the projects we are going to be doing will involve web scraping, and for that, we need certain tools such as Selenium. Selenium WebDriver is a tool used for automating web interactions and testing.</p><p>With Selenium, automated actions such as click hovers, and form fills can be performed on browsers by directly interacting with them. It supports multiple programming languages including Java, C#, PHP, Python, Perl, Go, and Ruby.</p><p>To use Selenium, one needs to choose from a variety of browser options such as Firefox, Chrome (Chromium), Edge, and Safari.</p><p>For our projects, we would be working with Chrome [with the headless option] (which does not display the user interface) because we are working on a remote instance, and it’s only the terminal we have access to.</p><p>I will not delve extensively into the technical details, but rather provide a concise list of the necessary commands to install Chrome and the driver on your remote instance. For more information, refer to the ff blog posts:</p><ul><li><a href="https://www.keeganleary.com/setting-up-chrome-and-selenium-with-python-on-a-virtual-private-server-digital-ocean/">Setting up Chrome and Selenium with Python on a Virtual Private Server (Digital Ocean)</a></li><li><a href="https://nander.cc/using-selenium-within-a-docker-container">Using Selenium With Python in a Docker Container</a></li></ul><p>The following commands are used to set up Google Chrome</p><pre># Adding trusting keys to apt for repositories<br>wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -<br><br># Adding Google Chrome to the repositories<br>sudo sh -c &#39;echo &quot;deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main&quot; &gt;&gt; /etc/apt/sources.list.d/google-chrome.list&#39;<br><br># Updating apt to see and install Google Chrome<br>sudo apt-get -y update<br><br># Install Chrome<br>sudo apt-get install -y google-chrome-stable<br><br># Check that the google chrome was installed correctly<br>google-chrome --version</pre><p>We then need to install the chrome driver</p><pre># Installing Unzip<br>sudo apt-get install -yqq unzip<br><br># Download the Chrome Driver<br>wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`<br>curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE<br>`/chromedriver_linux64.zip<br><br># Unzip the Chrome Driver into /usr/local/bin directory<br>sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/<br><br># Set display port as an environment variable<br>export DISPLAY=:99<br><br># Check that the chrome driver works<br>chromedriver --url-base=/wd/hub</pre><p><strong><em>Installation of Docker</em></strong></p><p>Docker will help us package our application and all its dependencies into a container which we can then deploy. To install docker use</p><pre>sudo apt-get install docker.io</pre><p>Check the version you installed using docker --version</p><p>In other to ensure that docker runs without sudo; check the <a href="https://github.com/sindresorhus/guides/blob/main/docker-without-sudo.md">link</a></p><p>Now try; docker run hello-world In this case; hello-world is a docker image. In the case you don’t have the docker image locally, docker pulls the image from the docker registry and builds the container on your local machine before running it.</p><p>Given that we have completed the majority of our setup, we could choose to conclude here. However, in order to enhance the development of our application, we can take an additional step and connect our remote instance to Visual Studio Code (VSCode). This will facilitate a more efficient development process. Vscode has an extension “Remote - SSH”, a tool that allows users to log into their remote instance from vscode.</p><p><strong>A step-by-step guide on how to connect Visual Studio Code to a remote instance</strong></p><p>From the extensions tab on vscode, search for Remote SSH, download and allow it to install its dependencies on vscode</p><p>To get started with it, look for &gt;&lt;at the lower left portion of the VScode GUI and click on it, select Connect to Host. This will list out the alias name you set up for your remote instances in the config file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olxyDr6icP7Akg5Fe5e5Iw.png" /><figcaption>Installing the Remote SSH extension on vscode</figcaption></figure><p>Select the one you want to connect to. As you can see from the image above, I have a couple of instances I can connect to. You can set up every remote instance connection from one config file located in the .ssh folder on your home directory.</p><p>With this, we are good to go, and now we can connect to our remote machine from vscode. This setup brings many benefits, one of which is what we call port forwarding.</p><p>If you have started using a remote instance actively, you might wonder how to use apps that need a Graphical User Interface like Jupyter Notebook. With port forwarding, we can connect these apps running on our remote machine to our local machine. We can use VSCode to do this. Let’s see an example to understand it better.</p><p>First of all, I will log into my remote instance from the terminal of my mac and run jupyter notebook by typing jupyter notebook</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YMQyUhoiIzTqn3LD39iPew.png" /><figcaption>Launching Jupyter Notebook</figcaption></figure><p>As seen from the image, I am provided with a link: <a href="http://localhost:8888/?token=6e873595950e652f43f941940039854223c92b9cbf8e71df">http://localhost:8888/?token=6e873595950e652f43f941940039854223c92b9cbf8e71df</a>. Copy the link provided from the terminal of your remote machine.</p><p>Open your vscode and connect to the remote instance (Yes, you can have multiple sessions of your instance running at once). Go to the port session and click on Forward a Port. Type in 8888, as this is the port jupyter notebook runs on (In other projects, we will cover this in more detail). This creates a local address.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPWNXtUJ-4Scu6EAMW3X1g.png" /><figcaption>Port forwarding on vscode</figcaption></figure><p>Before pasting the link for the Jupyter notebook in a browser, ensure that the port number specified in the Jupyter notebook link is the same as the one generated on the local address link. This will ensure that the connection is established correctly and the notebook can be accessed on the browser.</p><p>In the above case, both ports are the same because there is no application running on port 8888 on your local machine. However, if your Jupyter notebook is already running on your local machine, the local address link will generate a different port number. In this case, ensure to change the 8888 in the Jupyter notebook link to the number generated on your local machine. This is to avoid any conflicts with the already running notebook on your local machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AvWBTdPUCb5pCqyydtzzcg.png" /><figcaption>Jupyter notebook on the remote instance</figcaption></figure><p><strong>SUMMARY</strong></p><p>And that’s it, we have successfully been able to connect the jupyter notebook running on our remote instance to our local machine.</p><p>Wow, we have done a lot in just one article. Here is a summary:</p><ul><li>Set up and Connect to a Google Compute Engine Instance</li><li>Set up a Configuration file for direct SSH access</li><li>Installation of Anaconda, Chrome, Chrome Driver, and Docker</li><li>Set up of Remote SSH connection from vscode</li><li>Accessing Remote Applications from our Local Machine</li></ul><p>Before we conclude this article, it is important to note the ability to create an image of an instance in Google Cloud. This feature is significant as it allows for the preservation of the current environment, in the event that the instance needs to be shut down or deleted for cost-savings purposes. In a subsequent article, I will demonstrate the steps for creating an image of an instance. Overall, this feature is an essential aspect to keep in mind when working with Google Cloud as it enables efficiency and flexibility in managing instances and costs.</p><p>I trust that this article will serve as a valuable resource for individuals seeking to begin their journey with Google Cloud. There are a plethora of exciting capabilities and features to explore within the platform. However, it is important to exercise caution when experimenting with these features, as costs can quickly accumulate. Nonetheless, with the proper guidance and understanding, Google Cloud can be a powerful tool for any organization or individual. With that said, this article marks the end of our journey, I hope it was informative and you are now ready to embark on your own adventure with Google Cloud.</p><p>Next Post: Building an ETL pipeline leveraging Google Service Accounts</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=49d1d91fe7b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>