Businesses are increasingly harnessing data to improve their business outcomes. To enable this transformation to a data-driven business, customers are bringing together data from structured and unstructured sources into a data lake. Then they use business intelligence (BI) tools, such as Amazon QuickSight, to unlock insights from this data.
To provide fast access to datasets, QuickSight provides a fully managed calculation engine called SPICE—the Super-fast, Parallel, In-Memory Calculation Engine. At the time of writing, SPICE enables you to cache up to 250 million rows or 500 GB of data per dataset.
To extract value from the data quickly, you need access to new data as soon as it’s available. In this post, we describe how to achieve this by refreshing SPICE datasets as part of your extract, transform, and load (ETL) pipelines.
In this post, you automate the refresh of SPICE datasets by implementing the following architecture.
This architecture consists of two parts: an example ETL job and a decoupled event-driven process to refresh SPICE.
For the ETL job, you use Amazon Simple Storage Service (Amazon S3) as your primary data store. Data lands in an S3 bucket, which we refer to as the raw zone. An Amazon S3 trigger configured on this bucket triggers an AWS Lambda function, which starts an AWS Glue ETL job. This job processes the raw data and outputs processed data into another S3 bucket, which we refer to as the processed zone.
This sample ETL job converts the data to Apache Parquet format and stores it in the processed S3 bucket. You can modify the ETL job to achieve other objectives, like more granular partitioning, compression, or enriching of the data. The Glue Data Catalog stores the metadata and QuickSight datasets are created using Amazon Athena data sources.
To trigger the SPICE dataset refresh, after the ETL job finishes, an Amazon EventBridge rule triggers a Lambda function that initiates the refresh.
In summary, this pipeline transforms your data and updates QuickSight SPICE datasets upon completion.
Deploying the automated data pipeline using AWS CloudFormation
Before deploying the AWS CloudFormation template, make sure you have signed up for QuickSight in one of the 11 supported Regions:
- US East (Ohio)
- US East (N. Virginia)
- US West (Oregon)
- Asia Pacific (Mumbai)
- Asia Pacific (Seoul)
- Asia Pacific (Singapore)
- Asia Pacific (Sydney)
- Asia Pacific (Tokyo)
- EU (Frankfurt)
- EU (Ireland)
- EU (London)
This post works with both Standard and Enterprise editions of QuickSight. Enterprise Edition provides richer features and higher limits compared to Standard Edition.
- After you sign up for QuickSight, you can use CloudFormation templates to create all the necessary resources by choosing Launch stack:
- Enter a stack name; for example,
- Acknowledge the AWS Identity and Access Management (IAM) resource creation.
- Choose Create stack.
The CloudFormation template creates the following resources in your AWS account:
- Three S3 buckets to store the following:
- AWS Glue ETL job script
- Raw data
- Processed data
- Three Lambda functions to do the following:
- Create the ETL job
- Initiate the ETL job upon upload of new data in the raw zone
- Initiate the SPICE dataset refresh when the ETL job is complete
- An AWS Glue database
- Two AWS Glue tables to store the following:
- Raw data
- Processed data
- An ETL job to convert the raw data from CSV into Apache Parquet format
- Four IAM roles: One each for the Lambda functions and one for the ETL job
- An EventBridge rule that triggers on an AWS Glue job state change event with a state of
Succeededand invokes a Lambda function that performs the SPICE dataset refresh
Importing the dataset
For this post, you use the taxi Trip Record Data dataset publicly available from the NYC Taxi & Limousine Commission Trip Record Data dataset. You upload monthly data in CSV format to the raw zone S3 bucket.
This data is available in Amazon S3 through Open Data on AWS, a service designed to let you spend more time on data analysis rather than data acquisition.
You start by copying the For Hire Vehicle (FHV) data for March 2020. Because the data is already available in Amazon S3 through Open Data, run the following command to copy the data into the raw zone. Make sure you replace <raw bucket name> with the name of the raw bucket created by the CloudFormation template:
After you copy the data into the raw zone, the Amazon S3 event trigger invokes the Lambda function that triggers the ETL job. You can see the job status on the AWS Glue console by choosing Jobs in the navigation pane. The process takes about 2 minutes.
When the job is complete, check that you can see the Parquet files in the processed zone S3 bucket.
Creating a QuickSight analysis of the data
To visualize the taxi data, we create a QuickSight analysis.
First, you need to give QuickSight the necessary permissions to access the processed zone S3 bucket. For instructions, see I Can’t Connect to Amazon S3.
Then complete the following steps to create an analysis of the taxi data:
- On the QuickSight console, choose Datasets.
- Choose New dataset.
- Choose Athena and provide a name for the data source (such as Athena).
- Choose Create data source.
- For Database, choose the name of the taxi AWS Glue database (starting with
- For Tables, select processed_taxi_data as the table to visualize.
- Choose Select.
- Ensure Import to SPICE for quicker analytics is selected and choose Visualize.
After the data is imported into SPICE, you can create visuals to display the data. For example, the following screenshot shows a key performance indicator (KPI) of the number of taxi journeys aggregated at the month level and the number of journeys over time.
We use this dashboard to visualize the dataset again after we refresh SPICE with more data.
Automating the SPICE refresh
To refresh the SPICE dataset when the ETL job is complete, the CloudFormation template we deployed created an EventBridge rule that triggers a Lambda function each time an AWS Glue ETL job successfully completes. The following screenshot shows the code for the event pattern.
We need to configure the Lambda function with the ETL job name and the ID of the SPICE dataset we created in QuickSight.
- Locate the ETL job name on the AWS Glue console, named
- To find the SPICE dataset ID, run the following command using the AWS Command Line Interface (AWS CLI):
The following screenshot shows the output with the dataset ID.
- On the Lambda console, open the Lambda function named
- Update line 9 of the code to replace
ReplaceWithGlueJobNamewith the AWS Glue job name and
ReplaceWithYourDatasetIDwith the dataset ID.
Once a Glue job succeeds, this Lambda function is triggered. The EventBridge event that triggers the Lambda contains the name of the job. You can access this from the event as follows, as seen on line 25 of the function:
The Lambda function looks up the job name in the
data_set_map dictionary. If the dictionary contains the job name, the dataset ID is accessed and the function calls the QuickSight Create Ingestion API to refresh the SPICE datasets.
You can extend the
data_set_map dictionary to include additional job names and associated SPICE dataset IDs to be refreshed. If using this approach at scale, you might choose to move this configuration information to an Amazon DynamoDB table.
- Save the Lambda function by choosing Deploy.
Testing the automated refresh
Now that you have configured the Lambda function, we can test the ETL end-to-end process and make the next month’s data available for analysis.
To add the FHV data for April, run the following AWS CLI command:
As before, this upload to the raw zone triggers the Lambda function that starts the ETL job. You can to see the progress of the job on the AWS Glue console.
When the job is complete, navigate to QuickSight and open the taxi analysis (or, if you still have it open, refresh the window).
You can now see that both months’ data is available for analysis. This step might take 1–2 minutes to load.
To see the status of each SPICE refresh, navigate back to the dataset on the QuickSight console and choose View History.
The following screenshot shows the status of previous refreshes and the number of rows that have been ingested into SPICE.
Now that you have tested the end-to-end process, you can try copying more FHV data to the raw zone and see the data within your QuickSight analysis.
To clean up the resources you created by following along with this post, complete the following steps:
- Delete the QuickSight analysis you created.
- Delete the QuickSight dataset that you created.
- Delete the QuickSight data source:
- Choose New dataset.
- Select the data source and choose Delete data source.
- On the Amazon S3 console, delete the contents of the raw and processed S3 buckets.
- On the AWS CloudFormation console, select the stack SpiceRefreshBlog and choose Delete.
Using an event-based architecture to automate the refresh of your SPICE datasets makes sure that your business analysts are always viewing the latest available data. This reduction in time to analysis can help your business unlock insights quicker without having to wait for a manual or scheduled process. Additionally, by only refreshing SPICE when new data is available, the underlying data storage resources are used efficiently, so you only pay for what you need!
Get started with QuickSight today!
About the Authors
Rob Craig is a Senior Solutions Architect with AWS. He supports customers in the UK with their cloud journey, providing them with architectural advice and guidance to help them achieve their business outcomes.
Dylan Qu is an AWS solutions architect responsible for providing architectural guidance across the full AWS stack with a focus on Data Analytics, AI/ML and DevOps.