<?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 Mahak Urooj on Medium]]></title>
        <description><![CDATA[Stories by Mahak Urooj on Medium]]></description>
        <link>https://medium.com/@mahak.urooj?source=rss-0b7d10cac43b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZWo68jAqEfSG4mLJ</url>
            <title>Stories by Mahak Urooj on Medium</title>
            <link>https://medium.com/@mahak.urooj?source=rss-0b7d10cac43b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:55:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mahak.urooj/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[Serverless Solution to Automate S3-to-Tableau Data Pipelines]]></title>
            <link>https://medium.com/emumba/serverless-solution-to-automate-s3-to-tableau-data-pipelines-c44d3212eeaa?source=rss-0b7d10cac43b------2</link>
            <guid isPermaLink="false">https://medium.com/p/c44d3212eeaa</guid>
            <dc:creator><![CDATA[Mahak Urooj]]></dc:creator>
            <pubDate>Mon, 18 Aug 2025 12:35:10 GMT</pubDate>
            <atom:updated>2025-08-18T12:35:10.656Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yg2YuRP8jceUGmSOSD55hA.png" /></figure><p>In today’s fast-paced digital landscape, building real-time dashboards for data-driven decision-making is more critical than ever. As data trends evolve rapidly, delays in updating dashboards can lead to missed opportunities and hinder timely insights. Tableau, a widely adopted analytics and dashboarding tool, offers native connectors to various cloud platforms, making it well-suited for real-time or near real-time data ingestion.</p><p>Today we’ll explore a problem statement where application data is received daily in the form of CSV files, which are stored in date-based subfolders within an Amazon S3 bucket. As days progress, additional CSV files continue to accumulate in new folders. However, Tableau supports connecting only to a <strong>single CSV file</strong> within an S3 bucket, which poses a challenge:</p><p><em>How can we ensure Tableau accesses up-to-date data without manual consolidation?</em></p><p>To address this, we need a solution that automatically merges daily CSV data into a single, continually updated file or provides a structured way for Tableau to access and query this data without manual intervention.</p><p>This article outlines <strong>two fully serverless AWS-based solutions</strong> to automate the S3-to-Tableau data pipeline — ensuring Tableau receives consistent data updates and dashboards remain synchronized with the latest information.</p><h3>Proposed Solutions:</h3><ol><li><strong>AWS Lambda + Master CSV<br></strong> A lightweight Lambda function merges incoming daily CSVs into a single rolling <strong>master.csv</strong> file that Tableau can directly import.</li><li><strong>AWS Glue Crawler + AWS Glue Data Catalog + Athena<br></strong> A managed AWS Glue Crawler automatically discovers new files and schemas, while Athena enables SQL-based querying that Tableau can leverage using its Athena connector.</li></ol><p><strong>Note</strong>: Throughout this article, replace placeholders with your actual S3 bucket name and prefixes such as:</p><ul><li>YOUR_BUCKET_NAME</li><li>raw-data-prefix/</li><li>master-data-prefix/</li></ul><h3>Solution 1: AWS Lambda + Master CSV</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FtTzPSeECtDHlsbAiaoFQA.png" /></figure><h4>Architecture Overview</h4><p><strong>S3 Event Trigger</strong></p><ul><li>Fires AWS Lambda when new CSV files arrive within the specified folder of an S3 Bucket</li></ul><p><strong>Lambda Function</strong></p><ul><li>Reads a state marker (<em>last_processed.txt</em>) to determine which folders have been processed.</li><li>Downloads the existing <em>master.csv</em> from S3 <em>(if it exists)</em> to seed the merge.</li><li>Streams and concatenates only new CSV files from unprocessed date folders.</li><li>Uploads the updated <em>master.csv</em> directly to S3 and updates the <em>last_processed.txt</em> marker.</li></ul><p><strong>Tableau</strong>:</p><ul><li>Connects directly to the static <em>master.csv</em> in S3 using the native S3 connector or as an external file source.</li></ul><h4>Prerequisites</h4><ul><li>AWS account with S3 and Lambda permissions.</li><li>IAM user or role with rights to create and manage Lambda functions, IAM roles, and S3 resources.</li></ul><h4>Step 1: Create the S3 Bucket &amp; Folder Structure</h4><p>In the AWS Console, navigate to <strong>Amazon S3 </strong>service and click <strong>“Create bucket.” </strong>Name your bucket as YOUR_BUCKET_NAME.</p><p>Once the bucket is created, set up the folder<em> (prefix)</em> structure:</p><ol><li>Inside the bucket, create a folder for raw data/daily data dumps: <em>raw-data-prefix/.</em></li><li>Within this folder, upload at least one subfolder named in YYYY-MM-DD/ format <em>(e.g., 2025–07–10/)</em>, and place sample CSV files such as <em>regionA.csv</em> and <em>regionB.csv</em> inside it.</li></ol><p>Next, create another folder at the root level of the same bucket to store the consolidated output:</p><ul><li><em>master-data-prefix/</em> — this is where the merged <em>master.csv</em> will be stored.</li></ul><h4>Step 2: Create an IAM Role for Lambda</h4><p>In the <strong>AWS Console</strong>, navigate to <strong>IAM</strong> → <strong>Roles</strong>, and click <strong>“Create role.”<br></strong> This will guide you through a 3-step role creation process:</p><ol><li><strong>Select trusted entity</strong></li></ol><ul><li>Choose <strong>AWS service</strong> as the trusted entity type.</li><li>Select <strong>Lambda</strong> as the use case.</li><li>Click <strong>Next</strong>.</li></ul><p><strong>2. Add permissions</strong></p><ul><li>Attach the managed policy: <strong>AWSLambdaBasicExecutionRole</strong>.</li><li>Click <strong>Next</strong>.</li></ul><p><strong>3. Name, review and create</strong></p><ul><li>Enter a name for your role, e.g.: <em>lambda-s3-master-role.</em></li><li>Click <strong>Create role</strong>.</li></ul><p>Once the role is created:</p><ol><li>Navigate to the <strong>Permissions</strong> → “Add inline policy” of the newly created role.</li><li>In the policy editor, switch to the <strong>JSON</strong> tab and paste the following policy:</li></ol><pre>{<br> &quot;Version&quot;: &quot;2012–10–17&quot;,<br> &quot;Statement&quot;: [<br> {<br> &quot;Effect&quot;: &quot;Allow&quot;,<br> &quot;Action&quot;: [&quot;s3:ListBucket&quot;],<br> &quot;Resource&quot;: &quot;arn:aws:s3:::YOUR_BUCKET_NAME&quot;<br> },<br> {<br> &quot;Effect&quot;: &quot;Allow&quot;,<br> &quot;Action&quot;: [&quot;s3:GetObject&quot;,&quot;s3:PutObject&quot;],<br> &quot;Resource&quot;: &quot;arn:aws:s3:::YOUR_BUCKET_NAME/*&quot;<br> }<br> ]<br>}</pre><p>3. Click <strong>Next</strong> and name the policy LambdaS3AccessPolicy, and finally click on button <strong>Create policy</strong>.</p><p>You have now successfully created an IAM Role with the necessary permissions to access the S3 bucket and perform read and write operations.</p><h4>Step 3: Create the Lambda Function</h4><ol><li>Navigate to <strong>Lambda </strong>service<strong> → Create function</strong>.</li><li>Choose option “<strong>Author from scratch” to </strong>create the function.</li><li>Add the following settings for the Lambda function:</li></ol><ul><li>Function name: merge-daily-csvs <em>(our one of your choice)</em></li><li>Runtime: <strong>Python 3.9</strong> <em>(or higher).</em></li></ul><p>4. Under <strong>Permissions</strong>, select <strong>Use an existing role</strong> and choose IAM role we created earlier i.e. <em>lambda-s3-master-role</em>.</p><p>5. Click <strong>Create function</strong>.</p><h4>Step 4: Deploy the Lambda Code</h4><ol><li>In your lambda function’s <strong>Code</strong> tab, delete any default code.</li><li>Copy and paste the complete Python code below into <em>lambda_function.py</em>:</li></ol><pre>import os<br>import boto3<br>import csv<br>from io import StringIO<br>from datetime import datetime, timezone<br><br>s3 = boto3.client(&#39;s3&#39;)<br><br># ─── Configuration ──────────────────────────────────────────────<br>BUCKET        = os.environ.get(&#39;BUCKET&#39;, &#39;YOUR_BUCKET_NAME&#39;)<br>BASE_PREFIX   = os.environ.get(&#39;BASE_PREFIX&#39;, &#39;lambda/raw/&#39;)<br>MASTER_PREFIX = os.environ.get(&#39;MASTER_PREFIX&#39;, &#39;lambda/master/&#39;)<br>MASTER_KEY    = f&quot;{MASTER_PREFIX}master.csv&quot;<br>MARKER_KEY    = f&quot;{MASTER_PREFIX}last_processed.txt&quot;<br># ────────────────────────────────────────────────────────────────<br><br>def lambda_handler(event, context):<br>    print(&quot;Lambda triggered&quot;)<br><br>    # 1️⃣ Load last processed marker<br>    try:<br>        resp = s3.get_object(Bucket=BUCKET, Key=MARKER_KEY)<br>        last_processed = resp[&#39;Body&#39;].read().decode(&#39;utf-8&#39;).strip()<br>        print(&quot;Last processed date:&quot;, last_processed)<br>    except s3.exceptions.NoSuchKey:<br>        last_processed = &quot;0000-00-00&quot;<br>        print(&quot;No marker found; processing all folders&quot;)<br><br>    # 2️⃣ List all folders under raw/<br>    paginator = s3.get_paginator(&#39;list_objects_v2&#39;)<br>    all_folders = []<br>    for page in paginator.paginate(Bucket=BUCKET, Prefix=BASE_PREFIX, Delimiter=&#39;/&#39;):<br>        all_folders += [p[&#39;Prefix&#39;] for p in page.get(&#39;CommonPrefixes&#39;, [])]<br><br>    folders_to_proc = [<br>        p for p in all_folders<br>        if p.rstrip(&#39;/&#39;).split(&#39;/&#39;)[-1] &gt; last_processed<br>    ]<br>    if not folders_to_proc:<br>        print(&quot;✅ No new folders — nothing to do&quot;)<br>        return<br>    folders_to_proc.sort()<br>    print(&quot;Folders to process:&quot;, folders_to_proc)<br><br>    # 3️⃣ Start output buffer<br>    output = StringIO()<br>    writer = csv.writer(output)<br>    header_written = False<br><br>    try:<br>        resp = s3.get_object(Bucket=BUCKET, Key=MASTER_KEY)<br>        output.write(resp[&#39;Body&#39;].read().decode(&#39;utf-8&#39;))<br>        header_written = True<br>        print(&quot;✅ Seeded with existing master.csv&quot;)<br>    except s3.exceptions.NoSuchKey:<br>        print(&quot;ℹ️ No existing master.csv found — starting fresh&quot;)<br><br>    # 4️⃣ Process new files<br>    for prefix in folders_to_proc:<br>        print(&quot;→ Scanning folder:&quot;, prefix)<br>        result = s3.list_objects_v2(Bucket=BUCKET, Prefix=prefix)<br>        if &#39;Contents&#39; not in result:<br>            print(&quot;⚠️ No files found in&quot;, prefix)<br>            continue<br><br>        for obj in result[&#39;Contents&#39;]:<br>            key = obj[&#39;Key&#39;]<br>            if not key.lower().endswith(&#39;.csv&#39;):<br>                continue<br>            print(&quot;   Processing:&quot;, key)<br>            try:<br>                body = s3.get_object(Bucket=BUCKET, Key=key)[&#39;Body&#39;].read().decode(&#39;utf-8&#39;)<br>                reader = csv.reader(StringIO(body))<br>                header = next(reader)<br>                if not header_written:<br>                    writer.writerow(header)<br>                    header_written = True<br>                writer.writerows(reader)<br>            except Exception as e:<br>                print(&quot;❌ Error reading&quot;, key, &quot;:&quot;, str(e))<br><br>    # 5️⃣ Upload new master<br>    output.seek(0)  # 🔧 Required to reset pointer before reading buffer<br>    s3.put_object(<br>        Bucket=BUCKET,<br>        Key=MASTER_KEY,<br>        Body=output.getvalue().encode(&#39;utf-8&#39;)<br>    )<br>    print(f&quot;📄 Wrote up-to-date master to {MASTER_KEY}&quot;)<br><br>    # 6️⃣ Update marker<br>    newest_date = folders_to_proc[-1].rstrip(&#39;/&#39;).split(&#39;/&#39;)[-1]<br>    s3.put_object(<br>        Bucket=BUCKET,<br>        Key=MARKER_KEY,<br>        Body=newest_date.encode(&#39;utf-8&#39;)<br>    )<br>    print(f&quot;📝 Updated marker to {newest_date}&quot;)</pre><p>3. Click <strong>Deploy </strong>to deploy your code.</p><h4>Step 5: Configure S3 Trigger</h4><p>Next, configure a trigger for the Lambda function so that it runs automatically whenever the specified condition is met. This ensures the pipeline remains fully automated and eliminates the need for manual intervention.</p><ol><li>In Lambda function’s <strong>Configuration Tab → Triggers</strong>, click <strong>Add trigger</strong> and add following settings:</li></ol><ul><li>Select <strong>S3</strong>, choose YOUR_BUCKET_NAME.</li><li>Event type: <strong>PUT</strong>.</li><li>Prefix: raw-data-prefix/, Suffix: .csv.</li><li>Runtime: <strong>Python 3.9</strong> <em>(or higher).</em></li></ul><p>2. Click button <strong>Add</strong>.</p><p>You have now successfully set up an automated pipeline that automatically triggers the Lambda function whenever a new CSV file is uploaded to the S3 bucket, ensuring the data is seamlessly consolidated into a single master CSV file.</p><h4>Step 6: Test and Verify</h4><p>To test and verify your solution, follow these steps:</p><ol><li>Upload a new folder YYYY-MM-DD/ with CSV files under <em>raw-data-prefix/.</em></li><li>In <strong>CloudWatch Logs</strong>, check <em>/aws/lambda/merge-daily-csvs </em>for execution logs where you’ll be able to see that a new <em>master.csv</em> file is created in the same s3 bucket.</li><li>Confirm <em>master.csv</em> and <em>last_processed.txt</em> under <em>master-data-prefix/.</em></li></ol><p>With the first solution in place, it’s time to dive into the second serverless approach.</p><h3>Option 2: AWS Glue Crawler + Glue Data Catalog + Athena</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_lVhysRd8GfFOjlhxROFVw.png" /></figure><h4>Architecture Overview</h4><ul><li><strong>AWS Glue Crawler</strong>: Scans S3 daily and catalogs CSV schema and partitions.</li><li><strong>AWS Glue Data Catalog</strong>: Stores metadata and table definitions.</li><li><strong>Amazon Athena</strong>: Executes SQL queries over the cataloged data.</li><li><strong>Tableau</strong>: Connects via Athena ODBC/JDBC driver for live queries.</li></ul><h4>Prerequisites</h4><ul><li>AWS account with Glue, Athena, and S3 Bucket permissions.</li><li>IAM role for Glue with AWSGlueServiceRole and S3 read access.</li><li>An Athena workgroup (optional).</li></ul><p>Here’s a step by step guide on how we can configure AWS Glue Crawler to scan our daily CSV files coming up in S3 Bucket</p><h3>Step 1: Create the Glue Crawler</h3><p>In the AWS Console, navigate to <strong>AWS Glue → Crawlers → Add crawler</strong>.</p><ol><li><strong>Name your crawler</strong>:</li></ol><ul><li>Enter a unique name, such as “<em>daily-s3-crawler</em>”. Optionally, you may add a description to clarify the crawler’s purpose. Click <strong>Next</strong>.</li></ul><p><strong>2. Configure the data source</strong>:</p><ul><li>Choose <strong>S3</strong> as the data store.</li><li>Set the path to point to your S3 bucket (e.g., <em>s3://YOUR_BUCKET_NAME/raw-data-prefix/)</em>.</li><li>For crawler behavior, select <strong>“Crawl new sub-folders only”</strong> to ensure only newly added folders are processed, avoiding redundancy.</li><li>Once configured, add the data source and click <strong>Next</strong>.</li></ul><p><strong>3. Set up security</strong>:</p><ul><li>Choose an existing IAM role or create a new one that includes both <strong>AWSGlueServiceRole</strong> and <strong>S3</strong> read permissions.</li></ul><p><strong>4. Define output and schedule</strong>:</p><ul><li>Choose to create a new Glue database (<em>e.g., daily_data_db</em>) or select an existing one.</li><li>Set the crawler schedule to either <strong>Run on demand</strong> or define a schedule (<em>e.g., daily at 00:15 UTC</em>).</li></ul><p><strong>5. Review and complete</strong>:</p><ul><li>Review all settings and click <strong>Finish</strong>.</li></ul><p>Congratulations! Your crawler is now configured and ready to scan your S3 data.</p><h4>Step 2: Run the Crawler &amp; Validate</h4><p>Select your crawler and click <strong>Run crawler</strong> if you have configured it to run on demand.</p><p>Once the crawler completes its run, navigate to <strong>AWS Glue → Tables</strong>. You should now see a table <em>(e.g., raw_data_prefix) </em>that includes partitions organized by date. The table is typically named after the folder path where the daily CSV files are stored.</p><p>You’ll observe that the table includes data from all the CSV files present in your S3 bucket. In AWS Glue, partitions act like virtual folders — each partition corresponds to a sub-folder within your S3 bucket, allowing for efficient querying and organization based on those subdirectories.</p><h4>Step 3: Query Data in Athena</h4><ol><li>Open <strong>Amazon Athena</strong>.</li><li>In <strong>Query Editor</strong>, select the database daily_data_db.</li><li>Run the following sample query, you’ll be able to view the data for the specified date.</li></ol><pre>SELECT *<br>FROM raw_data_prefix<br>WHERE date = current_date;</pre><h4>Step 4: Connect Tableau to Athena</h4><ol><li>In Tableau Desktop, click <strong>Connect → Amazon Athena</strong>.</li><li>Enter your AWS credentials or use <strong>IAM Role</strong> if on EC2.</li><li>Select your <strong>region</strong>, S3 staging directory (e.g., <em>s3://YOUR_BUCKET_NAME/query-results/)</em>.</li><li>Choose the database daily_data_db and your table.</li><li>Build and publish dashboards that automatically reflect daily updates.</li></ol><p>We’ve now walked through a detailed, step-by-step guide on how to consolidate daily data dumps — uploaded as CSV files into an Amazon S3 bucket — and make them accessible to Tableau without requiring any manual intervention. Both solutions presented offer a fully automated, serverless setup to keep your Tableau dashboards up-to-date in near real-time.</p><p>Next, let’s compare the two solutions in terms of their <strong>advantages, trade-offs, and associated costs</strong>.</p><h3>Comparison: Pros, Cons &amp; Costs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7JyzKdJULQLZoHLltYRy1w.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fdatawrapper.dwcdn.net%2Fn2dRH%2F1%2F&amp;display_name=Datawrapper&amp;url=https%3A%2F%2Fdatawrapper.dwcdn.net%2Fn2dRH%2F1%2F&amp;image=https%3A%2F%2Fdatawrapper.dwcdn.net%2Fn2dRH%2Fplain-s.png%3Fv%3D1&amp;type=text%2Fhtml&amp;schema=dwcdn" width="600" height="525" frameborder="0" scrolling="no"><a href="https://medium.com/media/085702f4d83ae3b195707bec7fede19d/href">https://medium.com/media/085702f4d83ae3b195707bec7fede19d/href</a></iframe><h3><strong>When to choose Lambda solution</strong></h3><ul><li>You have small-to-medium daily CSVs (&lt;100 MB/day).</li><li>You need immediate updates on file arrival.</li><li>You prefer minimal AWS services and nearly zero cost.</li></ul><h3><strong>When to choose Glue + Athena solution</strong></h3><ul><li>You expect schema evolution or large data volumes.</li><li>You prefer SQL querying and partition pruning.</li><li>You can tolerate slight delays based on crawler schedule.</li></ul><h3><strong>Conclusion</strong></h3><p>Both solutions deliver a serverless pipeline to make daily S3 CSV dumps available in Tableau:</p><ul><li><strong>Lambda + Master CSV</strong> is ideal for ultra-simple, near real-time merging.</li><li><strong>Glue Crawler + Athena</strong> offers robust schema management and SQL-based analytics at scale.</li></ul><p>Select the pattern that best fits your data volume, freshness requirements, and operational overhead.</p><p>Happy Learning!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yyYQFZx1hITZxfbLuneyHA.png" /></figure><h3>References</h3><p>Here are some resources to learn more about the services used in these solutions:</p><ol><li><a href="https://aws.amazon.com/s3/?nc=sn&amp;loc=1&amp;refid=6f994a6a-dde0-4a5a-9b7d-16470c6f35bd">AWS S3</a></li><li><a href="https://aws.amazon.com/pm/lambda/?trk=bc544035-c62f-4265-a610-fe68e4271715&amp;sc_channel=ps&amp;ef_id=Cj0KCQjwnovFBhDnARIsAO4V7mCCByfsQVJMGwqnICXwr4FsGdy1C4ARy8b_yTDxpGu8ymxgwDxSmWYaAptsEALw_wcB:G:s&amp;s_kwcid=AL!4422!3!651510255294!e!!g!!aws%20lambda!19828212645!149982299751&amp;gad_campaignid=19828212645&amp;gbraid=0AAAAADjHtp_I5C-lRqgQfSepKdmaSdEem&amp;gclid=Cj0KCQjwnovFBhDnARIsAO4V7mCCByfsQVJMGwqnICXwr4FsGdy1C4ARy8b_yTDxpGu8ymxgwDxSmWYaAptsEALw_wcB">AWS Lambda</a></li><li><a href="https://aws.amazon.com/glue/">AWS Glue</a></li><li><a href="https://aws.amazon.com/athena/">AWS Athena</a></li><li><a href="https://www.tableau.com/">Tableau</a></li><li><a href="https://docs.aws.amazon.com/glue/latest/dg/add-crawler.html">Using glue crawlers to populate the Data Catalog</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c44d3212eeaa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/serverless-solution-to-automate-s3-to-tableau-data-pipelines-c44d3212eeaa">Serverless Solution to Automate S3-to-Tableau Data Pipelines</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>