<?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 Eve Maina on Medium]]></title>
        <description><![CDATA[Stories by Eve Maina on Medium]]></description>
        <link>https://medium.com/@eve.maina?source=rss-1adc1ec00478------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*6SbhB0KnpWGrsojVsPisTw.jpeg</url>
            <title>Stories by Eve Maina on Medium</title>
            <link>https://medium.com/@eve.maina?source=rss-1adc1ec00478------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 18:06:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@eve.maina/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[From An Instance to The Internet and Back: The Life of a Data Packet in AWS]]></title>
            <link>https://medium.com/@eve.maina/from-an-instance-to-the-internet-and-back-the-life-of-a-data-packet-in-aws-3dfe5e3eb214?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/3dfe5e3eb214</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 14:24:01 GMT</pubDate>
            <atom:updated>2026-10-31T17:19:42.890Z</atom:updated>
            <content:encoded><![CDATA[<h4>A step-by-step look at what happens to your data packet in a public and private subnet.</h4><p>Welcome to part three of my AWS Networking series!</p><p>If you missed out, here is <a href="https://medium.com/@eve.maina/networking-101-the-building-blocks-of-aws-networking-52e475840d94">networking 101</a> where I covered the basic building blocks of AWS networking and <a href="https://medium.com/@eve.maina/networking-102-scaling-traffic-in-aws-41227da3cee5">networking 102</a> where I explained how to scale traffic with Auto Scaling and Load Balancers.</p><p>This time, we go one level deeper. We know a private subnet needs a NAT Gateway to reach the internet, but why can’t it use the Internet Gateway directly?</p><p>By the end of this post, you’ll be able to explain exactly what happens to a packet at every hop.</p><p>In this post, we’ll follow the packet from the instance all the way to the web server and back, covering:</p><ol><li><strong>The public subnet journey:</strong> how a packet travels from an instance in a public subnet, through the Internet Gateway, to a web server on the internet.</li><li><strong>Why a private instance can’t use the Internet Gateway:</strong> what’s missing, even if you add the route.</li><li><strong>The private subnet journey:</strong> how the same packet gets out through a NAT Gateway, and how the reply finds its way back.</li></ol><p>We’ll basically be answering the question “What happens when i run sudo apt update on an instance in a public subnet and one in a private subnet?”</p><p>Let’s get right into it!</p><h4>The Set-up</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FyNK6Jb-QBZMGmES7ES91w.png" /><figcaption>Architecture Diagram</figcaption></figure><p>Before we follow any packets, let’s define the network we’ll use for every example in this post. Keep this section handy, because we’ll refer back to these addresses at each hop.</p><ol><li><strong>The VPC: </strong>We have one VPC with the CIDR block 10.0.0.0/16. That gives us the private address range 10.0.0.0 to 10.0.255.255 to divide up.</li><li><strong>The subnets: </strong>We split the VPC into two subnets:</li></ol><ul><li><strong>Public subnet:</strong> 10.0.1.0/24</li><li><strong>Private subnet:</strong> 10.0.2.0/24</li></ul><p>3. <strong>EC2 instances: </strong>We have an instance in every subnet:</p><ul><li><strong>Instance A</strong> is in the public subnet and has both a private and a public IP.</li><li><strong>Instance B</strong> is in the private subnet and has only a private IP.</li></ul><p>4. <strong>Public</strong> <strong>NAT Gateway: </strong>is in the public subnet and has an Elastic IP.</p><p>5. <strong>archive.ubuntu.com</strong> is the web server on the internet. It’s not a single machine, as DNS returns several addresses, so we’ll use 91.189.91.83 as our example.</p><h3>Journey 1: The Public Subnet</h3><p>We run the command on <strong>Instance A</strong> (private IP 10.0.1.10, public IP 54.1.2.3).</p><h4>Step 1: DNS lookup</h4><p>Before any packet goes to the web server, apt needs an IP address for archive.ubuntu.com.</p><p>The instance asks the <strong>VPC DNS resolver</strong>, which lives inside the VPC (at the VPC base address plus 2, so 10.0.0.2 here), and gets back 91.189.91.83. This lookup never leaves the VPC, so it doesn’t use the Internet Gateway.</p><h4>Step 2: The instance builds the packet</h4><p>apt opens a connection to the web server on port 80. The instance’s operating system picks a random ephemeral source port for the connection and builds the packet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0roYukj9fDk3XMMOIAs1IQ.png" /><figcaption>packet built by instance</figcaption></figure><p>Notice the source is a <strong>private</strong> IP. This is because<strong> an instance only ever knows its private ip</strong> located in the ENI (Elastic Network Interface) which is a virtual card that connects an instance to a vpc.</p><p>Key Components of an ENI:</p><ul><li><strong>Private IPv4 Address:</strong> One primary private IP (and optional secondary private IPs).</li><li><strong>Public IP / Elastic IP:</strong> Optional public-facing or static elastic IP addresses.</li><li><strong>MAC Address:</strong> A unique hardware address assigned to the interface.</li><li><strong>Security Groups:</strong> One or more firewall rules attached directly to the interface to control inbound and outbound traffic.</li><li><strong>Source/Destination Check Flag:</strong> A check that ensures the instance is the source or destination of any traffic it sends or receives (can be disabled for network appliances like firewalls).</li></ul><p>Run ip a on Instance A and you’ll only see 10.0.1.10. The public IP 54.1.2.3 is not on the instance at all.</p><p>So where does it live?</p><p>In the <strong>AWS control plane</strong>, the management layer that stores the facts about your VPC such as:which network interfaces exist, which private IPs they own, which public IPs are attached to them and what your route tables say. The control plane doesn’t carry your traffic. It holds the rules, and the network (the <strong>data plane</strong>) follows them.</p><p>When AWS attached 54.1.2.3 to this instance, it recorded one entry: 10.0.1.10 is linked to 54.1.2.3.</p><p>We’ll see in Step 4 how the Internet Gateway uses that record.</p><h4>Step 3: The route table decides where it goes</h4><p>The packet leaves the instance and AWS checks the public subnet’s route table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*HccLzunCXZ3w3U_mtVdKRA.png" /><figcaption>igw-outbound-translation</figcaption></figure><p>The destination 91.189.91.83 is not inside 10.0.0.0/16, so the local route doesn’t match. The 0.0.0.0/0 route matches everything else, so the packet is sent to the <strong>Internet Gateway(IGW)</strong></p><h4>Step 4: The Internet Gateway translates the source address</h4><p>The Internet Gateway looks up the network interface that sent the packet and finds its public IP: 10.0.1.10 maps to 54.1.2.3.</p><p>The source address has to change because 10.0.1.10 is a private IP and private addresses are not routable on the internet. Routers on the internet would drop the packet, or the server’s reply would never find its way back. Only a public IP can be used for the round trip.</p><p>It swaps the source address and sends the packet to the internet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YhK2xdFek3gnK0t8QgJZaA.png" /></figure><p>Two things to notice:</p><ul><li>Only the <strong>source IP</strong> changed. The destination stayed the same.</li><li>The <strong>port didn’t change at all</strong>. The IGW does a one-to-one translation of IP addresses. Because that public IP belongs to exactly one instance, there’s nothing to tell apart, so there’s no reason to touch ports.</li></ul><h4>Step 5: The web server replies</h4><p>The Ubuntu server sees a request from 54.1.2.3:50432. It has no idea the instance’s real address is 10.0.1.10. It processes the request and sends the reply back to the address it was given (in this case the software packages):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wB1E_utOh3lhI8t5QYQD9Q.png" /><figcaption>web server response</figcaption></figure><h4>Step 6: The Internet Gateway translates it back</h4><p>The reply arrives at the IGW, which finds that 54.1.2.3 belongs to the network interface with private IP 10.0.1.10. It swaps the destination and delivers the packet into the VPC:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AnzafM7gV2dctSPHFimvfQ.png" /><figcaption>ip address comparison</figcaption></figure><p>The packet reaches Instance A, the operating system matches port 50432 to the apt process that opened the connection, and the package list starts downloading.</p><h4>What makes this work</h4><p>For this to succeed, <strong>two things must be true together</strong>:</p><ol><li>The subnet’s route table has a route to the IGW (0.0.0.0/0 -&gt; igw-1234).</li><li>The instance has a <strong>public IP</strong>, so the IGW has an address to translate to.</li></ol><p>Remove either one and the packet never gets out. Hold on to that, because it explains the next section.</p><p><strong><em>Note on security groups:</em></strong><em> The instance’s security group must allow outbound traffic on port 80. Security groups are stateful, so the reply is allowed back in automatically.</em></p><h3>Journey 2: The Private Subnet</h3><p>Now we run the same command on <strong>Instance B</strong> (10.0.2.10), which sits in the private subnet and has <strong>no public IP</strong>.</p><h4>Step 1: DNS lookup</h4><p>Same as before. Instance B asks the VPC DNS resolver for archive.ubuntu.com and gets 91.189.91.83. This lookup stays inside the VPC, so it works even when the instance has no path to the internet.</p><h4>Step 2: The instance builds the packet</h4><p>apt opens a connection on port 80, and the operating system picks a random source port:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KKW84sRcyHMYmlOzGemkFg.png" /><figcaption>packet built by instance</figcaption></figure><p>As with Instance A, the source is a private IP. The difference is that there’s <strong>no public IP</strong> linked to this instance, so the IGW would have nothing to translate it to.</p><h4>Step 3: The route table sends it to the NAT Gateway</h4><p>The private subnet’s route table is checked:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*pqWeMS4YUGKVldO6JePu4Q.png" /><figcaption>private subnet’s route table</figcaption></figure><p>The destination isn’t inside 10.0.0.0/16, so the 0.0.0.0/0 route matches and the packet goes to the <strong>NAT Gateway</strong>, not the IGW.</p><h4>Step 4: The NAT Gateway translates the source (private to private)</h4><p>The NAT Gateway replaces the instance’s address and port with <strong>its own private IP</strong> and a port it chooses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AGpcNBHcetl-9WurFcDr9g.png" /><figcaption>nat gateway translation</figcaption></figure><p>It also records the swap in its <strong>connection table</strong>, so it can reverse it later. This process is called <strong>connection tracking.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_OgviAxhf-FCpgwrkbG2bw.png" /><figcaption>connection tracking entry</figcaption></figure><p>Notice that this translation is <strong>private to private</strong>. The NAT Gateway only knows its own private IP, just like any other network interface. The packet is still inside the VPC and still can’t travel on the internet.</p><p><strong>Why change the port?</strong></p><p>Many private instances share this one NAT Gateway, and each picks its source port independently. Two of them could choose 40000 at the same time. Because they all leave with the same IP from the NAT, the port is what tells the connections apart, so each connection gets its own entry in the table. The port 1024 here is illustrative. What’s guaranteed is that two live connections never share the same entry.</p><h4>Step 5: The route table sends it to the IGW</h4><p>The packet now leaves the NAT Gateway, so AWS checks the route table of the subnet the NAT Gateway lives in, which is the <strong>public</strong> subnet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*HccLzunCXZ3w3U_mtVdKRA.png" /><figcaption>public subnet’s route table</figcaption></figure><p>0.0.0.0/0 points to the IGW, so the packet goes there. This is why the NAT Gateway must be in a public subnet.</p><h4>Step 6: The Internet Gateway translates the source (private to public)</h4><p>The control plane has a record linking the NAT Gateway’s private IP to its Elastic IP: 10.0.1.50 to 52.9.9.9. The IGW uses it, exactly as it did for Instance A:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LastF8H3i2a41fgoP0luLA.png" /><figcaption>ip address comparison</figcaption></figure><h4>Step 7: The web server replies</h4><p>The Ubuntu server sees a request from 52.9.9.9:1024. It knows nothing about Instance B.</p><p>It processes the request and sends the reply back to the address it was given (in this case the software packages):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Uhg8IWf-pI4JpDoAOM4Ofg.png" /><figcaption>web server response</figcaption></figure><h4>Step 8: The Internet Gateway translates it back</h4><p>The IGW maps the nat gateway’s private IP Address to it’s elastic address:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RuVm7-gsUMzTivZAxQj1uw.png" /><figcaption>igw-translation</figcaption></figure><h4>Step 9: The NAT Gateway translates it back</h4><p>The NAT Gateway looks up 10.0.1.50:1024 in its connection table, finds that it belongs to 10.0.2.10:40000, rewrites the destination and forwards the packet over the local route:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BDGGquoN0P4CyB2h_Nb1UQ.png" /><figcaption>nat-translation</figcaption></figure><p>Instance B receives the reply from 91.189.91.83:80, as if it had spoken to the server directly, and the package list downloads.</p><h4>Why unsolicited traffic can’t get in</h4><p>If someone on the internet sends a packet to 52.9.9.9:1024, the NAT Gateway checks its connection table.</p><p>Entries are only created when an instance <strong>starts</strong> a connection, so a packet with no matching entry is dropped. This is what keeps the private subnet reachable only from the inside. Idle entries also expire, so very long idle connections can drop, which is why keep-alives help.</p><h3>Why a private instance can’t use the Internet Gateway</h3><p>We’ve seen both journeys, so the question is clearer now: <strong>what if Instance B simply used the Internet Gateway like Instance A?</strong></p><p>Let’s try it. Imagine we add a route to the private subnet’s route table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*HccLzunCXZ3w3U_mtVdKRA.png" /><figcaption>Private Subnet’s Route Table</figcaption></figure><p>Now Instance B runs sudo apt update, and the packet follows the same path as Instance A’s:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nDb_NH-32xFcTNY8sBBqpw.png" /><figcaption>instance packet</figcaption></figure><p>The route table sends it to the IGW.</p><p>The IGW looks for the public IP linked to 10.0.2.10, and <strong>there isn’t one</strong>. Instance B has no public IP, so the IGW has no address to put in the source field. The packet can’t be translated, so it can’t go anywhere, and apt hangs until it times out.</p><p>For an instance to use the Internet Gateway, <strong>both</strong> of these must be true:</p><ol><li>The subnet’s route table has a <strong>route to the IGW</strong>.</li><li>The instance’s network interface has a <strong>public IP</strong> (auto-assigned or an Elastic IP).</li></ol><p>The route gets the packet to the IGW. The public IP gives the IGW something to translate it to.</p><p>Remember, the instance only knows its private address, so the IGW depends on the record in the control plane to know which public address belongs to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MkMSkHDzC4cKVHWR0F5ABQ.png" /><figcaption>Summary table</figcaption></figure><h3>Conclusion</h3><p>Here’s a summary table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G_68aKmYiHmCVGOaY8AqbQ.png" /><figcaption>Summary table</figcaption></figure><p>If you remember one sentence, make it this one: <strong>the Internet Gateway needs a public IP to translate to, and the NAT Gateway is how a private instance borrows one.</strong></p><p>Now you know the journey a packet takes from your instance to the web and back.</p><p>In the next post, we’ll put that knowledge to work and troubleshoot common networking problems in AWS, working backward from “it doesn’t work” to the root cause, one hop at a time.</p><p>Thanks for reading. See you in the next one.</p><p>Adios! 🤗</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3dfe5e3eb214" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pin It or Break It: Versioning Terraform Modules the Right Way]]></title>
            <link>https://medium.com/@eve.maina/pin-it-or-break-it-versioning-terraform-modules-the-right-way-b4f8c8e5e35a?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4f8c8e5e35a</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Wed, 09 Sep 2026 08:15:30 GMT</pubDate>
            <atom:updated>2026-09-09T08:30:43.053Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hdWY60sEdaXuz0mjTX0qAw.png" /></figure><p>A module that only exists as a local folder path is not actually reusable, it just looks reusable. The moment you share it with a teammate, or split your own environments across dev and production, “reusable” starts to mean something specific: can two different callers depend on two different, known, stable copies of the same module at the same time. A local path can’t answer that question. A versioned one can.</p><p>This is what turns a module from a folder of .tf files into something a team can actually build on top of.</p><p>Code for this post: <a href="https://github.com/Eve-maina/terraform-30-day-challenge/tree/main/Day-09">terraform-30-day-challenge, Day 09</a></p><h3>Why a local module source stops working</h3><p>When a module is called with a plain relative path, there is only ever one copy of it, whatever is currently sitting on disk. If you edit the module to fix something for dev, production picks up that exact same edit the next time it runs terraform init, whether it&#39;s ready for it or not.</p><p>There&#39;s no way to say &quot;production is still on the version I tested last week&quot; if there is only ever one version that exists.</p><p>The fix isn’t a different file structure. It’s <strong>Git tags</strong>.</p><h3>Three ways a module breaks without ever throwing an error</h3><p>Before tagging anything, it’s worth knowing the mistakes that don’t show up as an error message. Terraform applies fine, and the bug only shows up later, usually in whichever environment you didn’t test in first.</p><ol><li><strong>File paths resolve relative to the caller, not the module.</strong></li></ol><p>When you run terraform apply, Terraform treats the directory you ran it from as &quot;where I am,&quot; and resolves every relative path in every file, no matter which file actually wrote that path, starting from there.</p><p>So a reference like ./user-data.sh written inside a module doesn&#39;t mean &quot;the file sitting next to this code.&quot; It means &quot;relative to wherever terraform was actually run from,&quot; which is the root config, not the module&#39;s own folder.</p><p>Say the module lives at modules/services/webserver-cluster/ and is called from live/dev/services/webserver-cluster/.</p><p>Writing ./user-data.sh inside the module&#39;s main.tf sends Terraform looking for that file inside live/dev/services/webserver-cluster/, since that&#39;s the directory terraform apply was run from, not inside the module where the script actually is. The file silently can&#39;t be found, or worse, a different file with the same name in the wrong folder gets picked up instead.</p><p>path.module fixes this by always resolving to the folder the current code is actually written in, no matter where terraform apply was run from:</p><pre>user_data = templatefile(&quot;${path.module}/user-data.sh&quot;, {<br>  server_port = var.server_port<br>})</pre><p>This always resolves to modules/services/webserver-cluster/user-data.sh, whether the module gets called from live/dev/, live/production/, or anywhere else.</p><p>./ means relative to the terminal. path.module means relative to the file. A module gets called from many different places, so its internal file references should only ever depend on the second one.</p><p><strong>2.Inline blocks and standalone resources fight over the same configuration.</strong></p><p>Some AWS resources let you configure the same thing two ways. aws_security_group accepts inline ingress blocks directly:</p><pre>resource &quot;aws_security_group&quot; &quot;cluster_sg&quot; {<br>  name   = &quot;webserver-cluster-sg&quot;<br>  vpc_id = var.vpc_id<br>  ingress {<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}</pre><p>Or the same rule can be declared as its own standalone resource instead, pointing back at the security group by ID:</p><pre>resource &quot;aws_security_group&quot; &quot;cluster_sg&quot; {<br>  name   = &quot;webserver-cluster-sg&quot;<br>  vpc_id = var.vpc_id<br>}<br>resource &quot;aws_security_group_rule&quot; &quot;allow_http&quot; {<br>  type              = &quot;ingress&quot;<br>  from_port         = 80<br>  to_port           = 80<br>  protocol          = &quot;tcp&quot;<br>  cidr_blocks       = [&quot;0.0.0.0/0&quot;]<br>  security_group_id = aws_security_group.cluster_sg.id<br>}</pre><p>Either one works on its own.</p><p>The problem is mixing them for the same security group, an inline ingress block in the module&#39;s main.tf, and then a caller (or another part of the module) also attaching a separate aws_security_group_rule to that same group. Terraform sees two different sources both trying to own that group&#39;s rule set, and on every plan it fights itself, adding and removing the same rule back and forth instead of converging.</p><p>Pick one pattern per module.</p><p>Separate resources are the better default, since they let callers add their own rules later without touching the module’s source, which the inline version doesn’t allow without editing the module itself.</p><p><strong>3. A module output inside depends_on drags the entire module along.</strong></p><p>Normally you never have to tell Terraform what order to build things in. If one resource’s config references another resource’s output, Terraform sees that reference and automatically builds the first one first.</p><p>depends_on only exists for the rare case where a resource genuinely needs another to exist first, but its own config never actually references any of that resource&#39;s attributes, so Terraform has no reference to follow and has to be told the order explicitly.</p><p>The trouble is that depends_on can only point at a whole object, never at just the part of it you actually need. A module is one object as far as depends_on is concerned, even though it might contain a dozen different resources inside it. So the moment you write this:</p><pre>resource &quot;aws_instance&quot; &quot;app_server&quot; {<br>  depends_on = [module.webserver_cluster]<br>}</pre><p>you’re not saying “wait for the cluster’s security group.” You’re saying “wait for every single resource this module creates, whatever they turn out to be.”</p><p>Think of it like being told to wait for a restaurant to open when all you actually needed was the kitchen ready.</p><p>Terraform will now hold app_server back until the ASG, the launch template, and the load balancer are all done too, even though app_server never touches most of those. And it keeps costing you after the first apply: if someone later changes something unrelated inside the module, say a tag on the load balancer, Terraform sees the whole module as &quot;changed,&quot; and app_server can get recreated for a change it had nothing to do with, purely because it was tied to the whole module instead of the one piece it needed.</p><p>It’s tempting to reach for a narrower fix, something like depends_on = [module.webserver_cluster.security_group_id], pointing at just the output you actually care about. That doesn&#39;t work. depends_on cannot take a module&#39;s output at all, only the module itself or another resource. There is no narrow version of depends_on for a module, which is the real gotcha here.</p><p>The actual fix is to sidestep depends_on entirely and let Terraform infer the dependency the normal way, by referencing the output directly inside a real argument:</p><pre>resource &quot;aws_instance&quot; &quot;app_server&quot; {<br>  vpc_security_group_ids = [module.webserver_cluster.security_group_id]<br>}</pre><p>The moment app_server references module.webserver_cluster.security_group_id in one of its own arguments, Terraform sees that reference and automatically waits on exactly the resource that produced it, nothing more. depends_on should only get reached for when there&#39;s genuinely no attribute to reference, no data actually flows between the two resources, but an ordering guarantee is still needed.</p><p>In that case, if what you depend on lives inside a module, you&#39;re stuck depending on the whole module, because depends_on has no way to reach into it. Granular outputs don&#39;t fix depends_on itself, they just mean you rarely need it in the first place, since there&#39;s almost always a real attribute to reference instead.</p><h3>Turning the module into a versioned release</h3><p>With the module pushed to its own repo, a Git tag is what gives it a first real version:</p><pre>git init<br>git add .<br>git commit -m &quot;Initial module release&quot;<br>git tag -a &quot;v0.0.1&quot; -m &quot;First release of webserver-cluster module&quot;<br>git remote add origin https://github.com/&lt;your-username&gt;/&lt;repo-name&gt;<br>git push origin main --tags</pre><p>The calling configuration then stops pointing at a folder and starts pointing at a specific, frozen commit:</p><pre>module &quot;webserver_cluster&quot; {<br>  source        = &quot;github.com/&lt;your-username&gt;/&lt;repo-name&gt;?ref=v0.0.1&quot;<br>  cluster_name  = &quot;webservers-dev&quot;<br>  instance_type = &quot;t3.micro&quot;<br>  min_size      = 2<br>  max_size      = 4<br>}</pre><p>The ?ref= is what changes everything. Without it, source means &quot;whatever is currently in the file.&quot; With it, source means one specific, citable release that will never quietly change underneath you.</p><h3>Same module, two pinned versions</h3><p>The real reason to version a module shows up once there’s more than one environment consuming it. After adding a new input variable to the module, tagging the change as v0.0.2, dev and production don&#39;t have to move together:</p><pre># live/dev/services/webserver-cluster/main.tf<br>module &quot;webserver_cluster&quot; {<br>  source        = &quot;github.com/&lt;your-username&gt;/&lt;repo-name&gt;?ref=v0.0.2&quot;<br>  cluster_name  = &quot;webservers-dev&quot;<br>  instance_type = &quot;t3.micro&quot;<br>  min_size      = 2<br>  max_size      = 4<br>}</pre><pre># live/production/services/webserver-cluster/main.tf<br>module &quot;webserver_cluster&quot; {<br>  source        = &quot;github.com/&lt;your-username&gt;/&lt;repo-name&gt;?ref=v0.0.1&quot;<br>  cluster_name  = &quot;webservers-production&quot;<br>  instance_type = &quot;t3.medium&quot;<br>  min_size      = 4<br>  max_size      = 10<br>}</pre><p>Dev tracks the newer tag, so the new variable actually gets exercised somewhere before anyone trusts it. Production stays on the version that’s already proven itself, and only moves forward on purpose. Running terraform init in each environment folder pulls exactly the tag that folder&#39;s config asks for, nothing is silently ahead of or behind the other.</p><h3>What makes a README actually good</h3><p>A module without a README is only usable by whoever wrote it, and only for as long as they remember writing it. A README earns its place once it covers:</p><ul><li><strong>What the module does</strong>, in a single paragraph, no more.</li><li><strong>Every input variable</strong>, with its type, description, and default if it has one.</li><li><strong>Every output</strong>, with a short description of what it hands back.</li><li><strong>A minimal usage example</strong>, showing the smallest working call to the module.</li><li><strong>Known limitations or gotchas</strong>, anything a caller would otherwise discover the hard way.</li><li><strong>Required provider versions</strong>, so a caller knows what it expects before running init.</li></ul><h3>What makes a module actually good</h3><p>Pulling all of this together, a module earns “good” once it can check off:</p><ul><li><strong>Does one thing.</strong> A web server cluster module shouldn’t also be quietly managing DNS.</li><li><strong>Sensible defaults, real flexibility.</strong> Only the values that genuinely differ per environment should be required.</li><li><strong>Granular outputs.</strong> Callers depend on the specific resource they need, not the module as a black box.</li><li><strong>Version pinned, always.</strong> Every environment references a tagged ?ref=, never a mutable branch.</li><li><strong>Paths resolved with path.module.</strong> So the module behaves the same no matter who’s calling it.</li><li><strong>One resource pattern, not two.</strong> No mixing inline blocks with standalone resources for the same config.</li><li><strong>Documented like someone else will use it.</strong> README covers inputs, outputs, usage, and gotchas in full.</li><li><strong>Proven in more than one environment.</strong> A module only tested in dev has only been tested once.</li><li><strong>Required provider versions</strong>, so a caller knows what it expects before running init.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4f8c8e5e35a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Broken Labs: VPC Lab 05, The Instance Was Never the Problem]]></title>
            <link>https://medium.com/@eve.maina/aws-broken-labs-vpc-lab-05-the-instance-was-never-the-problem-bdc5831f0899?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdc5831f0899</guid>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Tue, 08 Sep 2026 11:42:16 GMT</pubDate>
            <atom:updated>2026-09-08T11:42:16.122Z</atom:updated>
            <content:encoded><![CDATA[<p>Fifth lab in the <a href="https://www.cloudpathacademy.com/docs/aws/labs/vpc/">CloudPath Academy Broken Labs</a> series, and this one plays differently from the first four. Every previous lab described the same failure: the page won’t load.</p><p>This one is phrased differently, the web server is deployed in a custom VPC, but no URL is given in the stack Outputs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*UTRMBS4_WckP66PCBqilwQ.png" /></figure><h3>Starting where I always start</h3><p>Stack deployed with no errors. Before touching anything network-related, I went to the instance itself first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJCekA8uDFVkg-PLhd3wZA.png" /></figure><p>Status checks passing, instance healthy, and it had a public IP address assigned. Since the IP was right there, I tried it directly in the browser before assuming anything was actually broken.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ng80vzP8t1awv15X-cinoQ.png" /></figure><p>It loaded straight away. No timeout, no delay. So whatever the lab was pointing at as “broken,” it wasn’t reachability. Routing, security group, the instance itself, all of it was working.</p><h3>Noticing what was actually missing</h3><p>While I was still on the instance’s details panel, I noticed something: there was no public DNS name listed for it. Just the public IP, with the DNS name field empty.</p><p>That stood out because I already knew the stack’s WebPageURL output wasn&#39;t built from the IP:</p><pre>WebPageURL:<br>  Value: !Sub &quot;http://${LabInstance.PublicDnsName}/&quot;</pre><p>It was built from PublicDnsName.</p><p>If the instance genuinely had no DNS name assigned, that would explain everything, the IP itself would work perfectly, but the specific value the Outputs section needed to build the URL from would have nothing to draw on. That lined up with what I was seeing: a working server with a missing name.</p><h3>Going to where that name is actually controlled</h3><p>A public DNS hostname isn’t something set on the instance directly, it’s a VPC-level setting. I went to the VPC’s details and checked its DNS settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qceyMb3XgtzVKphASiHXNw.png" /></figure><p>DNS hostnames was turned off</p><pre>LabVPC:<br>  Type: AWS::EC2::VPC<br>  Properties:<br>    CidrBlock: 10.0.0.0/16<br>    EnableDnsSupport: true<br>    EnableDnsHostnames: false</pre><p>With that setting disabled, no instance in the VPC gets a public DNS hostname assigned, no matter what its public IP looks like. That’s exactly why the instance’s details page showed a populated IP and an empty DNS name field. And it’s exactly why PublicDnsName had nothing to give the !Sub output, resulting in a blank WebPageURL value in Outputs rather than a working link.</p><p>Worth noting the distinction between the two DNS settings sitting right next to each other in that template: EnableDnsSupport was true, which is what allows DNS resolution to function inside the VPC at all. EnableDnsHostnames is a separate, more specific setting, whether public-facing instances actually get a hostname assigned to go with their public IP. The first one being on doesn&#39;t imply the second one is.</p><h3>The fix</h3><p>Enabled EnableDnsHostnames on the VPC and updated the stack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bwuwywz3d4yIPls3oM5NJg.png" /></figure><p>Once that was on, the instance’s details page showed a real public DNS name where the field had been empty before, and Outputs finally populated WebPageURL with an actual value instead of leaving it blank.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7OaSks4B2LllFIXyA56bsw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdc5831f0899" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Broken Labs: VPC Lab 02, When the Allow Rule Never Gets a Chance]]></title>
            <link>https://medium.com/@eve.maina/aws-broken-labs-vpc-lab-02-when-the-allow-rule-never-gets-a-chance-3e12f0e25afb?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e12f0e25afb</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud-troubleshooting]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 09:58:26 GMT</pubDate>
            <atom:updated>2026-09-07T09:58:26.724Z</atom:updated>
            <content:encoded><![CDATA[<p>Second one in the <a href="https://www.cloudpathacademy.com/docs/aws/labs/vpc/lab-02-nacl/">CloudPath Academy Broken Labs</a> series. Same setup as before, a web server that should be reachable but isn’t, except this time the lab tells you upfront that the route table and Internet Gateway are already working. So the search starts somewhere else entirely.</p><h3>Setting the scene</h3><p>Stack deploys cleanly. Instance is up. Security group has port 80 open to the world. Route table has its 0.0.0.0/0 route pointed at the Internet Gateway. On paper, this should just work.</p><p>It doesn’t:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tvQ9wLeu9FHZt4GfL86Kqg.png" /></figure><p>Same failure signature as lab one. Same first instinct: a timeout means nothing is answering at all, not that something answered and said no. That still points at the network path rather than the application itself.</p><h3>Confirming what’s actually in place:</h3><p>The instance is up and running and passes all the status checks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKYhBywXq54n7VNW1iFmIA.png" /></figure><p>Then the security group attached to it, confirming the inbound rule on port 80 was actually there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qqroZ2UHyLIyDUB8-7zCZQ.png" /></figure><p>Then the subnet’s route table, confirming the 0.0.0.0/0 route was pointed at the Internet Gateway:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zYeAd8Z9vwZFrkP8K9g3AA.png" /></figure><p>All three checked out exactly as described. Instance healthy, security group open, route in place. Which meant, unlike lab one, the fix wasn’t going to be found in any of the pieces I’d normally check first.</p><h3>Narrowing down what’s left</h3><p>With the instance, security group, and routing path all confirmed working, there’s really only one other thing sitting on that traffic path inside the VPC: the network ACL attached to the subnet.</p><p>That’s the shift in thinking between lab one and lab two. A security group only ever tells you what it allows, there’s no explicit deny rule to trip over.</p><p>A network ACL is different. It evaluates a numbered list of rules in order and stops at the first match, allow or deny. That ordering is exactly where this one was hiding.</p><h4>Looking at what the subnet’s NACL actually contains</h4><p>I pulled up the subnet and checked which network ACL was attached to it, then opened its inbound rule set:</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*3j2Hqqk9bvZoxj4F7B6hXw.png" /></figure><p>At a glance this looks almost fine, there is an allow rule for port 80. But glancing at whether a rule exists isn’t the same as checking whether it ever actually gets used.</p><h4>Why the rule number is the whole story here</h4><p>Network ACLs process rules in ascending numeric order and act on the first one that matches the traffic. It doesn’t keep scanning after that to see if a “better” rule shows up further down. First match wins, and everything after it is irrelevant for that packet.</p><p>Here, rule 90 matches inbound TCP traffic on port 80 from anywhere, and it denies it. Since 90 comes before 100, that’s the rule that gets evaluated first, and because it’s a match, the ACL stops right there. Rule 100, sitting just below it with the correct allow, never even gets read for this traffic. It’s not wrong, it’s just unreachable, permanently shadowed by the deny rule ahead of it.</p><p>The * rule at the bottom is AWS&#39;s default catch-all deny, present on every NACL, but it isn&#39;t even the one causing the problem in this case. Rule 90 kills the request long before traffic would ever fall through to that default.</p><p>This is the core difference from a security group worth sitting with: security groups are allow-only and stateful, so there’s no ordering trap to fall into. NACLs are stateless and order-sensitive, so two contradictory rules can both exist at once, and whichever has the lower number quietly wins, every time, with nothing in the console shouting about it.</p><h3>Making the fix</h3><p>The rule doing the damage was rule 90. I had three options: delete it outright, renumber it so it sits after rule 100 instead of before it or allow traffic. I deleted the rule 90 deny entry, since there was no legitimate reason for a deny to exist ahead of the allow at all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hds7gDqYz6YL9X0KrQ4obA.png" /></figure><p>Reloaded the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kRVTaicfIyViXvlZnuoo4Q.png" /></figure><h3>Lab TakeAways</h3><p>Lab 01 was about a missing connection, a route that simply didn’t exist. This one was about a connection that existed twice, in contradictory forms, and the outcome depended entirely on which one AWS reached first. That’s a different category of bug to look for. It’s not enough to confirm that an allow rule is present somewhere in the list. You have to check whether anything positioned earlier in that list already made the decision for you.</p><p>Whenever I’m reading a NACL from now on, I’m reading it top to bottom, in rule-number order, the same way AWS evaluates it, rather than scanning for the rule that matches what I want to see.</p><p>Lab and CloudFormation template credit: <a href="https://www.cloudpathacademy.com/docs/aws/labs/vpc/lab-02-nacl/">CloudPath Academy, AWS Broken Labs</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e12f0e25afb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS Broken Labs: VPC Lab 01, No Route to the Internet Gateway]]></title>
            <link>https://medium.com/@eve.maina/aws-broken-labs-vpc-lab-01-no-route-to-the-internet-gateway-44f37203aa3d?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/44f37203aa3d</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[troubleshooting-tips]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[network-troubleshooting]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Mon, 07 Sep 2026 09:14:48 GMT</pubDate>
            <atom:updated>2026-09-07T09:14:48.708Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been going through <a href="https://www.cloudpathacademy.com/docs/aws/labs/vpc/lab-01-igw-routing/">CloudPath Academy’s AWS Broken Labs</a>, a set of deliberately misconfigured AWS environments where the task is to find the issue and fix it. I’m documenting how I worked through each one, not just what the fix was, but how I got there, because the process is the actual skill being practiced.</p><p>This is Lab 01: VPC Internet Gateway Routing.</p><h3>The scenario</h3><p>A web server is deployed in a VPC. The CloudFormation stack completes with no errors. The instance is running. The security group allows HTTP on port 80. There’s even an Internet Gateway, created and attached to the VPC. Everything that’s supposed to be there is there.</p><p>Open the page in a browser anyway, and:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-s-B35pwofjxPNM2ExT06A.png" /></figure><h3>Step 1: What does a timeout actually tell you</h3><p>Before touching the console, it’s worth pausing on what kind of failure this is. A timeout means the request never got a response, not even a rejection. That’s different from something like a “connection refused,” where the request reaches its destination and something there explicitly says no.</p><p>A timeout points upstream, toward the network path itself rather than the application. That’s the first real clue: whatever’s wrong, it’s likely not the web server.</p><p>So the instinct at this point is: this is a networking issue, somewhere on the path between the internet and the instance.</p><h3>Step 2: Confirm the obvious pieces are actually fine</h3><p>Rather than assume, I confirmed each of the pieces the lab description mentioned, one at a time.</p><ul><li>The instance was running and passing its status checks:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f4KgLDrIQV1FvsYVHBzEMw.png" /></figure><ul><li>The security group had an inbound rule allowing port 80 from anywhere:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hd2j1qeoiggU3dhizsLiVg.png" /></figure><ul><li>The Internet Gateway existed and was attached to the VPC:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WUPwuI7PIK8QLQmQRwKIlA.png" /></figure><p>All three checked out. Which meant the problem wasn’t in any of the pieces I was told to expect. It had to be in how they were connected.</p><h3>Step 3: Trace the actual path, not the pieces</h3><p>An Internet Gateway attached to a VPC doesn’t automatically mean any particular subnet can reach it. That relationship isn’t automatic, it has to be defined explicitly through a route.</p><p>So the next question wasn’t “is there an IGW,” it was “which subnet is this instance actually in, and what does that subnet’s route table say.”</p><p>I went to the instance’s networking details and found the subnet it was launched into.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOXrhvxxDsgMQU8VsJP5ZQ.png" /></figure><p>From there, I looked up which route table was associated with that subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SnLBlr8MbH1Nnsucw7JCTg.png" /></figure><h3>Step 4: Interpret the routes</h3><p>There it was. The only route present was the default local route for the VPC’s own CIDR block, the one AWS creates automatically so resources inside the VPC can talk to each other. There was no route sending internet-bound traffic (0.0.0.0/0) to the Internet Gateway.</p><h4>What that actually means</h4><p>A route table decides where traffic goes based on its destination. Without an explicit 0.0.0.0/0 → igw-xxxxxxxx route, the subnet has no instructions for what to do with traffic headed anywhere outside the VPC. It doesn&#39;t matter that the Internet Gateway exists and is correctly attached, the gateway is just a door. If nothing in the route table tells traffic to walk through that door, it never will.</p><p>That’s why every other piece could be correctly configured and the page would still fail to load. The security group governs what’s allowed once traffic arrives. The Internet Gateway provides a path to the internet if traffic is directed to it. Neither one does anything if the subnet’s route table never sends traffic there in the first place. The instance was reachable in theory and unreachable in practice, because the one piece connecting those two things was missing.</p><h3>The fix</h3><p>I added a route to the subnet’s route table:</p><ul><li><strong>Destination:</strong> 0.0.0.0/0</li><li><strong>Target:</strong> the Internet Gateway attached to the VPC</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qyok_u2DdQ2ynqMk6g-mgg.png" /></figure><p>Reloaded the page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1F-Zc_qhAkp7CV5FCyvHQQ.png" /></figure><h3>The takeaway</h3><p>Having every component present doesn’t mean they’re connected. A VPC, a subnet, an Internet Gateway, and a security group can all exist and all be individually correct, and the path between them can still be missing. The route table is what actually stitches “traffic from the internet” to “a specific subnet,” and it’s easy to overlook precisely because attaching an Internet Gateway to a VPC feels like it should be enough.</p><p>The habit worth keeping from this one: when something times out, don’t start with the resource that feels most likely to be broken. Start by tracing the path the traffic is supposed to take, one hop at a time, and check that each hop is actually told where to send it.</p><p>Lab and CloudFormation template credit: <a href="https://www.cloudpathacademy.com/docs/aws/labs/vpc/lab-01-igw-routing/">CloudPath Academy, AWS Broken Labs</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44f37203aa3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Networking 102: Scaling Traffic in AWS]]></title>
            <link>https://medium.com/@eve.maina/networking-102-scaling-traffic-in-aws-41227da3cee5?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/41227da3cee5</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Fri, 04 Sep 2026 14:39:04 GMT</pubDate>
            <atom:updated>2026-09-17T20:46:53.062Z</atom:updated>
            <content:encoded><![CDATA[<h4>From one instance to a self-healing fleet: Launch Templates, Auto Scaling, Target Groups, and Load Balancers explained</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GlKyk7WLS9sstCzGH7Cv7Q.png" /></figure><p>In Networking 101, we built a city. Houses had addresses, neighborhoods had gates, routes had a GPS to know where traffic should go, and guards stood at every door deciding who could come in.</p><p>That city worked beautifully, for one house.</p><p>But what happens when your city gets popular? What happens when one house can’t handle all the visitors showing up at once, or worse, that house shuts its doors for maintenance and now nobody can get in at all?</p><p>This is Networking 102, where we stop thinking about a single resource and start thinking about distributing traffic across many of them, reliably, automatically, and without a human standing by to fix things at 2 a.m.</p><p>Before we get into troubleshooting the things that go wrong (that’s the next post), let’s build the foundation of how AWS handles scale.</p><p>In this blog, I will vividly explain:</p><ol><li>Launch Templates</li><li>Auto Scaling Groups</li><li>Target Groups</li><li>Load Balancers</li><li>Health Checks</li></ol><h3>The problem: why one instance isn’t enough</h3><p>Imagine your city has exactly one house open to visitors. Two things can go wrong:</p><ol><li><strong>Too many visitors show up at once.</strong> One house, no matter how well built, can only serve so many people at a time. Eventually, visitors start waiting outside, or leaving.</li><li><strong>The house itself has a problem.</strong> Maybe the plumbing breaks. Maybe it needs renovation. While that’s happening, there’s nowhere else for visitors to go. The whole city is effectively closed.</li></ol><p>Both problems come down to the same root cause: <strong>relying on a single resource creates a single point of failure.</strong></p><p>The fix isn’t “build a bigger house.” It’s “build a system that can add more houses automatically, spread them across different parts of the city, and only send visitors to the ones that are actually open.”</p><p>That system is made of four building blocks: <strong>Launch Templates, Auto Scaling Groups, Target Groups, and Load Balancers.</strong></p><p>Let’s go through each one.</p><h3>1. Launch Templates: the blueprint</h3><p>Before you can build a house, you need a blueprint. In AWS, that blueprint is a <strong>Launch Template</strong>.</p><p>A Launch Template defines what an instance should look like when it’s created:</p><ul><li><strong>AMI</strong> — which base image (operating system) to use</li><li><strong>Instance type</strong> — how powerful the instance should be, for example t3.small or t3.micro</li><li><strong>Key pair</strong> — for SSH access</li><li><strong>Security groups</strong> — which guards stand at this house’s door</li><li><strong>User data</strong> — a script that runs automatically the first time the instance boots, often used to install and configure software</li><li><strong>IAM role</strong>, storage, and other configuration</li></ul><p>Here’s the important part: <strong>a Launch Template does not build anything by itself.</strong> It’s a blueprint sitting in a drawer. Something else has to actually pick it up and use it to construct a house.</p><p>That something else is the Auto Scaling Group.</p><h3>2. Auto Scaling Groups: the construction crew</h3><p>An <strong>Auto Scaling Group (ASG)</strong> is the crew that reads the blueprint and actually builds houses, as many as needed, in the right neighborhoods.</p><p>When you create an ASG, you tell it:</p><ul><li>Which Launch Template to build from</li><li><strong>Minimum, maximum, and desired</strong> number of instances</li><li><strong>Which subnets</strong> (and therefore which Availability Zones) it’s allowed to build in</li></ul><p>That last point matters more than it looks. Subnet placement is not defined in the Launch Template, it belongs to the ASG. This is a deliberate separation: the blueprint describes <em>what</em> to build, the ASG decides <em>where and how many</em>. That keeps the blueprint reusable across different deployment scenarios, while placement stays a scaling and availability decision.</p><p>The ASG spreads instances across the subnets you give it, ideally one per Availability Zone, so that if an entire AZ goes down, your other instances keep the city running.</p><p>It also does something else critical: if an instance becomes unhealthy or is terminated, the ASG notices and replaces it automatically, no manual intervention required. This is what makes the system “self-healing.”</p><p>But here’s a question worth sitting with: how does the ASG know an instance is unhealthy in the first place? By default, it doesn’t, not in the way you’d hope. We’ll come back to that.</p><h3>3. Target Groups: the building registry</h3><p>As the ASG builds houses, something needs to keep track of which houses exist and whether they’re actually fit to receive visitors. That’s the <strong>Target Group</strong>.</p><p>A Target Group is a registry. It holds:</p><ul><li>The list of registered targets (instances)</li><li>The <strong>health check configuration</strong>: which path to check, how often, what counts as a success</li><li>The current health status of each target: healthy, unhealthy, or initial</li></ul><p>Here’s a detail that catches a lot of people off guard: <strong>the Target Group doesn’t actually send the health check requests itself.</strong> It’s a configuration and status object, a filing cabinet, not a person walking around knocking on doors. The actual probing is performed by the Load Balancer, using the settings defined on the Target Group. The Target Group just stores the result.</p><h3>4. Load Balancers: the receptionist at the gate</h3><p>This is the piece that ties everything together. A <strong>Load Balancer</strong> sits at the entrance to your city and decides which house each visitor gets sent to.</p><p>Two concepts matter here: <strong>listeners</strong> and <strong>routing rules</strong>.</p><p>A <strong>listener</strong> is what the load balancer watches for, a protocol and port, like HTTP on 80 or HTTPS on 443. Think of it as which door the receptionist is standing at.</p><p>Once a request comes through a listener, <strong>routing rules</strong> decide where it goes. Simple routing sends everything to one Target Group. Content-based routing can send different requests to different Target Groups, based on path, host header, and more, /api/* goes one way, everything else goes another.</p><p>The load balancer isn’t one machine, either. Behind the scenes, it’s made up of <strong>load balancer nodes</strong>, one or more per enabled Availability Zone. This is why the load balancer uses a DNS name instead of a single static IP, there’s no single machine to point to.</p><h3>5. Health checks: how the receptionist knows who’s actually open</h3><p>This is the detail that quietly breaks more setups than almost anything else, so it’s worth its own section.</p><p>A Target Group’s health check works by repeatedly sending a request to one specific path on your instance, at a fixed interval, and checking whether the response code matches what you told it to expect, usually 200. That&#39;s it. It doesn&#39;t know anything about your app beyond that one number.</p><p>So the path you choose matters a lot. The temptation is to point the health check at /, your homepage, since it&#39;s already there and it&#39;s the thing users actually load. Don&#39;t.</p><p>/ is built for real users, not for infrastructure asking &quot;are you alive?&quot; It might render a full HTML page, query a database, call other services, do real work. Two problems follow from that:</p><ol><li><strong>It’s wasteful.</strong> The load balancer hits this path every 15 to 30 seconds, forever, for every single instance. If / does expensive work, like a database query, you&#39;re paying that cost constantly, just to answer a yes/no question that shouldn&#39;t need it.</li><li><strong>It can lie to you.</strong> A / route that&#39;s mostly static, or that doesn&#39;t touch your app&#39;s critical dependencies, can happily return 200 OK even when something important is broken. Say your database connection pool is exhausted, / might still render fine from cached content while every <em>real</em> request to your app is failing. The health check sees 200, calls the instance healthy, and the load balancer keeps sending it live traffic it can&#39;t actually serve.</li></ol><h3>Why /health is the better practice</h3><p>The fix is to build a dedicated, lightweight path whose only job is to answer that one question honestly: /health (some teams use /healthz, /status, or /ping, the name doesn&#39;t matter, the purpose does).</p><p>A well-built /health endpoint should:</p><ul><li>Respond quickly, no heavy rendering, no unnecessary work</li><li>Check the things that actually determine whether the instance can serve real traffic, for example, can it reach the database</li><li>Return a simple, honest status: 200 OK when things are fine, a 500-level code when something critical is broken</li></ul><p>This gives you a health check that’s both <strong>cheap to run constantly</strong> and <strong>actually meaningful</strong>, instead of one that’s either expensive or misleading.</p><h3>A concrete example</h3><p>Here’s the difference in a small Express (Node.js) app:</p><pre>// The real homepage - not meant for health checks<br>app.get(&#39;/&#39;, async (req, res) =&gt; {<br>  const products = await db.query(&#39;SELECT * FROM products&#39;); // expensive, hits the DB<br>  res.render(&#39;homepage&#39;, { products }); // renders a full HTML page<br>});<br><br>// Dedicated health check - cheap, but still tells the truth<br>app.get(&#39;/health&#39;, async (req, res) =&gt; {<br>  try {<br>    await db.ping(); // a cheap check that the DB connection is alive<br>    res.status(200).json({ status: &#39;ok&#39; });<br>  } catch (err) {<br>    res.status(500).json({ status: &#39;error&#39; }); // tells the load balancer this instance is broken<br>  }<br>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D08JJbR94y0a7_AwfBgGVw.png" /></figure><p>If the Target Group’s health check path were set to /, it would run that full product query every 15 to 30 seconds, per instance, forever, just to answer &quot;are you up?&quot; Pointed at /health instead, it gets a fast, purpose-built answer that still reflects something real: whether the database connection is actually alive.</p><h3>The part that’s easy to miss</h3><p>That endpoint has to actually exist in your application code. The load balancer isn’t magic, it’s sending a plain HTTP request to whatever path you configured, and it only knows how to interpret the response code it gets back. If your app has no route defined for /health, you&#39;ll get a 404, and every single instance gets marked unhealthy, even if the rest of your app is working perfectly fine.</p><p>In other words: configuring the Target Group’s health check path is only half the job. Someone still has to write the route it’s checking.</p><h3>The gotcha: EC2 status checks are not the same as Target Group health</h3><p>Remember the question from earlier, how does the ASG know an instance is unhealthy? Here’s the part that surprises people.</p><p>An EC2 instance can show <strong>3/3 status checks passed</strong> in the console, and still be <strong>completely unhealthy in the Target Group</strong>, at the same time.</p><p>That’s not a contradiction. They’re checking two entirely different things.</p><p><strong>EC2 status checks</strong> only confirm that the underlying hardware is fine and the operating system has booted. They know nothing about your application. Apache could have never installed, your app could have crashed on startup, and EC2 status checks would still show green.</p><p><strong>Target Group health checks</strong> are the ones that actually test your application, hitting /health and checking the response. This is where real problems, a missing dependency, a blocked security group, a service that never started, actually show up.</p><p>And by default, your <strong>Auto Scaling Group only looks at EC2 status checks</strong>, not Target Group health. That means an instance can sit there, completely broken as far as your users are concerned, passing at 3/3, while the ASG has no idea anything is wrong and never replaces it.</p><p>To fix this, the ASG’s health check type has to be explicitly set to include <strong>ELB health checks</strong>, so it reads the Target Group’s results and reacts to them. Without that setting, the two systems are running side by side, but not actually talking to each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vK3TSeZEVYITcOrDl8gsxg.png" /></figure><h3>Putting it all together: one request’s journey</h3><p>Here’s the full path a single request takes, end to end:</p><ol><li>A client sends a request to the Load Balancer’s DNS name.</li><li>The request arrives at a <strong>listener</strong> watching that port and protocol.</li><li><strong>Routing rules</strong> on that listener evaluate the request and pick a <strong>Target Group</strong>.</li><li>The Load Balancer checks that Target Group’s current health status, tracked from its ongoing health checks, and forwards the request only to a target marked <strong>healthy</strong>.</li><li>The instance processes the request and sends the response back through the Load Balancer to the client.</li></ol><p>Meanwhile, in the background, entirely separate from that request:</p><ul><li>The <strong>Auto Scaling Group</strong> is continuously making sure the right number of instances exist, built from the <strong>Launch Template</strong>, spread across the subnets it was given.</li><li>The <strong>Target Group</strong> is continuously being probed by the Load Balancer, updating each instance’s health status.</li><li>If ELB health checks are enabled on the ASG, an instance that fails those checks gets terminated and replaced, automatically, without anyone needing to notice first.</li></ul><p>Four components. Four different jobs. None of them doing the other’s work, but all of them depending on each other to function.</p><h3>Where this leaves us</h3><p>You now have a city that can grow, shrink, heal itself, and spread its risk across multiple locations, without anyone manually building or removing a house every time traffic changes.</p><p>But knowing how these pieces are <em>supposed</em> to work together is only half the picture. The far more common experience, especially the first time you build this, is staring at a Target Group that stubbornly says <strong>0 healthy targets</strong>, with no obvious reason why.</p><p>That’s exactly where the next post picks up: the real, practical failure points, security groups that silently block the Load Balancer, private subnets with no path to the internet, health check paths that were never actually built, and how to methodically work backward from “it doesn’t work” to the actual cause.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41227da3cee5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Networking 101: The Building Blocks of AWS Networking]]></title>
            <link>https://medium.com/@eve.maina/networking-101-the-building-blocks-of-aws-networking-52e475840d94?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/52e475840d94</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Wed, 26 Aug 2026 11:21:13 GMT</pubDate>
            <atom:updated>2026-09-24T07:44:10.801Z</atom:updated>
            <content:encoded><![CDATA[<h4>Breaking down the basic AWS networking concepts behind every VPC</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*fbPAUGcuOvr_8smKrt7xcw.png" /></figure><p>If you have ever looked at an AWS architecture diagram and thought, “Okay… but how does the traffic actually get from here to there?”, you are not alone.</p><p>When I first started working with AWS infrastructure, I could recognize names like VPC, subnet, route table, security group and Internet Gateway. But recognizing the names is very different from understanding how they work together.</p><p>This is <strong>Networking 101</strong>, where we strip networking down to its building blocks and answer one simple question:</p><p><em>When traffic needs to move from the internet into your cloud environment, or between resources inside it, what actually happens?</em></p><p>In this blog, I will explain:</p><ol><li>AWS Regions and Availability Zones</li><li>VPC and Subnets</li><li>Internet and NAT Gateways</li><li>Security Groups and NACLs</li></ol><h3>First, what is networking?</h3><p>At its simplest, networking is just <strong>communication between computers and other devices</strong>.</p><p>Imagine a city.</p><p>Every house has an address. Roads connect different neighborhoods. There are gates that connect the city to the outside world. There are security checkpoints. There are maps telling you which road to take.</p><p>Computer networks work in a surprisingly similar way. Here’s how the pieces map:</p><ul><li>IP address → A house address</li><li>VPC → Your private city</li><li>Subnet → A neighborhood</li><li>Route table → A map showing where traffic should go</li><li>Internet Gateway → A gate connecting your city to the internet</li><li>Security Group → Security around an individual building</li><li>NACL → Security checkpoint around an entire neighborhood</li></ul><p>Once you see networking this way, AWS becomes much easier to understand.</p><h3>1. AWS Region and Availability Zones</h3><p>Before creating a network, we need to know where it lives.</p><p>AWS organizes its infrastructure into <strong>Regions</strong>.</p><p>For example, AWS has a Region in US called us-east-1.</p><p>Inside a Region are multiple <strong>Availability Zones</strong>, which are separate infrastructure locations designed to provide isolation and resilience.</p><p>You can picture it like this:</p><pre>AWS Region: us-east-1<br>├── Availability Zone A<br>├── Availability Zone B<br>└── Availability Zone C</pre><p>Why does this matter?</p><p>Because when we build highly available applications, we don’t want everything sitting in one location.</p><p>If something goes wrong in one Availability Zone, having resources in another gives us somewhere else to operate from.</p><p>One important rule to remember: a subnet belongs to one Availability Zone. You cannot create one subnet and stretch it across multiple Availability Zones.</p><h3>2. VPC: Your Network Inside AWS</h3><p>Now we can create our own network.</p><p>That’s where the <strong>Virtual Private Cloud, or VPC</strong>, comes in.</p><p>A VPC is essentially your own logically isolated network inside AWS.</p><p>For example, let’s create a VPC with the CIDR block 10.0.0.0/16.</p><p>Think of the VPC as our city. Everything we build later will live inside this city.</p><p>But we don’t want everything in one giant network. We need neighborhoods. That’s where subnets come in.</p><h3>3. CIDR: Dividing the Network</h3><p>You will often see something like 10.0.0.0/16. This is a <strong>CIDR block</strong>.</p><p>Don’t let the /16 scare you. For now, think of CIDR as a way of describing the size and range of an IP network.</p><p>We can divide our VPC’s 10.0.0.0/16 into smaller networks, for example:</p><p>10.0.1.0/24, 10.0.2.0/24, 10.0.11.0/24, 10.0.12.0/24</p><p>These smaller networks become our subnets. This is called <strong>subnetting</strong>. We are taking one larger network and dividing it into smaller sections.</p><h3>4. Subnets: The Neighborhoods</h3><p>A subnet is a smaller network inside our VPC.</p><p>For our architecture, we can create four:</p><ul><li>Public Subnet A — 10.0.1.0/24 in us-east-1a</li><li>Public Subnet B — 10.0.2.0/24 in us-east-1b</li><li>Private Subnet A — 10.0.11.0/24 in us-east-1a</li><li>Private Subnet B — 10.0.12.0/24 in us-east-1b</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cjyxBD4TFJUr20AAmkPFg.png" /></figure><p>At this point, you might be tempted to think: “Okay, the first two are public because we named them public, and the other two are private because we named them private.”</p><p>Not quite. And this is one of the most important lessons in AWS networking.</p><h4>A subnet is not public just because you named it public.</h4><p>You could name a subnet my-super-public-subnet, but that doesn&#39;t make it public. The name is just a label.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*VyJqrngtN5_oe-Q6lhStGw.png" /></figure><p>As you can see above there is no route to the internet yet the subnet is named public.</p><p>What actually determines whether a subnet is public is <strong>its routing</strong>.</p><p>More specifically, a subnet is considered public when its associated route table contains a route to an Internet Gateway. That means having a route like 0.0.0.0/0 → Internet Gateway is much more important than the word &quot;public&quot; in the subnet&#39;s name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1HfA_WPXU95O8JteJwy1QA.png" /></figure><p>This distinction becomes extremely important when troubleshooting.</p><h3>5. Route Tables: The Network’s GPS</h3><p>Now we have neighborhoods, but there is a problem.</p><p>Suppose an EC2 instance wants to communicate with another computer. How does AWS know where the traffic should go?</p><p>Enter the <strong>route table</strong>. A route table is essentially a collection of instructions that says: “For this destination, send the traffic this way.” Think of it as the GPS of your network.</p><p>Every route table is made up of rows, and each row has two main parts: a <strong>destination</strong> and a <strong>target</strong>.</p><p>The <strong>destination</strong> is the range of IP addresses the traffic is trying to reach. It’s written as a CIDR block, like 10.0.0.0/16 or 0.0.0.0/0. AWS looks at where the traffic is headed and matches it against this column.</p><p>The <strong>target</strong> is where that traffic should be sent next in order to get there. This could be local, meaning stay inside the VPC, or it could point to a gateway, like an Internet Gateway, that knows how to route it further.</p><p>So a route made up of destination 10.0.0.0/16 and target local means: if the destination is somewhere inside our VPC, keep the traffic inside the VPC. It never leaves.</p><p>Then we might add a second route: destination 0.0.0.0/0 and target Internet Gateway. This one is special because 0.0.0.0/0 means &quot;everything&quot;, or more precisely, any address that didn&#39;t match a more specific route above it. So this route means: if the destination doesn&#39;t match the VPC&#39;s local network, send the traffic towards the Internet Gateway.</p><p>This is why 0.0.0.0/0 is often called the default route. It&#39;s the catch-all for anything not explicitly accounted for elsewhere in the table.</p><p>So a public route table has two rows: one with destination 10.0.0.0/16 and target local, and one with destination 0.0.0.0/0 and target Internet Gateway.</p><p>Notice something important. The route table isn’t saying “Allow this traffic.” It is saying <strong>“This is where the traffic should go.”</strong> Whether that traffic is actually allowed once it arrives is a decision made elsewhere, by NACLs and Security Groups, which we’ll get to shortly.</p><p>That distinction is critical.</p><p>Here is an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K538DbE_dH5Gr7IX1Y7uvA.png" /></figure><h3>6. Internet Gateway: The Door to the Internet</h3><p>Our VPC is isolated from the internet by default.</p><p>If we want resources in our VPC to communicate with the internet, we need an <strong>Internet Gateway</strong>, or IGW.</p><p>Think of the IGW as the main gate connecting our city to the outside world. Traffic flows from the internet, through the Internet Gateway, into the VPC.</p><p>But simply attaching an Internet Gateway to the VPC does not magically make every subnet public.</p><p>Remember our route table? The subnet also needs a route pointing internet traffic toward the IGW, 0.0.0.0/0 → Internet Gateway.</p><p>So internet connectivity involves several pieces working together, in this order: Internet, then Internet Gateway, then Route Table, then Subnet, then Resource.</p><p>If one of those pieces isn’t configured correctly, the traffic may not reach its destination. And that is exactly why understanding these building blocks matters.</p><h3>7. Public vs Private Subnets</h3><p>Let’s put everything we’ve learned together.</p><p>Our public subnets use a route table with both 10.0.0.0/16 → local and 0.0.0.0/0 → Internet Gateway.</p><p>Our private subnets use a route table with only 10.0.0.0/16 → local, and no route to the internet.</p><p>The difference is the route to the Internet Gateway.</p><p>So remember: the name of a subnet does not make it public or private. Its routing configuration does.</p><h3>8. NAT Gateway</h3><p>At this point, a natural question comes up.</p><p>If a private subnet has no route to the Internet Gateway, how does a resource inside it ever reach the internet? For example, an EC2 instance in a private subnet might still need to download a software update, or call an external API.</p><p>This is where the <strong>NAT Gateway</strong> comes in.</p><p>NAT stands for Network Address Translation. Think of it as a one-way door. Resources inside the private subnet can go out through it to reach the internet, but nothing from the internet can come in through it to reach those resources.</p><p>A NAT Gateway itself lives in a <strong>public subnet</strong>, not a private one. That’s an important detail. The NAT Gateway needs its own route to the Internet Gateway in order to do its job.</p><p>Here’s how it fits together. The private subnet’s route table gets a new route: destination 0.0.0.0/0, target NAT Gateway. So instead of pointing straight at the Internet Gateway, private subnet traffic is routed to the NAT Gateway first. The NAT Gateway, sitting in the public subnet with its own route to the IGW, then forwards that traffic out to the internet on the resource&#39;s behalf.</p><p>When a response comes back, it comes back to the NAT Gateway, which then routes it to the correct resource in the private subnet.</p><p>But if someone on the internet tries to initiate a connection to that same private resource directly, there’s no route back in. The NAT Gateway only forwards traffic that started from inside the private subnet.</p><p>So the difference between an Internet Gateway and a NAT Gateway comes down to direction. An Internet Gateway allows traffic in both directions, which is why it makes a subnet public. A NAT Gateway only allows traffic to leave and lets the responses come back, but it never allows a connection to be started from the outside.</p><h3>9. Security Groups: Security around an individual building</h3><p>Now we have traffic flowing in the right direction. But should every resource accept every connection?</p><p>Definitely not. This is where <strong>Security Groups</strong> come in.</p><p>A Security Group acts like security around an individual building. In our neighborhood analogy, the EC2 instance is the building, and the Security Group is the guard standing at its door, controlling which traffic can reach it.</p><p>For example, an inbound rule of protocol TCP, port 80, source 0.0.0.0/0, action Allow, means: allow HTTP traffic from anywhere on the internet.</p><p>We could also allow SSH from a specific trusted source.</p><p>The important thing is that Security Groups work at the <strong>resource level</strong>, such as the network interface attached to an EC2 instance.</p><h3>10. NACLs: S<strong>ecurity checkpoint at the entrance to the neighborhood</strong></h3><p>Now we have another security concept: the <strong>Network Access Control List</strong>, or NACL.</p><p>At first glance, NACLs and Security Groups can seem like the same thing. They aren’t.</p><p>Here’s an analogy that makes the difference easier to remember.</p><p>Imagine an apartment building. The <strong>NACL is the security checkpoint at the entrance to the neighborhood</strong>. The <strong>Security Group is the security guard at your individual building</strong>.</p><p>Traffic from the internet passes through the NACL checkpoint first, then reaches the Security Group guarding the individual EC2 instance.</p><p>The NACL operates at the <strong>subnet level</strong>. The Security Group operates at the <strong>resource level</strong>.</p><p>So: NACL protects the neighborhood. Security Group protects the building.</p><h3>11. NACL vs Security Group</h3><p>Let’s make the difference crystal clear.</p><p>NACL:</p><ul><li>Applies to the subnet</li><li>Controls traffic entering or leaving the subnet</li><li>Stateless</li><li>Supports allow and deny rules</li><li>Rules are evaluated in order, lowest numbered rule first</li><li>The default NACL allows all traffic</li></ul><p>Security Group:</p><ul><li>Applies to the resource or network interface</li><li>Controls traffic to or from the resource</li><li>Stateful</li><li>Supports allow rules only</li><li>No rule ordering in the same sense</li><li>The default Security Group allows inbound from the same SG and allows all outbound traffic</li></ul><p>One of the biggest differences is <strong>statefulness</strong>.</p><p>Security Groups are <strong>stateful</strong>. If you allow an incoming connection, the response traffic is automatically allowed as part of that connection.</p><p>NACLs are <strong>stateless</strong>. They evaluate inbound and outbound traffic separately. So if your NACL allows incoming traffic, you also need appropriate outbound rules for the response.</p><p>When AWS creates a VPC, it creates a default NACL. The default NACL allows all inbound and outbound traffic.</p><p>So the default NACL isn’t restricting traffic. That’s useful while learning because we can first understand routing and Security Groups without another layer blocking our traffic.</p><p>Later, we can create a custom NACL and deliberately introduce restrictions to see what happens.</p><h3><strong>Putting the Building Blocks Together</strong></h3><p>The Internet Gateway provides the connection between the VPC and the internet.</p><p>The route table determines where traffic should go.</p><p>The subnet provides a smaller network inside the VPC.</p><p>The NACL controls traffic at the subnet boundary.</p><p>The Security Group controls traffic at the resource level.</p><p>The EC2 instance runs our actual application.</p><p>That’s the foundation, and in the next post, we’ll build on it with load balancers, Auto Scaling, and the patterns that turn these building blocks into architectures that can handle real traffic at scale.</p><p>See yah!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52e475840d94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Modules: Turning Copy-Paste Infrastructure Into Reusable Building Blocks]]></title>
            <link>https://medium.com/@eve.maina/terraform-modules-turning-copy-paste-infrastructure-into-reusable-building-blocks-0e5647d4bfb0?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/0e5647d4bfb0</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Fri, 07 Aug 2026 21:36:53 GMT</pubDate>
            <atom:updated>2026-09-21T08:27:08.301Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oWfznetFOs-3N15-yu8yHQ.png" /></figure><p>If you’ve spent any time writing Terraform, you’ve probably hit this wall: you need the same EC2 instance, the same security group, the same load balancer setup, just in a different environment with slightly different values. Without a way to package that logic, you end up copy-pasting whole files and hand-editing numbers, which is tedious and a great way to introduce a typo into production. Modules are Terraform’s answer to that problem, and this post walks through building one from scratch.</p><h3>What Is a Module, Really?</h3><p>Think of a module like a recipe. Every time you want tea, you don’t rewrite the recipe from scratch, you just say “make me tea, but with 2 teaspoon-fulls of sugars instead of 1.” Same recipe, different inputs plugged in.</p><p>A Terraform module is exactly that: a folder of .tf files describing <em>how</em> to build something, with blanks left in it (variables) for the specific values to be filled in later. Every Terraform configuration you write is technically a module, the &quot;root module.&quot; What you&#39;re doing when you build a <em>child module</em> is packaging up reusable resource logic so it can be called from multiple places with different inputs, instead of copy-pasted and hand-edited each time.</p><p>Concretely, a module has three jobs, split across three files:</p><ul><li><strong>variables.tf</strong> — the inputs it accepts (the blanks in the recipe)</li><li><strong>main.tf</strong> — the actual resources it creates (the recipe itself)</li><li><strong>outputs.tf</strong> — the values it hands back once it&#39;s done (what the recipe returns)</li></ul><h3>Building an EC2 Instance Module</h3><pre>modules/<br>└── services/<br>    └── ec2-instance/<br>        ├── main.tf<br>        ├── variables.tf<br>        ├── outputs.tf<br>        └── versions.tf</pre><p><strong>variables.tf</strong> defines every configurable input, with types and descriptions:</p><pre>variable &quot;instance_name&quot; {<br>  description = &quot;Name tag for the EC2 instance&quot;<br>  type        = string<br>}<br>variable &quot;instance_type&quot; {<br>  description = &quot;EC2 instance type&quot;<br>  type        = string<br>  default     = &quot;t3.small&quot;<br>}<br>variable &quot;ami_id&quot; {<br>  description = &quot;AMI ID to launch the instance from&quot;<br>  type        = string<br>}</pre><p><strong>main.tf</strong> holds the resource definition, with no hardcoded values, everything configurable flows through a variable:</p><pre>resource &quot;aws_instance&quot; &quot;my_instance&quot; {<br>  ami           = var.ami_id<br>  instance_type = var.instance_type<br> <br>  tags = {<br>    Name = var.instance_name<br>  }<br>}</pre><p><strong>outputs.tf</strong> exposes what a caller might need:</p><pre>output &quot;instance_id&quot; {<br>  value       = aws_instance.my_instance.id<br>  description = &quot;ID of the EC2 instance&quot;<br>}<br>output &quot;public_ip&quot; {<br>  value       = aws_instance.my_instance.public_ip<br>  description = &quot;Public IP address of the EC2 instance&quot;<br>}</pre><h3>The Root/Module Split</h3><p><strong>“Root module” </strong>just means whichever folder you cd into and run terraform apply from. It&#39;s not a special file type, it&#39;s just Terraform&#39;s name for the folder you&#39;re standing in when you run the command. My root configs live in a separate live/ tree:</p><pre>live/<br>├── dev/<br>│   └── services/<br>│       └── ec2_instance/<br>│           ├── main.tf<br>│           └── outputs.tf<br>└── production/<br>    └── services/<br>        └── ec2_instance/<br>            ├── main.tf<br>            └── outputs.tf</pre><p>Each one calls the module with environment-specific values:</p><p><strong>Provider blocks live only in the root, never in the module.</strong> A module shouldn’t know or care which AWS account, region, or credentials it’s deployed into, that’s the caller’s decision. The module can declare <em>what version</em> of the provider it needs (required_providers in a versions.tf), but the actual provider &quot;aws&quot; { region = ... } configuration belongs in each root config only.</p><p><strong>The </strong><strong>source path is just relative directory navigation</strong>, counted the same way cd .. works in a terminal. From live/dev/services/ec2_instance/main.tf, reaching modules/services/ec2-instance/ means climbing out of four folders (ec2_instance, services, dev, live) before walking back down, hence ../../../../modules/services/ec2-instance.</p><pre># live/dev/services/ec2-instance/main.tf<br><br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt;5.0&quot;<br>    }<br>  }<br><br>  backend &quot;s3&quot; {<br>    bucket       = &quot;kalibee-terraform-state-bucket&quot;<br>    key          = &quot;dev/services/ec2-instance/terraform.tfstate&quot;<br>    region       = &quot;us-east-1&quot;<br>    encrypt      = true<br>    use_lockfile = true<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br><br>}<br><br>module &quot;ec2_instance&quot; {<br>  source = &quot;../../../../modules/services/ec2-instance&quot;<br><br>  instance_name = &quot;dev_server&quot;<br>  instance_type = &quot;t3.small&quot;<br>  ami_id = &quot;ami-0bdc7d025135d7b49&quot;<br><br>}<br></pre><pre>output &quot;instance_id&quot; {<br>    value = module.ec2_instance.instance_id<br>    description = &quot;Id of the instance&quot;<br>  <br>}<br><br>output &quot;public_ip&quot; {<br>    value = module.ec2_instance.public_ip<br>    description = &quot;public IP of the instance&quot;<br>  <br>}</pre><p>Same module, different inputs, zero duplicated resource code. That’s the entire point.</p><p>Run terraform plan then apply :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5rIWJyajfUtH9ZrSx-aGuA.png" /></figure><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt;5.0&quot;<br>    }<br>  }<br><br>  backend &quot;s3&quot; {<br>    bucket       = &quot;kalibee-terraform-state-bucket&quot;<br>    key          = &quot;dev/services/ec2-instance/terraform.tfstate&quot;<br>    region       = &quot;us-east-1&quot;<br>    encrypt      = true<br>    use_lockfile = true<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br><br>}<br><br>module &quot;ec2_instance&quot; {<br>  source = &quot;../../../../modules/services/ec2-instance&quot;<br><br>  instance_name = &quot;prod_server&quot;<br>  instance_type = &quot;t3.small&quot;<br>  ami_id = &quot;ami-0bdc7d025135d7b49&quot;<br><br>}</pre><pre>output &quot;instance_id&quot; {<br>    value = module.ec2_instance.instance_id<br>    description = &quot;Id of the instance&quot;<br>  <br>}<br><br>output &quot;public_ip&quot; {<br>    value = module.ec2_instance.public_ip<br>    description = &quot;public IP of the instance&quot;<br>  <br>}</pre><p>After running terraform plan and apply:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0o0QbDysDi7GsO-GY68sqA.png" /></figure><p>Always remember to run terraform destroy.</p><h3>Conclusion</h3><p>What started as frustration with copy-pasting the same EC2 setup across environments turned into a clear grasp of how Terraform organizes reusable infrastructure: a module only exposes what it explicitly outputs, the root has to reach through that interface rather than into its internals, and configuration like providers and backends stays strictly at the root. That boundary is what makes modules useful at scale, once dev and production are just two input sets pointed at the same source, adding a new environment or handing the module off to someone else stops being a copy-paste exercise and becomes a one-block addition.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0e5647d4bfb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform State Isolation, Explained: Workspaces, File Layouts, and Where Each Breaks]]></title>
            <link>https://medium.com/@eve.maina/terraform-state-isolation-explained-workspaces-file-layouts-and-where-each-breaks-19d83449dbcc?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/19d83449dbcc</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Thu, 30 Jul 2026 14:50:53 GMT</pubDate>
            <atom:updated>2026-07-30T14:50:53.510Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HwnJ7JYfsL29ycVCeY4EbQ.png" /></figure><p>Every team hits this problem eventually: how do you manage dev, staging, and production without copy pasting the same .tf files three times and hoping you don&#39;t forget to update all three copies when something changes.</p><p>Terraform Workspaces are one answer. Here’s how they actually work, using a real EC2 example.</p><h3>The problem with a single state file</h3><p>By default, Terraform tracks all your infrastructure in one state file. That’s fine until you need more than one environment. If dev and production share a state file, applying a change for one risks touching the other. You could split each environment into its own folder with duplicated code, but then a change to your instance configuration means editing three separate files and hoping you don’t miss one.</p><p>Workspaces solve this differently. Same code, same directory, but a separate state file per environment. Terraform tracks each one independently, so resources in dev are completely invisible to staging and production, even though they were built from the exact same .tf files.</p><h3>The code</h3><p>Two files do all the work here. First, the variables:</p><pre>variable &quot;aws_region&quot; {<br>    description = &quot;Region of deployment&quot;<br>    type = string<br>    default = &quot;us-east-1&quot;<br>}<br>variable &quot;ami_id&quot; {<br>    description = &quot;Ami ID of instance&quot;<br>    type = string<br>    default = &quot;ami-02b64aa047cb5edf5&quot; <br>}<br>variable &quot;instance_type&quot; {<br>    description = &quot;Instance type of instances&quot;<br>    type = map(string)<br>    default = {<br>        dev = &quot;t3.micro&quot;<br>        staging = &quot;t3.small&quot;<br>        production = &quot;c7i-flex.large&quot;<br>    }<br></pre><p>The important one here is instance_type. Instead of a plain string, it&#39;s a map. Each key is an environment name, each value is the instance size that environment should get. On its own, a map does nothing special. What makes it useful is how it gets read.</p><p>Then the main config:</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>        source = &quot;hashicorp/aws&quot;<br>        version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br>backend &quot;s3&quot; {<br>    bucket = &quot;kalibee-terraform-state-2026&quot;<br>    key = &quot;terraform.tfstate&quot;<br>    region = &quot;us-east-1&quot;<br>    dynamodb_table = &quot;terraform-locks&quot;<br>    encrypt = true <br>  }<br>}<br>provider &quot;aws&quot; {<br>    region = var.aws_region<br>}<br>resource &quot;aws_instance&quot; &quot;web&quot; {<br>    ami = var.ami_id <br>    instance_type = var.instance_type[terraform.workspace]<br>    <br>    tags = {<br>      Name = &quot;web-${terraform.workspace}&quot;<br>      Environment = terraform.workspace<br>    }</pre><p>Two lines are doing the real work. var.instance_type[terraform.workspace] uses the name of whatever workspace is currently active as the key into that map, so the instance type resolves differently depending on where you&#39;re standing. And Name = &quot;web-${terraform.workspace}&quot; tags every instance with the environment it belongs to, so nothing in the AWS console is a mystery later.</p><p>terraform.workspace is a built in value. You never define it. It just always equals the name of your current workspace.</p><h3>Creating the workspaces</h3><pre>terraform workspace new dev<br>terraform workspace new staging<br>terraform workspace new production</pre><p>Each command does two things: creates a brand new, empty state file, and switches you into it immediately. At this point, three workspaces exist, but only one has actually been applied.</p><pre>terraform workspace select dev<br>terraform apply</pre><p>This creates the first real instance. Since dev’s state was empty, Terraform builds everything from scratch. According to the map, dev resolves to t3.micro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e1X3nKn9l-Ccy9PqkAatOg.png" /></figure><p>One instance, tagged correctly, sized correctly, state tracked separately from anything else.</p><h3>Switching and repeating</h3><pre>terraform workspace select staging<br>terraform apply</pre><pre>terraform workspace select production<br>terraform apply</pre><p>No code changed between these three applies. Not one line. The only thing that changed was which workspace was active, and the map did the rest: staging picked up t3.small, production picked up c7i-flex.large.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-QCpRzhz1JgmB-4PulFpg.png" /></figure><p>The asterisk marks whichever workspace is currently active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EK91naX2O77iNXTHxEaB9w.png" /></figure><p>Three real, independent EC2 instances. Three separate state files sitting in the same S3 bucket, each tracking only its own environment. Run terraform destroy from inside staging and only the staging instance disappears. Dev and production don&#39;t even know it happened.</p><h3>What this doesn’t solve</h3><p>Worth saying clearly: workspaces isolate state, not configuration. Every workspace still shares the same provider settings, the same backend bucket, and any variable that isn’t explicitly keyed by workspace like instance_type is. If dev and production ever need different AWS accounts, different VPCs, or fundamentally different infrastructure rather than just different sizing, workspaces stop being the right tool. That&#39;s usually the point teams move to separate root modules instead.</p><p>For a setup where the only real difference between environments is scale, workspaces get the job done with a single, small config file.</p><h3>The alternative: file layouts</h3><p>There’s a second way to isolate state, and it takes the opposite approach. Instead of one shared config with a hidden switch (terraform.workspace) deciding what gets built, file layouts give every environment its own directory, with its own complete copy of the code:</p><pre>environments/<br>├── dev/<br>│   ├── main.tf<br>│   ├── variables.tf<br>│   ├── outputs.tf<br>│   └── backend.tf<br>├── staging/<br>│   ├── main.tf<br>│   ├── variables.tf<br>│   ├── outputs.tf<br>│   └── backend.tf<br>└── production/<br>    ├── main.tf<br>    ├── variables.tf<br>    ├── outputs.tf<br>    └── backend.tf</pre><p>Each environment&#39;s backend.tf points to a completely different state file path in S3:</p><pre># environments/dev/backend.tf<br>terraform {<br>  backend &quot;s3&quot; {<br>    bucket         = &quot;kalibee-terraform-state-2026&quot;<br>    key            = &quot;environments/dev/terraform.tfstate&quot;<br>    region         = &quot;us-east-1&quot;<br>    dynamodb_table = &quot;terraform-locks&quot;<br>    encrypt        = true<br>  }<br>}</pre><pre>variable &quot;aws_region&quot; {<br>  description = &quot;Region of deployment&quot;<br>  type        = string<br>  default     = &quot;us-east-1&quot;<br>}<br><br>variable &quot;ami_id&quot; {<br>  description = &quot;Ami ID of instance&quot;<br>  type        = string<br>  default     = &quot;ami-02b64aa047cb5edf5&quot;<br>}<br><br>variable &quot;instance_type&quot; {<br>  description = &quot;EC2 instance type for this environment&quot;<br>  type        = string<br>  default     = &quot;t3.micro&quot;<br>}<br><br>variable &quot;environment&quot; {<br>  description = &quot;Name of this environment&quot;<br>  type        = string<br>  default     = &quot;dev&quot;<br>}</pre><p>Notice what disappears here: no terraform.workspace lookup, and instance_type goes back to being a plain string instead of a map, because each directory only ever represents one environment.</p><p>There&#39;s nothing to look up, dev&#39;s variables.tf just says default = &quot;t3.micro&quot; .</p><pre>cd environments/production<br>terraform init<br>terraform apply</pre><p>Running apply from inside a directory means you&#39;re never relying on remembering which workspace you last selected. The environment you&#39;re operating on is the folder you&#39;re standing in, visible in your terminal prompt, impossible to apply to unless you cd into it first.</p><p><a href="https://github.com/Eve-maina/terraform-30-day-challenge/tree/main/Day-07">Github</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19d83449dbcc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Local to Locked: Setting Up Remote Terraform State with S3 and DynamoDB]]></title>
            <link>https://medium.com/@eve.maina/from-local-to-locked-setting-up-remote-terraform-state-with-s3-and-dynamodb-89922a56ebe8?source=rss-1adc1ec00478------2</link>
            <guid isPermaLink="false">https://medium.com/p/89922a56ebe8</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Eve Maina]]></dc:creator>
            <pubDate>Fri, 24 Jul 2026 10:25:55 GMT</pubDate>
            <atom:updated>2026-07-24T11:04:50.736Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kgvcs6USENNBC60IKwF1Xg.png" /></figure><p>It’s a normal Tuesday. You run terraform apply so does your teammate, thirty seconds later, on the same project, without knowing you&#39;re mid-deploy. Neither of you sees an error. Both applies finish &quot;successfully.&quot; And now your state file, the single source of truth for everything Terraform thinks exists in your AWS account, has quietly forgotten about a resource one of you just created.</p><p>This is the exact failure that state locking exists to prevent. If you’ve never hit it, it’s probably because your backend was already locking for you. Today I set one up from scratch, using Amazon S3 to store the state and DynamoDB to lock it, and I want to walk through what it actually does, not just how to configure it.</p><h3>What Terraform state actually is</h3><p>Every time Terraform manages your infrastructure, it keeps a JSON file, terraform.tfstate, that maps your configuration to real resource IDs in the cloud. It&#39;s how Terraform knows the difference between &quot;create this&quot; and &quot;this already exists, just update it.&quot; By default, that file lives on your local disk. Fine if you&#39;re the only person touching the project. A liability the moment anyone else joins in.</p><h3>The problem local state doesn’t solve</h3><p>Terraform’s core loop, for any plan or apply, looks like this: read the state, calculate the diff, make changes against your cloud provider, write the updated state back. If two of these loops run at the same time against the same state file, both read it at nearly the same moment, both calculate their own changes, and both eventually try to write their version back. Whoever writes last wins, and the other person’s changes vanish from the record, even though they’re still sitting there in AWS. Your state file and reality have now drifted apart, and untangling that later is not a fun afternoon.</p><p>Notice this isn’t about two people editing the <em>same</em> resource. It happens even with completely unrelated changes, because the lock, when you have one, covers the entire state file, not individual resources inside it.</p><h3>What locking actually does about it</h3><p>A remote backend with locking enabled adds one rule: only one Terraform operation can hold the state at a time. Everyone else gets told to wait. No silent overwrites, no drift, no mystery resources.</p><p>With the S3 backend, S3 stores the file itself, but S3 alone has no “block anyone else from touching this” mechanism. That’s where DynamoDB comes in. Terraform uses a DynamoDB table purely as a lock flag, not as a database in any traditional sense. When you run apply, Terraform tries to write one row to that table, keyed by a string built from your bucket and file path (something like your-bucket/terraform.tfstate). DynamoDB&#39;s conditional writes guarantee only one process can successfully create that row. If it succeeds, you hold the lock and Terraform proceeds. If someone else already holds it, your write fails instantly and you get an error telling you exactly who&#39;s holding the lock and since when. When the operation finishes, Terraform deletes that row, and the next person in line can grab it.</p><p>One quirk worth knowing before you set this up: you can’t use Terraform to create the S3 bucket and DynamoDB table that Terraform’s own state depends on. That would mean storing the state for creating your state backend somewhere that doesn’t exist yet. So this part gets built manually, once, through the AWS console or CLI, and never touched by Terraform again.</p><h3>Setting it up</h3><p><strong>Step 1: Create the S3 bucket</strong></p><p>In the S3 console, create a bucket with a globally unique name. Turn on versioning (so a corrupted or overwritten state file can be rolled back), leave default encryption on, and keep all public access blocked. State files can contain sensitive values, so none of this is optional.</p><p><strong>Step 2: Create the DynamoDB table</strong></p><p>In the DynamoDB console, create a table with a partition key named exactly LockID, type String. This name isn&#39;t a style choice, Terraform&#39;s S3 backend looks for this exact attribute. Default on-demand billing is enough; a lock table sees a handful of tiny writes, not real traffic.</p><p><strong>Step 3: Point Terraform at both</strong></p><p>The backend configuration lives inside your existing terraform block, next to required_providers:</p><pre>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br><br>  backend &quot;s3&quot; {<br>    bucket         = &quot;kalibee-terraform-state-2026&quot;<br>    key            = &quot;terraform.tfstate&quot;<br>    region         = &quot;us-east-1&quot;<br>    dynamodb_table = &quot;terraform-locks&quot;<br>    encrypt        = true<br>  }<br>}<br><br>provider &quot;aws&quot; {<br>  region = var.aws_region<br>}</pre><p>One catch: the backend block can’t reference variables. Terraform needs to know where the state lives before it even loads your variable definitions, so bucket, key, region, and table name all have to be literal strings.</p><p><strong>Step 4: Migrate</strong></p><pre>terraform init</pre><p>Terraform notices the backend changed and asks whether to copy your existing local state up to S3. Say yes, and from that point on, every plan and apply reads and writes through S3, with DynamoDB enforcing the lock.</p><p>You can view the file from your console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o2Cw7xokTq8ue4SF9dcs_Q.png" /></figure><h4>State Locking in Action</h4><p>To see this for real, I opened two terminals side by side in the same project. In the left pane, I ran `terraform apply`. While it was still acquiring the lock, I fired off `terraform plan` in the right pane, against the exact same state file.</p><p>The left terminal got there first, grabbed the lock, refreshed state, found nothing to change, and released it cleanly: “Apply complete! Resources: 0 added, 0 changed, 0 destroyed.”</p><p>The right terminal wasn’t as lucky. It tried to acquire the same lock a moment later and got an error:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wO1_1oMfq4TjcicA69RApQ.png" /></figure><p>That ConditionalCheckFailedException is the whole mechanism laid bare. DynamoDB tried to write a new lock row with the same LockID as one that already existed, the conditional write rejected it, and Terraform surfaced that rejection as a plain English “someone else is already running an operation against this state, wait your turn.”</p><p>No corrupted state, no race condition, no two processes stepping on each other. Just one clean error instead of a silent mess.</p><h4>Conclusion</h4><p>State locking isn’t about DynamoDB or S3 themselves, it’s about trust. The moment more than one person or process can touch your infrastructure, your state file has to be something everyone agrees on, not something enforced by luck and good timing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89922a56ebe8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>