<?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 Haifa Aljundi on Medium]]></title>
        <description><![CDATA[Stories by Haifa Aljundi on Medium]]></description>
        <link>https://medium.com/@haifajundi?source=rss-3c96abc2baa4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*trg0pKF1Xdhv97krGi1m5g.jpeg</url>
            <title>Stories by Haifa Aljundi on Medium</title>
            <link>https://medium.com/@haifajundi?source=rss-3c96abc2baa4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 18:24:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haifajundi/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[How I Built a Cost Calculator After My Side Project’s AWS Bill Hit $$$]]></title>
            <link>https://aws.plainenglish.io/i-built-a-cost-calculator-after-my-side-projects-aws-bill-hit-0c42576c95d4?source=rss-3c96abc2baa4------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c42576c95d4</guid>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Haifa Aljundi]]></dc:creator>
            <pubDate>Tue, 30 Sep 2025 12:09:55 GMT</pubDate>
            <atom:updated>2025-10-01T04:21:19.185Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><em>I went from panic to control with a custom dashboard and saved my side project</em></blockquote><h3>The Wake-Up Call</h3><p>It was 2 AM when I got the AWS billing alert email. My small side project had just cost me $340 in a single month.</p><p>One of the biggest challenges when working with AWS is <strong>keeping track of costs</strong>. The more services you use, the harder it becomes to understand where your money is going.</p><p>That’s when I decided to build my own cost tracking system. Not because the AWS Cost Explorer doesn’t exist it does but because I needed something that would actually help me understand my spending in real-time, without clicking through a dozen pages.</p><p>This is the story of how I built it, what I learned, and how it saved my side project from bankruptcy.</p><h3>Why AWS Cost Explorer Wasn’t Enough</h3><p>Look, AWS gives you tools. The Cost Explorer is fine for big companies with finance teams. But for a solo developer running a side project? It felt like using a firehose to water a houseplant.</p><p><strong>My problems:</strong></p><ul><li>Data is delayed by 24+ hours (my bill was already high by the time I saw it)</li><li>Too many clicks to get simple answers</li><li>Can’t set up the exact alerts I need</li><li>No way to see trends that actually matter to me</li><li>Couldn’t share a simple dashboard with my co-founder</li></ul><p>I needed something simpler, faster, and actually built for how I think about costs.</p><h3>The Right Architecture (After Research)</h3><p>After reading AWS documentation and blog posts, I learned about the proper way to handle cost analytics at scale:</p><h3>Two-Layer Approach</h3><p><strong>Layer 1: Batch Analytics</strong></p><pre>CUR → S3 → Glue Crawler → Athena → QuickSight</pre><p>For deep historical analysis and ML forecasting</p><p><strong>Layer 2: Real-Time Monitoring</strong></p><pre>CloudWatch → Lambda → SNS → Alerts</pre><p>For immediate anomaly detection</p><h3>Why This Architecture?</h3><p>This isn’t just for enterprise — it’s actually perfect for side projects because:</p><ul><li><strong>All serverless</strong> (no servers to manage)</li><li><strong>Pay-per-use</strong> (perfect for variable workloads)</li><li><strong>Industry-standard</strong> (learn what companies actually use)</li><li><strong>Scalable</strong> (works for $50/month or $50K/month)</li></ul><h3>Phase 1: Setting Up the Data Foundation</h3><h4>Step 1: Enable Cost and Usage Reports</h4><p>The first thing I learned: AWS Cost Explorer only shows you aggregated data. If you want the raw details, you need Cost and Usage Reports (CUR).</p><p><strong>Setup process:</strong></p><ol><li>AWS Console → Billing → Cost &amp; Usage Reports</li><li>Create new report</li><li>Create an S3 bucket for the data</li></ol><p><strong>Important:</strong> The first report takes 24–48 hours. I kept refreshing the bucket thinking I did something wrong. Be patient.</p><h4>Step 2: Understanding What CUR Actually Contains</h4><p>When my first CUR file finally appeared, I opened it in Athena and was overwhelmed — 150+ columns of data.</p><p><strong>The columns that actually matter:</strong></p><pre>Key Columns I Use:<br><br>line_item_usage_start_date     → When it was used<br>line_item_product_code         → Which AWS service<br>line_item_blended_cost         → What it cost<br>product_region                 → Where it ran<br>resource_id                    → The specific resource<br>line_item_usage_type           → Type of usage</pre><p>The rest? Mostly metadata I don’t need for basic analysis.</p><h4>Step 3: AWS Glue Crawler (The Game Changer)</h4><p>This was my “aha!” moment. Instead of manually processing CUR files, AWS Glue can automatically:</p><ul><li>Discover new files in S3</li><li>Detect their schema</li><li>Create a queryable database</li><li>Handle format changes</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qzgbuBXQJxc79iLzjURH9w.png" /></figure><p><strong>Setting up Glue:</strong></p><ol><li>Create a database:</li></ol><pre>Database name: cost_analytics_db<br>Description: CUR data catalog</pre><p>2. Create a crawler:</p><pre>Crawler name: daily-cur-crawler<br>Data source: s3://my-cur-bucket/<br>IAM role: AWSGlueServiceRole-CURCrawler<br>Schedule: Daily at 2:00 AM UTC<br>Database: cost_analytics_db</pre><p>The crawler runs daily and automatically updates my data catalog. Zero manual work.</p><h3>Phase 2: Batch Analytics with Athena + QuickSight</h3><h3>Amazon Athena: SQL for S3</h3><p>Athena lets me query my CUR data using SQL without loading anything into a database.</p><p><strong>Example queries I use regularly:</strong></p><p><strong>1. Top10</strong> <strong>Spend by AccountID:</strong></p><pre>SELECT line_item_usage_account_id, ROUND(SUM(line_item_unblended_cost),2) AS cost FROM cost_analytics_db.cur_table<br>GROUP BY line_item_usage_account_id<br>ORDER BY cost DESC<br>LIMIT 10;</pre><p><strong>2. Top10 Costs by Product:</strong></p><pre>SELECT line_item_product_code, ROUND(SUM(line_item_unblended_cost),2) AS cost FROM cost_analytics_db.cur_table<br>GROUP BY line_item_product_code<br>ORDER BY cost DESC<br>LIMIT 10;</pre><p><strong>3. Top10 Costs by Line Item Description</strong></p><pre>SELECT line_item_product_code, line_item_line_item_description, ROUND(SUM(line_item_unblended_cost),2) AS cost FROM cost_analytics_db.cur_table<br>GROUP BY line_item_product_code, line_item_line_item_description<br>ORDER BY cost DESC<br>LIMIT 10;</pre><p><strong>4. Top EC2 Costs</strong></p><pre>SELECT line_item_product_code, line_item_line_item_description, ROUND(SUM(line_item_unblended_cost),2) AS cost FROM cost_analytics_db.cur_table<br>WHERE line_item_product_code LIKE &#39;%AmazonEC2%&#39;<br>GROUP BY line_item_product_code, line_item_line_item_description<br>ORDER BY cost DESC<br>LIMIT 10;</pre><p><strong>5. Top EC2 OnDemand Costs</strong></p><pre>SELECT line_item_product_code, line_item_line_item_description, ROUND(SUM(line_item_unblended_cost),2) AS cost FROM cost_analytics_db.cur_table<br>WHERE line_item_product_code LIKE &#39;%AmazonEC2%&#39; and line_item_usage_type LIKE &#39;%BoxUsage%&#39;<br>GROUP BY line_item_product_code, line_item_line_item_description<br>ORDER BY cost DESC<br>LIMIT 10;</pre><p><strong>Query Performance:</strong></p><ul><li>First run: ~8–12 seconds (scanning data)</li><li>Subsequent runs: ~2–4 seconds (caching)</li><li>Cost: ~$0.10 per TB scanned</li></ul><h3>Amazon QuickSight: The Dashboard</h3><p>This was the part that impressed me most. QuickSight gave me a professional BI dashboard without building a frontend.</p><ol><li><strong>Subscribe to QuickSight</strong></li><li><strong>Connect to Athena</strong></li></ol><ul><li>Data source: Athena</li><li>Database: cost_analytics_db</li><li>Table: cur_table</li></ul><p>3.<strong> Create Calculated Fields</strong></p><pre>-- PurchaseOption<br><br>ifelse(split({line_item_usage_type},&#39;:&#39;,1) = &#39;SpotUsage&#39;,&#39;Spot&#39;,ifelse(right(split({product_usagetype},&#39;:&#39;,1), 8) = &#39;BoxUsage&#39;,{pricing_term},&#39;other&#39;))</pre><pre>--InstanceType<br><br>split({line_item_usage_type},&#39;:&#39;,2)</pre><p>4.<strong> Build Dashboards</strong></p><p><strong>Executive Overview</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*27neMrCUDuDi9pxwMVp7nA.png" /></figure><h3>Phase 3: Real-Time Monitoring &amp; Alerts</h3><p>Having historical dashboards is great, but I needed to know immediately when something goes wrong.</p><h3>CloudWatch Billing Metrics</h3><p>AWS publishes billing metrics to CloudWatch every 6 hours. I used these to set up automated monitoring.</p><p><strong>Available Metrics:</strong></p><ul><li>EstimatedCharges (Total bill so far)</li><li>Service-specific charges (EC2, S3, Lambda, etc.)</li></ul><h3>Lambda for Anomaly Detection</h3><p>I wrote a Lambda function that runs daily and checks for unusual spending patterns:</p><p><strong>What it does:</strong></p><ol><li>Queries Athena for yesterday’s costs</li><li>Compares to 30-day average</li><li>Calculates percentage change</li><li>Sends alert if &gt; 50% increase</li></ol><p><strong>Deployment:</strong></p><pre>Function name: daily-cost-checker<br>Runtime: Python 3.11<br>Memory: 256 MB<br>Timeout: 60 seconds<br>Schedule: Daily at 9:00 AM<br>Environment variables:<br>  - ATHENA_DATABASE: cost_analytics_db<br>  - SNS_TOPIC_ARN: arn:aws:sns:...:cost-alerts</pre><p><strong>The Logic (Simplified):</strong></p><pre># Pseudocode for the Lambda function<br>def lambda_handler(event, context):<br>    # Query yesterday&#39;s cost<br>    yesterday_cost = query_athena(&quot;&quot;&quot;<br>        SELECT SUM(line_item_blended_cost) <br>        FROM cur_table <br>        WHERE date = current_date - 1<br>    &quot;&quot;&quot;)<br>    <br>    # Query 30-day average<br>    avg_cost = query_athena(&quot;&quot;&quot;<br>        SELECT AVG(daily_cost) <br>        FROM (<br>            SELECT DATE, SUM(cost) as daily_cost<br>            FROM cur_table <br>            WHERE date &gt;= current_date - 30<br>            GROUP BY DATE<br>        )<br>    &quot;&quot;&quot;)<br>    <br>    # Calculate change<br>    change_percent = ((yesterday_cost - avg_cost) / avg_cost) * 100<br>    <br>    # Alert if unusual<br>    if change_percent &gt; 50:<br>        send_alert(f&quot;Cost spike detected: {change_percent}% above average&quot;)<br>    <br>    # Also send weekly summary every Monday<br>    if today_is_monday():<br>        send_weekly_summary()</pre><h3>SNS for Multi-Channel Alerts</h3><p>I set up SNS (Simple Notification Service) to deliver alerts via:</p><p><strong>1. Email Alerts</strong></p><pre>Subject: AWS Cost Alert - Unusual Activity<br><br>Your AWS spending yesterday was $18.40, which is <br>127% higher than your 30-day average of $8.10.<br><br>Top contributors to the spike:<br>- EC2 (us-east-1): +$7.30 (Instance i-abc123 left running)<br>- S3 API Calls: +$2.50 (Unusual traffic pattern)<br><br>View details: [Link to QuickSight Dashboard]</pre><p><strong>2. Slack Integration</strong></p><pre>SNS → Lambda → Slack Webhook<br><br>Slack message format:<br>Cost Alert<br>Yesterday: $18.40 (↑127%)<br>Average: $8.10<br><br>Top Issues:<br>- EC2: Instance i-abc123 running 18 hours<br>- S3: 3.2M GET requests (unusual)<br><br>[View Dashboard] [Acknowledge]</pre><p><strong>3. Weekly Summary Email</strong></p><pre>Subject: Weekly AWS Cost Summary<br><br>This week: $58.30 (↓15% vs last week)<br>This month: $127.40 (on track for $165)<br><br>Service breakdown:<br>- Lambda: $19.80 (34%)<br>- S3: $16.30 (28%)<br>- EC2: $12.20 (21%)<br><br>Insights:<br>S3 costs down 45% after implementing lifecycle policies<br>Lambda invocations up 23%—monitor closely<br><br>[View Full Report]</pre><h3>What I Discovered About My Bill</h3><p>Once the system was running, I finally understood what caused the spike:</p><h3>Root Cause Analysis</h3><p><strong>The Culprit: Forgotten GPU Instance</strong></p><p>Using Athena queries, I found:</p><pre>SELECT <br>  resource_id,<br>  line_item_usage_type,<br>  SUM(line_item_blended_cost) as cost,<br>  COUNT(*) as hours<br>FROM cur_table<br>WHERE DATE = &#39;2025-06-15&#39;<br>  AND line_item_blended_cost &gt; 1<br>GROUP BY resource_id, line_item_usage_type<br>ORDER BY cost DESC;</pre><p><strong>Results:</strong></p><pre>resource_id: i-0a1b2c3d4e5f<br>instance_type: p3.2xlarge (GPU instance)<br>cost: $234.56<br>hours: 307 hours<br>rate: $3.06/hour<br>Status: Running (forgot to stop after testing)</pre><p><strong>Secondary Issues Found:</strong></p><ul><li>S3 transfer costs spiked (moved data to wrong region)</li><li>NAT Gateway running 24/7 (unnecessary for my use case)</li><li>Old CloudWatch Logs not deleted (7 months of logs)</li></ul><p><strong>Total waste identified: $287 in a single month</strong></p><h3>The Results</h3><h4>Cost Reduction</h4><p><strong>Before the system:</strong></p><pre>June: $340<br>- No visibility<br>- Reactive problem solving<br>- Wasted resources running</pre><p><strong>After implementation:</strong></p><pre>July: $53<br>August: $47<br>September: $51<br><br>Savings: ~$240/month<br>Annual savings: ~$2,880</pre><h3>What Actually Changed</h3><p><strong>Immediate Actions Taken:</strong></p><ol><li>Terminated forgotten p3.2xlarge instance</li><li>Moved S3 data to correct region (eliminated cross-region transfer)</li><li>Replaced NAT Gateway with VPC endpoints ($32/month → $0)</li><li>Set up S3 lifecycle policy (moved old logs to Glacier)</li><li>Implemented auto-shutdown for dev EC2 instances</li></ol><h3>Final Thoughts</h3><p>Building this cost analytics platform turned a $340 mistake into a valuable learning experience.</p><p>The architecture I used — CUR → Glue → Athena → QuickSight + CloudWatch alerts isn’t just for side projects. It’s the same approach used by companies spending millions on AWS.</p><p><strong>If you’re running anything on AWS side project, startup, or just learning build this system.</strong> You’ll save money and learn industry-standard tools.</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c42576c95d4" width="1" height="1" alt=""><hr><p><a href="https://aws.plainenglish.io/i-built-a-cost-calculator-after-my-side-projects-aws-bill-hit-0c42576c95d4">How I Built a Cost Calculator After My Side Project’s AWS Bill Hit $$$</a> was originally published in <a href="https://aws.plainenglish.io/">AWS in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>