<?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 Mohamed Mokhtar Riahi on Medium]]></title>
        <description><![CDATA[Stories by Mohamed Mokhtar Riahi on Medium]]></description>
        <link>https://medium.com/@mokhtarriahi?source=rss-adfaa1d58835------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*lP5VRy49nMzd6dfnF16tEQ.jpeg</url>
            <title>Stories by Mohamed Mokhtar Riahi on Medium</title>
            <link>https://medium.com/@mokhtarriahi?source=rss-adfaa1d58835------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:17:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mokhtarriahi/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[Automating Amazon QuickSight SPICE Refreshes Using AWS Lambda, Step Functions, and AWS SDK]]></title>
            <link>https://medium.com/datareply/automating-amazon-quicksight-spice-refreshes-using-aws-lambda-step-functions-and-aws-sdk-9aa86c13e972?source=rss-adfaa1d58835------2</link>
            <guid isPermaLink="false">https://medium.com/p/9aa86c13e972</guid>
            <category><![CDATA[amazon-quicksight]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Mohamed Mokhtar Riahi]]></dc:creator>
            <pubDate>Tue, 06 May 2025 08:14:18 GMT</pubDate>
            <atom:updated>2025-05-06T08:14:18.334Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sSLOxUDNDC90HNXN.png" /></figure><p>Amazon QuickSight is a powerful business intelligence service that allows organizations to visualize and analyze their data efficiently. One of its key features is <strong>SPICE (Super-fast, Parallel, In-memory Calculation Engine)</strong>, which enables fast querying by storing datasets in memory. However, refreshing SPICE datasets can be a challenge when working with dynamic data pipelines.</p><p>By default, QuickSight provides scheduled and manual refresh options. But what if we want on-demand, API-driven refreshes that trigger only when new data is available? This is where AWS Lambda, Step Functions, and API calls come into play. In this article, we’ll explore a solution that uses a YAML configuration file to dynamically control QuickSight SPICE refreshes after a data pipeline execution (e.g., dbt models being updated in a nightly run).</p><h3><strong>The Challenge with SPICE Refreshes</strong></h3><p>When working with modern data pipelines, such as those built with dbt, AWS Glue, or Snowflake, new data is not always available at fixed intervals. Triggering a SPICE refresh every time data changes ensures users always see up-to-date insights.</p><p>Challenges include:</p><ul><li>The default QuickSight schedule might refresh datasets unnecessarily, increasing costs.</li><li>Manual refreshes are not scalable for large analytics teams.</li><li>Triggering refreshes programmatically is possible but requires a structured approach.</li></ul><p>To solve this problem, we propose an event-driven SPICE refresh approach using:</p><ul><li>YAML configuration to define datasets dynamically.</li><li>AWS Lambda functions to trigger QuickSight API calls.</li><li>Step Functions to orchestrate the process.</li></ul><h3>Types of Refreshes in QuickSight SPICE</h3><p>When working with Amazon QuickSight SPICE refreshes, there are two main types of refresh methods:</p><p><strong>1- Full Refresh:</strong></p><p>A Full Refresh replaces the entire dataset stored in SPICE with new data. It essentially deletes the previous dataset and reloads everything from the data source. It ensures all data is fresh, preventing inconsistencies. However, it can be resource-intensive if the dataset is large.</p><p>When to Use a Full Refresh:</p><ul><li>If the dataset is small to medium-sized, making a full reload feasible.</li><li>When historical data frequently changes and needs a full update.</li><li>If there is no way to track incremental changes from the data source.</li></ul><p><strong>2- Incremental Refresh:</strong></p><p>An Incremental Refresh updates only the new or changed data while keeping the existing records in SPICE. Instead of replacing the entire dataset, it adds or updates only the necessary parts. It is faster and more efficient than a full refresh for large datasets and reduces data ingestion time and computational overhead. It uses a lookback window to capture updates for a specific period. For that reason, it needs a column (e.g., timestamp) to track new or updated records. Typically, a full refresh is applied on incremental datasets once in a while (weekly, monthly…).</p><p>When to Use an Incremental Refresh:</p><ul><li>When working with large datasets that grow over time (e.g., logs, transactions).</li><li>If only recent changes need to be updated (e.g., last 7 days of data).</li><li>When a timestamp or key column is available to track new data.</li></ul><h3>YAML Configuration for SPICE Refreshes</h3><p>In order to make the SPICE refresh process dynamic and configurable, we use a YAML file to define datasets and their refresh settings. This allows us to easily add, remove, or modify datasets without changing the code.</p><p>By using a YAML configuration, we can:</p><ul><li>Define multiple datasets in one place.</li><li>Specify refresh settings per dataset (full or incremental).</li><li>Control schedules dynamically based on business needs.</li><li>Ensure flexibility when adding new datasets.</li></ul><p>Below is an example YAML configuration file that defines how datasets should be refreshed.</p><pre>qs_cost_details:<br>  account_id: &quot;123456789012&quot;<br>  dataset_id: &quot;01c57dd3-ab62-4c1c-849d-6453a87899aa&quot;<br>  refresh_type: &quot;INCREMENTAL_REFRESH&quot;<br>  refresh_configuration:<br>    column_name: &quot;usage_date&quot;<br>    size_unit: &quot;DAY&quot;<br>    size: 5<br>    full_refresh_schedule: &quot;WEEKLY&quot;<br><br>qs_sales_data:<br>  account_id: &quot;123456789012&quot;<br>  dataset_id: &quot;273f2b95-3a3d-47dd-b552-f9cc134184be&quot;<br>  refresh_type: &quot;FULL_REFRESH&quot;<br>  refresh_schedule: &quot;DAILY&quot;</pre><p><em>Figure 1: YAML configuration file for Ingestion refreshes.</em></p><h3>Detailed Explanation of YAML Parameters</h3><p>For each dataset, we have specific parameters:</p><ul><li><strong><em>account_id:</em></strong> AWS Account ID where QuickSight is running.</li><li><strong><em>dataset_id:</em></strong> Unique identifier for the dataset in QuickSight.</li><li><strong><em>refresh_type:</em></strong> Type of refresh: “FULL_REFRESH” or “INCREMENTAL_REFRESH”.</li><li><strong><em>refresh_schedule:</em></strong> Defines how often a full refresh should occur (e.g., “DAILY”, “WEEKLY”).</li><li><strong><em>refresh_configuration: </em></strong>Only for Incremental Refresh. Contains detailed settings for updating data selectively.</li></ul><p>The incremental refresh configuration need the following parameters:</p><ul><li><strong><em>column_name:</em></strong> The timestamp or key column used to track new records.</li><li><strong><em>size_unit:</em></strong> Defines the time unit (DAY, HOUR, etc.).</li><li><strong><em>size:</em></strong> Defines how many units (e.g., last 5 days) to update.</li><li><strong><em>full_refresh_schedule: </em></strong>Specifies how often to perform a full refresh (e.g., “WEEKLY”).</li></ul><h3>Why Use a YAML Configuration?</h3><ul><li><strong>Easy to modify:</strong> No need to change Python code when adding new datasets.</li><li><strong>Flexible: </strong>Different datasets can have different refresh types and schedules.</li><li><strong>Scalable: </strong>Supports multiple datasets with minimal configuration.</li><li><strong>Automated:</strong> Works with AWS Lambda &amp; Step Functions to trigger refreshes dynamically.</li></ul><h3>Refreshing QuickSight Datasets: An Overview of the Step Function</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1O0q7nMiiae6rgcS.png" /></figure><p>Before diving into the Lambda function implementation, it’s crucial to understand the <strong>AWS Step Function</strong> workflow that orchestrates the entire SPICE refresh process. By breaking it down first, we can clearly see how each component interacts, making it easier to understand the role of each Lambda function in the process.</p><p><strong>Step Function Workflow Overview</strong></p><p>The SPICE ingestion workflow is orchestrated using AWS Step Functions:</p><ul><li><strong>Parse YAML: </strong>Reads dataset details from an S3 YAML file.</li><li><strong>Parallel Refresh: </strong>Triggers refresh tasks for multiple datasets simultaneously.</li><li><strong>Check Status: </strong>Periodically checks if the ingestion is complete.</li></ul><p>The Step Function ensures that dataset refreshes are managed efficiently by handling parallel execution, monitoring ingestion statuses, and managing errors systematically.</p><p>Once we understand this workflow, we can explore the implementation details of each component of the workflow.</p><h3>Detailed Breakdown of the Lambda Implementation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6gq6c14nHzYpxqVg.png" /></figure><p>To automate the QuickSight SPICE refresh process, we use multiple AWS Lambda functions, each responsible for a specific part of the workflow. These functions interact with AWS Step Functions, Amazon S3 and QuickSight APIs to ensure a structured, scalable, and event-driven refresh mechanism.</p><p>In this section, we will walk through the key Lambda functions used in the implementation, explaining their roles and how they interact with the Step Function workflow.</p><p><strong>Parsing the YAML File from S3</strong></p><pre>def parse_yaml(event, context):<br>    s3 = boto3.client(&#39;s3&#39;)<br>    bucket_name = event[&#39;bucket_name&#39;]<br>    yaml_file_key = event[&#39;yaml_file_key&#39;]<br>    <br>    response = s3.get_object(Bucket=bucket_name, Key=yaml_file_key)<br>    content = response[&#39;Body&#39;].read().decode(&#39;utf-8&#39;)<br>    datasets_yaml = yaml.safe_load(content)<br><br>    datasets = []<br>        for name, dataset in datasets_yaml.items():<br>            refresh_type = dataset[&#39;refresh_type&#39;]<br>            # Filter out the weekly and monthly full refreshes if not needed<br>            ...<br>            datasets.append(dataset)<br>    <br>    return datasets</pre><p><em>Figure 2: Function to parse the YAML file and return the datasets’ configurations.</em></p><p><strong>Explanation:</strong></p><ul><li>Reads a YAML configuration file from an S3 bucket.</li><li>Parses and returns the dataset configurations as a list of JSONs.</li><li>Ensures that refresh configuration is set up correctly.</li><li>Ensures that we execute weekly and monthly full refreshes at the adequate days.</li></ul><p><strong>Refreshing QuickSight Datasets</strong></p><p>Once dataset configurations are parsed, the next Lambda function interacts directly with Amazon QuickSight APIs to trigger dataset refreshes. Depending on whether the dataset requires a full or incremental refresh, specific QuickSight APIs will be called.</p><p>The primary API call used is:</p><p><strong>1-<em> </em>create_ingestion — </strong>Initiates the SPICE dataset refresh:</p><pre>quicksight = boto3.client(&#39;quicksight&#39;)<br>response = quicksight.create_ingestion(<br>    DataSetId=&quot;dataset-id-here&quot;,<br>    IngestionId=&quot;unique-ingestion-id&quot;,<br>    AwsAccountId=&quot;123456789012&quot;,<br>    IngestionType=&quot;FULL_REFRESH&quot;  # or &quot;INCREMENTAL_REFRESH&quot;<br>)</pre><p><em>Figure 3: create_ingestion boto3 API call code snippet.</em></p><p>For incremental refreshes, additional API interactions are necessary:</p><p><strong>2- describe_data_set_refresh_properties</strong> — Checks existing incremental refresh configuration in QuickSight to avoid duplication and ensure consistency:</p><pre>quicksight = boto3.client(&#39;quicksight&#39;)<br>existing_properties = quicksight.describe_data_set_refresh_properties(<br>                AwsAccountId=&quot;123456789012&quot;,<br>                DataSetId=&quot;dataset-id-here&quot;)</pre><p><em>Figure 4: describe_data_set_refresh_properties boto3 API call code snippet.</em></p><p><strong>3–put_data_set_refresh_properties</strong> — Configures or updates incremental refresh settings if needed:</p><pre>quicksight = boto3.client(&#39;quicksight&#39;)<br>response = quicksight.put_data_set_refresh_properties(<br>    AwsAccountId=&quot;123456789012&quot;,<br>    DataSetId=&quot;dataset-id-here&quot;,<br>    DataSetRefreshProperties={<br>        &quot;RefreshConfiguration&quot;: {<br>            &quot;IncrementalRefresh&quot;: {<br>                &quot;LookbackWindow&quot;: {<br>                    &quot;ColumnName&quot;: &quot;usage_date&quot;,<br>                    &quot;Size&quot;: 5,<br>                    &quot;SizeUnit&quot;: &quot;DAY&quot;<br>                }<br>            }<br>        }<br>    }<br>)</pre><p><em>Figure 5: put_data_set_refresh_properties boto3 API call code snippet.</em></p><p>When incremental settings change, QuickSight automatically triggers a full refresh with a request type of “EDIT.” To manage and verify this behavior, two additional API calls are crucial:</p><p><strong>4- list_ingestions</strong> — Retrieves ingestion history to identify automatic refreshes triggered by configuration changes:</p><pre>quicksight = boto3.client(&#39;quicksight&#39;)<br>response = quicksight.list_ingestions(<br>    AwsAccountId=&quot;123456789012&quot;,<br>    DataSetId=&quot;dataset-id-here&quot;<br>)</pre><p><em>Figure 6: list_ingestions boto3 API call code snippet.</em></p><p><strong>5- describe_ingestion</strong> — Monitors the status of dataset refreshes, allowing our workflow to confirm completion, handle failures, or continue monitoring:</p><pre>quicksight = boto3.client(&#39;quicksight&#39;)<br>response = quicksight.describe_ingestion(<br>    AwsAccountId=&quot;123456789012&quot;,<br>    DataSetId=&quot;dataset-id-here&quot;,<br>    IngestionId=&quot;unique-ingestion-id&quot;<br>)</pre><p><em>Figure 7: describe_ingestion boto3 API call code snippet.</em></p><p><strong>Checking QuickSight Dataset Ingestion Status</strong></p><p>Once a dataset refresh (SPICE ingestion) has been triggered, we need to monitor its status to determine whether it succeeded, failed, or is still running. The function interacts with Amazon QuickSight APIs to fetch the latest ingestion status.</p><pre>response = quicksight.describe_ingestion(<br>    AwsAccountId=account_id,<br>    DataSetId=dataset_id,<br>    IngestionId=event[&#39;ingestion_id&#39;]<br>)<br>status = response[&#39;Ingestion&#39;][&#39;IngestionStatus&#39;]<br><br>if status == &#39;COMPLETED&#39;:<br>    # Proceed successfully<br>elif status == &#39;RUNNING&#39;:<br>    # Continue monitoring with backoff<br>elif status == &#39;FAILED&#39;:<br>    # Handle the failure</pre><p><em>Figure 8: checking QuickSight dataset ingestion status snippet.</em></p><h3>Step Function Workflow for Refreshing QuickSight Datasets</h3><p>This AWS Step Function is designed to orchestrate the refresh process of multiple QuickSight datasets in parallel while actively monitoring their ingestion statuses.</p><p><strong>1- Parsing the YAML File:</strong></p><p>The first state in the Step Function is ParseYAML, which extracts dataset configurations from the S3 YAML file.</p><p><strong>2- Triggering Parallel Refreshes:</strong></p><p>Once the dataset configurations are extracted, the Step Function uses a <strong>Map state</strong> to process multiple datasets in parallel. The Step Function iterates over each dataset in parallel.</p><p>It triggers the refresh datasets Lambda function to:</p><ul><li>Start a SPICE ingestion for the dataset.</li><li>Return an ingestion ID used to monitor the dataset’s refresh progress.</li></ul><p>The Map state can be used as follows:</p><pre>&quot;ParallelRefresh&quot;: {<br>  &quot;Type&quot;: &quot;Map&quot;,<br>  &quot;ItemsPath&quot;: &quot;$.datasets&quot;,<br>  &quot;Iterator&quot;: {<br>    &quot;StartAt&quot;: &quot;TriggerRefresh&quot;,<br>    &quot;States&quot;: {<br>      &quot;TriggerRefresh&quot;: {<br>        &quot;Type&quot;: &quot;Task&quot;,<br>        &quot;Resource&quot;: &quot;lambda_function_arn&quot;,<br>        &quot;Parameters&quot;: {<br>          ...<br>        },<br>        &quot;ResultPath&quot;: &quot;$.ingestion&quot;,<br>        ...<br>      }...<br>}</pre><p><em>Figure 9: Example of Step Function JSON definition snippet for a Map state.</em></p><p><strong>3- Monitoring the Refresh Progress:</strong></p><p>After triggering the ingestion, we initialize a wait time and actively monitor the ingestion status in an active loop. If the ingestion is still running, the Step Function waits before checking again. The waiting time is stored and used for exponential backoff. This ensures we don’t overload the QuickSight API with frequent status checks and prevent a high number of steps transitions which reduces the costs.</p><p>The ingestion status can be:</p><ul><li>“COMPLETED” → Proceed to success.</li><li>“RUNNING” → Wait and recheck.</li><li>“FAILED” → Move to failure handling.</li></ul><p><strong>4- Aggregating Results:</strong></p><p>At the end of the parallel refreshes, we aggregate the results of each parallel branch and we react with the aggregated result accordingly.</p><p>As a summary of the step function workflow, we provide the following flow diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xiSyvV-lQ3Kv28fMiNWcgA.png" /><figcaption><em>Figure 10: Workflow Diagram of the Step Function.</em></figcaption></figure><h3>Conclusion</h3><p>In this blog post, we explored how to dynamically control and automate QuickSight SPICE refreshes using AWS Lambda, Step Functions, API calls, and a YAML-based configuration. By leveraging this approach, we achieve:</p><ul><li><strong>Full control over dataset refreshes</strong>: The YAML configuration allows us to define datasets, refresh schedules, and incremental update settings in a structured and scalable manner.</li><li><strong>Seamless orchestration with AWS Step Functions: </strong>The step function enables parallel execution of multiple dataset refreshes while actively monitoring their ingestion statuses.</li><li><strong>Efficient and optimized refresh execution</strong>: By differentiating between full and incremental refreshes, we reduce unnecessary data processing and improve QuickSight performance.</li></ul><p>This solution provides a scalable, automated, and configurable way to refresh QuickSight datasets, making it easier to keep dashboards up to date without manual intervention.</p><p>As a next step, this implementation can be extended to include event-driven triggers, integration with AWS EventBridge for real-time dataset refreshes, and enhanced monitoring with CloudWatch metrics and logs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9aa86c13e972" width="1" height="1" alt=""><hr><p><a href="https://medium.com/datareply/automating-amazon-quicksight-spice-refreshes-using-aws-lambda-step-functions-and-aws-sdk-9aa86c13e972">Automating Amazon QuickSight SPICE Refreshes Using AWS Lambda, Step Functions, and AWS SDK</a> was originally published in <a href="https://medium.com/datareply">DataReply</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>