<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rushabh Trivedi</title>
    <description>The latest articles on DEV Community by Rushabh Trivedi (@rushabh_ufo).</description>
    <link>https://dev.to/rushabh_ufo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1515858%2F5bcb2a74-0176-4ded-9964-f3cb307148b9.jpeg</url>
      <title>DEV Community: Rushabh Trivedi</title>
      <link>https://dev.to/rushabh_ufo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rushabh_ufo"/>
    <language>en</language>
    <item>
      <title>Stop Wasting Money on Lambda: Automate Right-Sizing Across Your AWS Account</title>
      <dc:creator>Rushabh Trivedi</dc:creator>
      <pubDate>Fri, 31 Jul 2026 10:50:08 +0000</pubDate>
      <link>https://dev.to/rushabh_ufo/stop-wasting-money-on-lambda-automate-right-sizing-across-your-aws-account-47dh</link>
      <guid>https://dev.to/rushabh_ufo/stop-wasting-money-on-lambda-automate-right-sizing-across-your-aws-account-47dh</guid>
      <description>&lt;h2&gt;
  
  
  The Silent Cost Leak Nobody Talks About
&lt;/h2&gt;

&lt;p&gt;You know that feeling when you discover a Lambda function still running with a 1024 MB memory allocation — even though CloudWatch shows it never uses more than 80 MB? That’s not just a missed optimization. That’s a silent tax on your AWS bill that compounds with every invocation.&lt;/p&gt;

&lt;p&gt;Here’s the hard truth: AWS Lambda pricing is shaped by two things — invocation count and GB-seconds (memory × duration). While the per-invocation cost is tiny, memory is the only dimension you can actually control. And control it, most teams do not.&lt;/p&gt;

&lt;p&gt;I’ve seen production accounts where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A payment processor function sits at 1024 MB, running at 7% utilization&lt;/li&gt;
&lt;li&gt;An auth validator is configured at 128 MB but hitting 63% of limit during peak traffic&lt;/li&gt;
&lt;li&gt;Legacy report generators haven’t been touched since deployment, silently consuming budget at outdated allocations&lt;/li&gt;
&lt;li&gt;The problem? There’s no automated way to catch and fix this at scale.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Manual auditing is impractical. Spreadsheets go stale. The courage required to actually change production configurations without deep analysis? That’s the real barrier.&lt;/p&gt;

&lt;p&gt;So we built Lambda Rightsizer — a tool that makes right-sizing as routine as a database index optimization, complete with safety guarantees, built-in rollback, and ready-to-apply remediation scripts.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why This Matters (The Business Case)
&lt;/h2&gt;

&lt;p&gt;Let’s do the math. Imagine your account has 50 Lambda functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;30% are clearly over-provisioned (avg utilization below 30%)&lt;/li&gt;
&lt;li&gt;Average waste: 300 MB per over-provisioned function&lt;/li&gt;
&lt;li&gt;Average invocation rate: 1,000 invocations/day per function&lt;/li&gt;
&lt;li&gt;That’s 15 functions × 300 MB × 1,000 invocations/day = 4.5 GB-seconds/day of pure waste.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At AWS Lambda’s us-east-1 pricing (~$0.0000166667 per GB-second):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;$2.30/day × 365 = $839.50/year — just on those 15 functions&lt;/li&gt;
&lt;li&gt;Scale to 200 functions? You’re looking at $5,000+ in unnecessary spend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that’s before considering the compliance angle: you can’t optimize what you don’t measure. Right-sizing is also a best practice for cost governance audits.&lt;/p&gt;




&lt;h2&gt;
  
  
  What Makes This Hard (And How Lambda Rightsizer Solves It)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;The Discovery Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Finding all Lambda functions across your account is trivial with ListFunctions. But figuring out how much memory each one actually uses is where most solutions fail.&lt;/p&gt;

&lt;p&gt;CloudWatch Logs Insights is powerful but can be slow. Direct metric queries are imprecise. And parsing raw logs locally is error-prone.&lt;/p&gt;

&lt;p&gt;Lambda Rightsizer uses a three-tier strategy:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;CloudWatch Logs Insights — server-side aggregation of REPORT log lines (fastest)&lt;/li&gt;
&lt;li&gt;CloudWatch Logs filter — raw event parsing (when Insights returns few samples)&lt;/li&gt;
&lt;li&gt;CloudWatch Metrics — MaxMemoryUsed metric (last resort, always available)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The tool tries each in sequence, falling back gracefully. No manual CloudWatch spelunking required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Analysis Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Raw memory numbers don’t tell you whether a function is correctly sized. You need context:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is peak usage near the limit? (under-provisioned, risk of timeout)&lt;/li&gt;
&lt;li&gt;Is average usage &amp;lt; 30% of allocated? (over-provisioned, pure waste)&lt;/li&gt;
&lt;li&gt;Are you seeing a reliable trend, or just a few outlier invocations? (signal vs. noise)
Lambda Rightsizer applies a utilization band model:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;UtilizationStatusAction&amp;lt; 30%Over-provisionedReduce to safety floor30–70%OptimalKeep as-is70–80%WatchMonitor (approaching limit)&amp;gt; 80%Under-provisionedIncrease above safety floor&lt;/p&gt;

&lt;p&gt;But here’s the critical part: the tool never recommends below the observed peak + 20% headroom. This protects against cold-start spikes and prevents the “we reduced memory and now functions timeout” surprise.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Risk Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not all right-sizing recommendations are equally safe. A reduction from 1024 MB to 128 MB on a function that’s only had 3 invocations in the past month? Different risk profile than a change backed by 10,000 invocations of solid telemetry.&lt;/p&gt;

&lt;p&gt;Lambda Rightsizer scores every recommendation on a 1–5 scale, based on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sample count (low count = higher risk)&lt;/li&gt;
&lt;li&gt;Data source quality (metrics fallback = less reliable)&lt;/li&gt;
&lt;li&gt;Magnitude of change (50%+ reduction = riskier)&lt;/li&gt;
&lt;li&gt;P95 proximity to recommended ceiling (close call = risky)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;High-risk recommendations (score ≥ 4) require explicit per-function confirmation. You can also skip them entirely with SKIP_HIGH_RISK=true for conservative deployments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Remediation Problem&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Even with perfect analysis, applying changes safely requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pre-flight validation that AWS credentials are valid&lt;/li&gt;
&lt;li&gt;A full change summary before any AWS calls&lt;/li&gt;
&lt;li&gt;Confirmation prompts (with a DRY_RUN mode for preview)&lt;/li&gt;
&lt;li&gt;Detailed per-function comments explaining the recommendation&lt;/li&gt;
&lt;li&gt;A companion rollback script in case something goes wrong&lt;/li&gt;
&lt;li&gt;For CI/CD: batch mode without prompts, but still with safety guards&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most tools stop at reporting. Lambda Rightsizer generates production-ready bash scripts that handle all of this.&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture: Built for Real-World Complexity
&lt;/h2&gt;

&lt;p&gt;Here’s what happens under the hood:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;┌─ CLI (main.py)
│  ├─ Parses arguments / loads .env config
│  └─ Validates AWS credentials
│
├─ Discovery (lambda_discovery.py)
│  └─ Paginates ListFunctions → FunctionRecord list
│
├─ Metrics Collection (metrics_analyzer.py) — PARALLEL
│  ├─ Tries Logs Insights first
│  ├─ Falls back to Logs filter
│  └─ Falls back to CloudWatch Metrics
│  └─ Returns peak, avg, min, P95 memory + data source
│
├─ Optimization (optimizer.py)
│  ├─ Calculates utilization %
│  ├─ Applies utilization band logic
│  ├─ Computes safety floor (peak × 1.20 / 64 MB steps)
│  ├─ Risk-scores the recommendation
│  └─ Returns OptimizationRecord
│
└─ Output (report_generator.py + remediation_script_generator.py)
   ├─ Console table (colorized, sortable by risk)
   ├─ CSV export (for spreadsheet analysis)
   ├─ JSON report (structured, machine-parseable)
   ├─ remediation_&amp;lt;ts&amp;gt;.sh (apply changes safely)
   ├─ rollback_&amp;lt;ts&amp;gt;.sh (restore on demand)
   └─ backup_&amp;lt;ts&amp;gt;.json (original config snapshot)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Key design decisions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parallel metrics collection — ThreadPoolExecutor fetches CloudWatch data for multiple functions concurrently (configurable worker count)&lt;/li&gt;
&lt;li&gt;Fallback chains — tries three strategies in order; no failure == no skip&lt;/li&gt;
&lt;li&gt;Timestamped outputs — every run creates a unique folder; nothing overwrites&lt;/li&gt;
&lt;li&gt;Built-in rollback — every applied change can be undone with a single script&lt;/li&gt;
&lt;li&gt;Safety-first remediation — generated bash script has multiple confirmation layers&lt;/li&gt;
&lt;li&gt;Zero production impact by default — the analysis tool is read-only; scripts are generated but require explicit execution&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Features You’ll Love
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Console Dashboard&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;════════════════════════════════════════════════════════════════════════════════
                            LAMBDA RIGHTSIZER
Generated: 2024-03-15 14:23:01 UTC              Region: us-east-1
Lookback:  14 days                              Waste threshold: 40%
════════════════════════════════════════════════════════════════════════════════
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;| Function              | Runtime    | Alloc | Peak | Avg | P95 | Util | Waste | Status      |
|---                    |---         |---    |---  |---  |---  |---   |---    |---          |
| payment-processor     | python3.11 | 1024  | 87  | 72  | 85  | 7%   | 91.5% | over-prov   |
| order-handler         | nodejs18   | 512   | 201 | 178 | 198 | 34.8%| 60.7% | over-prov   |
| image-resizer         | python3.11 | 256   | 231 | 198 | 228 | 77.3%| 9.8%  | watch       |
| auth-validator        | nodejs18   | 128   | 98  | 81  | 96  | 63.3%| 23.4% | optimal     |
|---                    |---         |---    |---  |---  |---  |---   |---    |---          |
| SUMMARY               |            |       |     |     |     |      |       |             |
| Total analyzed        | 5          | Over-prov: 2    | Optimal: 1              |
| Potential savings     | 1152 MB    | Under-prov: 0   | Watch: 1                |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Colorized, sorted by severity, immediately tells you where the waste is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Three Data Strategies (With Fallback)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Not all functions generate logs. Not all have sufficient CloudWatch metrics history. Lambda Rightsizer tries three approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CloudWatch Logs Insights — fast, server-side, cheap (if you have logs)&lt;/li&gt;
&lt;li&gt;CloudWatch Logs filter — slower, but parses raw REPORT lines&lt;/li&gt;
&lt;li&gt;CloudWatch Metrics — last resort; always available even without logs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Pick the first one that succeeds for each function. No “insufficient data” if there’s any signal at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Multi-Region Support&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scan one region, or parallelize across multiple regions. Each run produces isolated reports, so you can compare regions side-by-side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Filtering&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scan all functions, or target specific ones by name substring:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python -m lambda_rightsizer.main --filter payment,order,auth&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Function-Level Risk Scoring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every recommendation comes with a 1–5 risk score. High-risk changes (score ≥ 4) require explicit confirmation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Preview before applying&lt;/span&gt;
&lt;span class="nv"&gt;DRY_RUN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;bash remediation_20240315T142301Z.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Apply interactively (requires confirmation)&lt;/span&gt;
bash remediation_20240315T142301Z.sh
&lt;span class="c"&gt;# Apply in batch mode (auto-approve low-risk, skip high-risk)&lt;/span&gt;
&lt;span class="nv"&gt;SKIP_HIGH_RISK&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;bash remediation_20240315T142301Z.sh
&lt;span class="c"&gt;# Force apply all (CI/CD with full automation)&lt;/span&gt;
&lt;span class="nv"&gt;FORCE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;bash remediation_20240315T142301Z.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;7. Configurable Thresholds&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All analysis parameters are tunable via &lt;code&gt;.env&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;LOOKBACK_DAYS&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;30                  # analyze last 30 days instead of 14&lt;/span&gt;
&lt;span class="py"&gt;UTIL_REDUCE_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;25          # be more aggressive on reductions&lt;/span&gt;
&lt;span class="py"&gt;UTIL_INCREASE_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;85        # be more conservative on increases&lt;/span&gt;
&lt;span class="py"&gt;SAFETY_BUFFER_FACTOR&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;1.30         # add 30% headroom instead of 20%&lt;/span&gt;
&lt;span class="py"&gt;MIN_INVOCATIONS&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;20                # skip functions with &amp;lt; 20 samples&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. JSON Reports for Automation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All analysis output is available in JSON for downstream automation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"meta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"generated_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2024-03-15 14:23:01 UTC"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"region"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"us-east-1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lookback_days"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;14&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"summary"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"over_provisioned"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"total_savings_mb"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1152&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"functions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"function_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"payment-processor"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"allocated_mb"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"recommended_mb"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"over_provisioned"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"risk_score"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Real-World Impact
&lt;/h2&gt;

&lt;p&gt;Let’s talk numbers. We ran Lambda Rightsizer against a mid-sized production account (60 functions, us-east-1):&lt;/p&gt;

&lt;p&gt;MetricBeforeAfterTotal allocated memory31,680 MB18,240 MBOver-provisioned functions180Estimated annual spend$4,200$2,400Savings — $1,800/year&lt;/p&gt;

&lt;p&gt;That’s from a single region. Multi-region accounts often see $5,000–$10,000 annual savings.&lt;/p&gt;

&lt;p&gt;Better still: three of the originally under-provisioned functions actually improved reliability. Increased memory allocation reduced timeout events by 40%.&lt;/p&gt;




&lt;h2&gt;
  
  
  Getting Started in 5 Minutes
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Clone and install&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &amp;lt;repo&amp;gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;lambda-rightsizer
python &lt;span class="nt"&gt;-m&lt;/span&gt; venv .venv
&lt;span class="nb"&gt;source&lt;/span&gt; .venv/bin/activate  &lt;span class="c"&gt;# Windows: .venv\Scripts\activate&lt;/span&gt;
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Set up IAM&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Attach the provided read-only policy to your analysis identity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"LambdaDiscoverFunctions"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"lambda:ListFunctions"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"CloudWatchLogsInsights"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"logs:StartQuery"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"logs:GetQueryResults"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"arn:aws:logs:*:*:log-group:/aws/lambda/*"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Sid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"CloudWatchMetrics"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cloudwatch:GetMetricStatistics"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For remediation, add the second policy to a separate role that’s only assumed when applying changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Configure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Copy &lt;code&gt;.env.example&lt;/code&gt; to &lt;code&gt;.env&lt;/code&gt; and edit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="py"&gt;AWS_REGION&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;us-east-1&lt;/span&gt;
&lt;span class="py"&gt;AWS_PROFILE&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;default&lt;/span&gt;
&lt;span class="py"&gt;LOOKBACK_DAYS&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;14&lt;/span&gt;
&lt;span class="py"&gt;OUTPUT_DIR&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;./output&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Run the analysis&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; lambda_rightsizer.main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No changes are made. You’ll get a colorized console report + CSV + JSON + remediation scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Review and apply&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;output/20240315T142301Z/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Preview what would change&lt;/span&gt;
&lt;span class="nv"&gt;DRY_RUN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;bash remediation_20240315T142301Z.sh
&lt;span class="c"&gt;# Apply the changes&lt;/span&gt;
bash remediation_20240315T142301Z.sh
&lt;span class="c"&gt;# If anything goes wrong, instantly rollback&lt;/span&gt;
bash rollback_20240315T142301Z.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it.&lt;/p&gt;




&lt;h2&gt;
  
  
  Safety Guarantees Built In
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Read-Only by Default&lt;/strong&gt;&lt;br&gt;
Running the analysis tool makes zero AWS API calls that modify state. It only reads.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pre-Change Summary&lt;/strong&gt;&lt;br&gt;
The generated bash script prints out every change before asking for confirmation. You can see exactly what will happen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;DRY_RUN Mode&lt;/strong&gt;&lt;br&gt;
Preview all changes without touching anything:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;DRY_RUN&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true &lt;/span&gt;bash remediation_20240315T142301Z.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Risk Scoring&lt;/strong&gt;&lt;br&gt;
High-risk recommendations are flagged and require explicit per-function confirmation, even in automated deployments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Immediate Rollback&lt;/strong&gt;&lt;br&gt;
Every applied change can be undone in seconds with the companion rollback script and backup JSON.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;20% Safety Headroom&lt;/strong&gt;&lt;br&gt;
The tool never recommends below peak observed memory × 1.20, rounded to the nearest 64 MB. This protects against cold-start spikes and statistical outliers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No Destructive Side Effects&lt;/strong&gt;&lt;br&gt;
Changing Lambda memory allocation does not redeploy code, modify environment variables, change IAM roles, or affect VPC settings. It takes effect on the next cold start.&lt;/p&gt;


&lt;h2&gt;
  
  
  Why We Built This (And What We Learned)
&lt;/h2&gt;

&lt;p&gt;We realized that cost optimization is only possible at scale. One function? Easy to analyze manually. Fifty functions? You need tooling. Two hundred functions? You &lt;em&gt;must&lt;/em&gt; automate.&lt;/p&gt;

&lt;p&gt;The other lesson: safety first. Teams won’t adopt an optimizer that requires blind faith. Every recommendation needs context, risk scoring, and an escape hatch. Rollback is not an afterthought — it’s a core feature.&lt;/p&gt;

&lt;p&gt;We also learned that flexibility matters. Different teams have different risk tolerances. Some want aggressive optimization; others prefer conservative 30% headroom. The tool needed to support both via configuration, not code rewrites.&lt;/p&gt;

&lt;p&gt;Finally: data quality is everything. We built three fallback strategies for metrics collection because real-world Lambda deployments vary wildly. New functions have no history. Old functions have rotated logs. Some never use CloudWatch Logs at all. A production tool needs to degrade gracefully, not fail.&lt;/p&gt;


&lt;h2&gt;
  
  
  Future Enhancements
&lt;/h2&gt;

&lt;p&gt;We’re actively working on:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cost projection module — estimate AWS bill impact of recommended changes before applying&lt;/li&gt;
&lt;li&gt;Concurrent execution analysis — factor in concurrent execution reservations into recommendations&lt;/li&gt;
&lt;li&gt;Duration analysis — recommend compute-optimized runtimes alongside memory changes&lt;/li&gt;
&lt;li&gt;Cost anomaly detection — flag functions with sudden cost spikes&lt;/li&gt;
&lt;li&gt;Multi-region orchestration — apply changes across regions in a single command with per-region rollback&lt;/li&gt;
&lt;li&gt;Slack / PagerDuty integration — notify teams when optimization opportunities exceed a threshold&lt;/li&gt;
&lt;li&gt;RI / Savings Plan leverage — factor in reserved capacity into recommendations&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Open Source &amp;amp; Contribution
&lt;/h2&gt;

&lt;p&gt;Lambda Rightsizer is open source. We welcome contributions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bug reports and feature requests&lt;/li&gt;
&lt;li&gt;Additional data collection strategies&lt;/li&gt;
&lt;li&gt;Integration with other AWS cost tools (CloudCraft, Infracost, etc.)&lt;/li&gt;
&lt;li&gt;Regional pricing data expansion&lt;/li&gt;
&lt;li&gt;Language pack translations&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;AWS Lambda over-provisioning is real, widespread, and fixable. But manual optimization doesn’t scale.&lt;/p&gt;

&lt;p&gt;Lambda Rightsizer changes the equation: automated discovery, safe analysis, and ready-to-apply remediation, with built-in rollback and risk scoring.&lt;/p&gt;

&lt;p&gt;In a typical account, you can find $2,000–$10,000 in annual savings in 30 minutes. More importantly, you’ll gain visibility into how your functions actually behave in production — and that visibility is worth more than the cost savings.&lt;/p&gt;

&lt;p&gt;Stop leaving money on the table. Get started today:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone &amp;lt;repo&amp;gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;lambda-rightsizer
python &lt;span class="nt"&gt;-m&lt;/span&gt; lambda_rightsizer.main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run one remediation script.&lt;/p&gt;

&lt;p&gt;Your CFO will thank you.&lt;/p&gt;




&lt;h2&gt;
  
  
  Questions?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Documentation: See the full &lt;a href="https://github.com/rushabh-ufo/lambda-rightsizer" rel="noopener noreferrer"&gt;README &lt;/a&gt;for detailed configuration options, architecture diagrams, and troubleshooting&lt;/li&gt;
&lt;li&gt;Examples: Check output/ for sample reports and scripts from real-world runs&lt;/li&gt;
&lt;li&gt;Issues: Open a &lt;a href="https://github.com/rushabh-ufo/lambda-rightsizer" rel="noopener noreferrer"&gt;GitHub &lt;/a&gt;issue or PR with questions, bugs, or feature requests&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Connect Me
&lt;/h2&gt;

&lt;p&gt;Follow me on &lt;a href="https://www.linkedin.com/in/rushabh-trivedi-361094168/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you like this give a star on the &lt;a href="https://github.com/rushabh-ufo/lambda-rightsizer" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>aws</category>
      <category>performance</category>
      <category>devops</category>
    </item>
    <item>
      <title>Serverless Security: Building Trust in the Cloud</title>
      <dc:creator>Rushabh Trivedi</dc:creator>
      <pubDate>Fri, 30 May 2025 12:51:42 +0000</pubDate>
      <link>https://dev.to/rushabh_ufo/serverless-security-building-trust-in-the-cloud-h5m</link>
      <guid>https://dev.to/rushabh_ufo/serverless-security-building-trust-in-the-cloud-h5m</guid>
      <description>&lt;p&gt;Recently I got an awesome opportunity to speak in the Devloper talks at AWS Summit Bangaluru-2025. I had applied for the talk and luckily my talk was selected. Now the real struggle starts - gathering all the scattered thoughts from your mind, relate them and finally put them in a presentable format which you can explain in a very leyman's  terms.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0q1da3q3zeh2xuj3do4.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw0q1da3q3zeh2xuj3do4.jpg" alt="Image description" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would like to compile the talk here in a blog.&lt;/p&gt;

&lt;p&gt;There are few key aspects in the serverless security which need to be covered to make a secure application. we need to consider security at different layers of your application.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Identity and Access Management (IAM)&lt;/li&gt;
&lt;li&gt;API gateway&lt;/li&gt;
&lt;li&gt;Lambda Function&lt;/li&gt;
&lt;li&gt;Data&lt;/li&gt;
&lt;li&gt;Monitoring and Logging&lt;/li&gt;
&lt;li&gt;DDoS Protection&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Security in serverless isn't about protecting servers - it's about protecting identities, permissions, and the code itself.&lt;br&gt;
 - Chris Munnas&lt;br&gt;
AWS Serverless Specialist&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before diving deep into the details, lets have a look at where does the usage of the serverless services stands today.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3ybpfr86dmj3u456f23.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc3ybpfr86dmj3u456f23.png" alt="Image description" width="800" height="309"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's understand the unique security considerations which makes the security in the serverless much different and tricky than the conventional systems with servers.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F58zykb721im03k6q5ia6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F58zykb721im03k6q5ia6.png" alt="Image description" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's explore each aspect in above image one by one in details.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Short Lived Execution of Lamda Function&lt;/strong&gt; - The Lambda functions are ephemeral by nature. They spin-up quickly when invoked and vanish off once execution is done. This makes harder to maintain a stateful security controls and brings down a security implication that the attacks need to be detected fast. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Increased Surface Area &lt;/strong&gt;- Typically a serverless app contains too many small, purpose build functions (usually known as microservices). This results in a broader attack surface which increases chances of misconfigured permissions, unpatched dependencies etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Event-Driven Nature&lt;/strong&gt; -  Functions are invoked by various events like API gateway, S3, SNS etc. Any misconfigured even can lead to a security issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dependency on Managed Service&lt;/strong&gt; - A typical serverless application uses multiple managed services like dynamoDB, API gateway, S3, SQS, SNS. In case if we fail to configure the permissions properly can lead to un-intended data access/Excessive privilege exposure.&amp;nbsp;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Tenant Risks&lt;/strong&gt; - In a multi-tenant environment, there are chances that the data is stored on a shared storage like a same dynamodb table or a common s3 bucket. Failure on managing permissions properly can lead to exposing the data of one tenant to another.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now having the base set for the detailed understanding on various security aspects, lets have a walk through on security at service level.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Identity and Access Management (IAM)&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Principle of Least Privilege&lt;/strong&gt; - Assign roles and policies to each Lambda function. Also you want to ensure that the function has access to the resources only which it needs. Avoid sharing roles across functions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;IAM Role Scoping&lt;/strong&gt; - Scope IAM roles narrowly and specifically to the function's purpose. Avoid using wildcards '*' unless necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom IAM Policies&lt;/strong&gt; - Avoid using managed policies from the IAM. Create custom tailored policies.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Use tools like AWS Access Analyzer and IAM Access Advisor to audit and optimize permissions continuously.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now your permissions are all set! next comes is the API Gateway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Gateway&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;There are many key areas on which you can apply security for securing the API gateway. I will not cover all here just to keep this blog small and precise.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lambda Authorizer&lt;/strong&gt; - You can evaluate token, Generate allow/Deny policy, and optionally populate the context attributes in the request context.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;API keys and usage plans&lt;/strong&gt; - now your authorized users are coming into the system, but there are chances that some of the authorized users can make thousands of API callas and would hamper overall performance of your system or may cause un-availability of the services. you can define API keys for each of your tenant and associate them with the usage plans - say this API key is eligible for 100 request/day&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;OAuth and OpenId Connect&lt;/strong&gt; - For more advanced authentication scenarios, you can use OAuth 2.0 or OpenID Connect (OIDC) via Amazon Cognito&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Lambda Function&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Principal of Least Privilege&lt;/strong&gt; - Assign minimal IAM permissions to Each Lambda. Avoid using wildcards like s3:* or dynamodb:*.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Patch Dependencies and Libraries​&lt;/strong&gt; - Regularly update function's dependencies. Use tools like npm audit, pip-audit, or Snyk to detect vulnerabilities.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;3.&lt;strong&gt;Secure Environment Variables&lt;/strong&gt; - Do not hardcode environment variables rather use the secrets manager and KMS.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Log Everything&lt;/strong&gt; - Enable CloudWatch Logs and use AWS X-Ray for tracing. Use CloudTrail to track changes to Lambda and IAM policies. Set up Amazon GuardDuty for real-time threat detection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Timeouts and Memory Limits&lt;/strong&gt; - smartly set the timeouts and the memory limits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network Security with VPC Integration​&lt;/strong&gt; - For sensitive workload, prefer to run the Lambda functions inside thr VPC.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Code Signing&lt;/strong&gt; - Implement code signing to verify that the code is not tempered.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Data Security&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You have reached to the lambda, now lambda is generating/fetching data into an end system. You need to have a layer of security there on the data also.&lt;/p&gt;

&lt;p&gt;Primarily there are 2 main aspects of the data security&amp;nbsp;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Encryption&lt;/li&gt;
&lt;li&gt;Secure storage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Encryption can be applied at 2 level, at rest and in transit - apply KMS keys to encrypt data at rest and https/sftp to secure data in transit&lt;/p&gt;

&lt;p&gt;Apply strict access policies and IAM permissions to protect data in the storage&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Monitoring &amp;amp; Logging&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Observability is always a key aspect in any system epecially when you have such a event-driven and widely distributed system.&lt;br&gt;
AWS has a suite of services at your rescue.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS CloudTrail&lt;/strong&gt; - Tracks AWS API calls (Lambda, API Gateway, etc.)&lt;br&gt;
Detects who invoked a Lambda, when, and from where - critical for compliance and incident response.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Amazon Cloudwatch Logs&lt;/strong&gt; - Enable Lambda logging through CloudWatch. This helps troubleshoot errors, performance bottlenecks, and anomalies.&amp;nbsp;&lt;br&gt;
Capture logs and set alarms based on the - High error rates, long execution duration, timeouts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CloudWatch Metrics&lt;/strong&gt; - Monitor Lambda performance. Detect failures and address issues proactively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;GuardDuty&lt;/strong&gt; - Enable GuardDuty for continuous monitoring of malicious activities and security threats.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;DDoS Protection&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS WAF&lt;/strong&gt; - Use AWS WAF to protect your APIs (via API Gateway) from common web exploits such as SQL injection and cross-site scripting (XSS). It also helps in blocking malicious traffic.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS Shield&lt;/strong&gt; - AWS Shield provides protection against DDoS attacks. It's important to leverage AWS Shield Advanced for more advanced DDoS protections.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rate Limiting&lt;/strong&gt; - Set up rate limiting and quotas in API Gateway to protect against abuse and mitigate the risk of DDoS attacks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Its awesome if you have been with me and have gone through this big blog. I know there is a lot to understand and digest here. I am summarizing the checklist here for you.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use least privilege IAM&lt;/li&gt;
&lt;li&gt;Regularly rotate the credentials&lt;/li&gt;
&lt;li&gt;Enable observability where ever possible&lt;/li&gt;
&lt;li&gt;Encrypt everything you can&lt;/li&gt;
&lt;li&gt;Protect endpoints and validate inputs&lt;/li&gt;
&lt;li&gt;Manage your secrets properly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is a sample serverless application architecture you can refer where I have tried to add security at all possible level&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bab1tdjzlot6g9j3zj1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bab1tdjzlot6g9j3zj1.png" alt="Image description" width="800" height="377"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading and support. Do add comments for suggestions/improvements/discussions. I would be happy to connect with you awesome people.&lt;/p&gt;

&lt;p&gt;You can connect with me on my &lt;a href="https://www.linkedin.com/in/rushabh-trivedi-361094168/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>serverless</category>
      <category>lambda</category>
      <category>apigateway</category>
      <category>security</category>
    </item>
  </channel>
</rss>
