Estuary

Connect Redshift to Google Sheets for Dynamic Reporting

Unlock real-time insights with Amazon Redshift and Google Sheets integration. Streamline workflows and make informed decisions. Dive into our step-by-step guide today!

Connect Redshift to Google Sheets for Dynamic Reporting
Share this article

Gone are the days of static reports and disconnected insights. In today's data-driven world, staying ahead of the curve requires dynamic reporting that empowers you to make informed decisions in real-time. When it comes to data management, Amazon Redshift and Google Sheets are two powerful and widely used tools. Amazon Redshift is a high-performance data warehousing solution with scalable storage capacity, while Google Sheets is a cloud-based spreadsheet tool that simplifies data organization and analysis.

Integrating these tools offers a dynamic solution for real-time insights and streamlining workflows. Whether you're a data analyst or a business professional looking to leverage data effectively, this step-by-step guide will walk you through the process to help you unlock the full potential of your data. Let's dive in!

Redshift Overview

redshift to google sheets-redshift

Image Source

Amazon Redshift is a fully-managed and cloud-based data warehousing solution by Amazon Web Services (AWS). It is designed to handle vast volumes of structured and unstructured data with exceptional efficiency, making it capable of effortlessly processing exabytes (1018 bytes) of data. Moreover, Redshift prioritizes data security by offering high levels of encryption, safeguarding sensitive information against potential threats.

Here are some of the key features of Redshift:

  • Massive Parallel Processing (MPP): Redshift breaks down large data jobs into smaller tasks and distributes them across multiple processors. This approach ensures that massive processing tasks are completed quickly and efficiently.
  • Column-Oriented Databases: Redshift organizes data into columns; it can efficiently access and retrieve specific columns needed for a query, resulting in faster query performance than row-oriented databases. This feature makes Redshift well-suited for handling large-scale analytics and data warehousing workloads.
  • Fault Tolerance: Redshift is designed to ensure the availability of your data, even in the event of system failures. It constantly monitors the clusters, and in case of any issues with drives, nodes, or clusters, it automatically replicates and transfers the data to operational nodes.

Google Sheets Overview

redshift to google sheets-google sheets

Image Source

Google Sheets is a popular cloud-based spreadsheet application developed by Google. It offers a collaborative platform for data management, analysis, and visualization. You can create, edit, and organize spreadsheets online, simultaneously allowing real-time collaboration with multiple users.

Google Sheets supports various functions, formulas, and formatting options, making it suitable for budgeting, data analysis, project management, and more. Whether for personal use or professional projects, Google Sheets empowers you with a versatile and accessible spreadsheet solution.

Some of its key features include:

  • Collaborative Editing: Google Sheets excels in fostering teamwork as multiple users can simultaneously edit a spreadsheet in real-time. This enables seamless collaboration, eliminating sharing files back and forth.
  • Offline Editing: Google Sheets supports offline editing on desktop and mobile apps, allowing you to work on spreadsheets without an internet connection. Changes made offline are automatically synchronized once a connection is restored, ensuring a seamless workflow.
  • Supported File Formats: Google Sheets offers extensive support for spreadsheet file formats, including .xlsx, .xls, .ods, .csv, and .tsv. This flexibility enables easy import and export of data in different formats, catering to diverse business needs.

Methods to Connect Redshift to Google Sheets

There are several methods available for transferring data from Redshift to Google Sheets. In this guide, we'll explore two popular methods to connect Redshift to Google Sheets:

  • Method 1: Connecting Redshift to Google Sheets using Python Scripts
  • Method 2: No-Code SaaS Alternatives Like Estuary

Method 1: Connecting Redshift to Google Sheets using Python Scripts

Here's how you can extract data from Amazon Redshift and push it to a Google Spreadsheet using Python Scripts:

Step 1: Create a Project

  • Sign into your Google Cloud Platform account. 
  • Click on Select a project at the top of the page and then click on New Project
  • Give your project a name, and click the Create button to create the project.

Step 2: Enable Google Drive API and Google Sheets API

  • Select your newly created project from the Select a project dropdown at the top. 
  • Click on + ENABLE APIS AND SERVICES to enable the APIs for your project.
  • In the Search box, type Google Drive API and click the ENABLE button to enable the Google Drive API for your project. Repeat the same process for the Google Sheets API and enable it as well.
redshift to google sheets-python step2

Image Source

Step 3: Create Credentials

  • To create credentials for accessing Google Drive and Google Sheets APIs, click on Create credentials from the dashboard, select Google Drive API as the API being used, Application data as the location, and specify Other non-UI for the type of data being accessed, then proceed with the credential creation process.
redshift to google sheets - python step 3

Image Source

Step 4: Create Service Account Key

  • Enter a Service Account Name, and choose a Role. Click on the Continue button. Click on Create key to generate a new key for your service account. Choose the key type as JSON and click on the Create button.
  • A JSON file containing the credentials for your service account will be downloaded. Rename this file as client_secretkey.json.
redshift to google sheets-python step 4

Image Source

Step 5: Share Google Sheets with Service Account

  • Go to your Google Drive and create a new Google Sheet. Name the spreadsheet Redshift-to-Google-Sheet or any other suitable name.
  • Open the client_secretkey.json file and copy the value of the client_email field. Share the Google Sheet with this client_email with edit permissions so the service account can write data to it.

Step 6: Install Required Libraries

  • At this point, you have set up the necessary credentials and shared the Google Sheet with the service account. Now you can write your Python script to extract data from Amazon Redshift and push it to Google Sheets.
  • Open the terminal and run the following commands to install the necessary Python libraries:
python
pip install gspread pip install oauth2client pip install sqlalchemy pip install df2gspread

Step 7: Create Python Script

  • Create a new Python file and name it redshift_to_spreadsheet.py. Copy and paste the following code into the script:
python
import gspread from oauth2client.service_account import ServiceAccountCredentials import pandas as pd from sqlalchemy import create_engine from df2gspread import df2gspread as d2g # Set the scope for Google Sheets API scope = ["https://spreadsheets.google.com/feeds", 'https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/drive"] # Upload the DataFrame to the specified Google Spreadsheet def write_googlesheet(df, spreadsheet_key, sheet_title, starting_cell, overwrite): d2g.upload(df, spreadsheet_key, sheet_title, credentials=credentials, col_names=overwrite, row_names=True, start_cell = starting_cell, clean=overwrite) if __name__ == "__main__": # Connecting to the Amazon Redshift database engine = create_engine('postgresql://user:password@host:5439/database') data_frame = pd.read_sql('SELECT * FROM article_sales;', engine) print(data_frame) credentials = ServiceAccountCredentials.from_json_keyfile_name('client_secretkey.json', scope) client = gspread.authorize(credentials)            write_googlesheet(data_frame, 'SPREADSHEET_KEY', 'Sheet1', 'A1', True)
  • Replace the details such as client_secretkey.jsonuser:password@host:5439/databaseSELECT * FROM article_sales, and SPREADSHEET_KEY with your respective actual values for service account credentials, Amazon Redshift database connection, SQL query, and Google Spreadsheet key.

Step 8: Run the Script

  • Run the Python script. Now, Open the Google Sheet you specified with the spreadsheet key. You will see that your Google Sheet is updated with the content fetched from Amazon Redshift.

Limitations of Using Python Scripts 

There are, however, a few downsides to using Python scripts to move data from Redshift to Google Sheets: 

  • Technical expertise: This method requires technical expertise in Python programming, making it challenging for non-technical users to implement and maintain the script due to complexities in understanding Python concepts, libraries, APIs, and managing dependencies.
  • Real-Time Updates: This method does not offer real-time updates to the Google Sheet, meaning that the data in the Google Sheet will not automatically reflect changes made in the Redshift database after the initial run of the script. Nevertheless, you can set up real-time updates but that would require more technical expertise. 
  • Maintenance and Error Handling: The script may require additional error handling and maintenance, as any changes in the database schema or API behavior could lead to errors or inconsistencies in the data extraction process, requiring periodic updates and monitoring.

Method 2: No-Code SaaS Alternatives Like Estuary

Are you looking for an efficient way to load Redshift data into Google Sheets without scripts? Consider using SaaS tools like Estuary Flow. 

Flow is a powerful real-time data integration platform that connects various data sources to destinations including Redshift and Google Sheets. It offers an all-in-one solution to extract, transform and load your data.

Benefits of Using Estuary Flow:

  • Easy-to-Use Interface: Estuary Flow offers a user-friendly interface to easily set up data transfer configurations. With Flow, creating a data pipeline is simple and straightforward.
  • Real-Time Data Streaming: Flow data pipelines facilitate real-time data synchronization, ensuring that any changes occurring in Redshift are immediately reflected in Google Sheets.
  • Scalability: Estuary Flow handles large data volumes, supporting active workloads up to 7GB/s change data capture (CDC) from databases of any size.
  • Accessibility: Flow ensures data is in a format compatible with destinations by performing data quality checks, schema validation, and transformations.
  • Data Transformation: Estuary Flow stands out for its robust data integration capabilities, allowing for real-time data modifications and processing using streaming SQL and JavaScript transformations.

Let's delve into the step-by-step process in detail.

Prerequisite: Set up Redshift to connect with Flow. Learn how here.

Step 1: Capture the Data From Your Source

  • Sign in to your Estuary account. You can sign up for free if you don't have an account. After logging in, click on the Sources option in the Estuary dashboard. In the Sources window, Click on + New Capture.
  • On the Captures page, search for Redshift and click on Capture.
  • Give the Capture a name and proceed to fill in the details of your source database, including Host, DatabaseUsername, and Password.
redshift to google sheets-estuary step
  • Once you have filled in all the required details, click on Next. Estuary Flow will initiate a connection with your Redshift account and identify data tables.
  • Click on Save and Publish to finalize the data capture process.

Step 2: Set up Your Data Destination

  • Navigate to the Estuary dashboard and click on Destinations in the left-side pane. Click on New Materialization. On the Materialization page, search for Google Sheets and click on Materialization.
  • Provide the Materialization name and Endpoint config details, such as the Google Sheets spreadsheet URL and collection name. Click on Next to proceed.
redshift to google sheets-estuary materialization
  • The data collections you previously captured from Redshift may already be populated in your Flow collections. If not, use the Source Collections feature to locate and add the collections you intend to use.
  • Finally, click on Save and Publish. Estuary Flow will now continuously replicate your Redshift data to Google Sheets in real-time, ensuring that your data warehouse is always up-to-date.
  • Check out the Estuary documentation for:

Conclusion

Amazon Redshift to Google Sheets migration for dynamic reporting offers a powerful solution to gain real-time insights and streamline data workflows. This guide explores two popular methods for connecting Redshift to Google Sheets. The first method involves using Python scripts to extract data from Redshift and push it to a Google Spreadsheet. While this approach can be effective, it has a few limitations, such as handling large data volumes and requiring technical expertise for maintenance and error handling.

An alternative solution is leveraging SaaS platforms like Estuary Flow. Estuary provides a user-friendly interface for setting up data pipelines, enabling real-time data synchronization

Start streaming your data for free

Build a Pipeline
Share this article

Table of Contents

Build a Pipeline

Start streaming your data for free

Build a Pipeline

About the author

Picture of Jeffrey Richman
Jeffrey Richman

With over 15 years in data engineering, a seasoned expert in driving growth for early-stage data companies, focusing on strategies that attract customers and users. Extensive writing provides insights to help companies scale efficiently and effectively in an evolving data landscape.

Popular Articles

Streaming Pipelines.
Simple to Deploy.
Simply Priced.
$0.50/GB of data moved + $.14/connector/hour;
50% less than competing ETL/ELT solutions;
<100ms latency on streaming sinks/sources.