<?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 Anjana Muthunayake on Medium]]></title>
        <description><![CDATA[Stories by Anjana Muthunayake on Medium]]></description>
        <link>https://medium.com/@anjana-muthuanayake?source=rss-20a3d47e8fa6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cEbLNy-2ySTnSUS5jIdnvA.png</url>
            <title>Stories by Anjana Muthunayake on Medium</title>
            <link>https://medium.com/@anjana-muthuanayake?source=rss-20a3d47e8fa6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:15:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anjana-muthuanayake/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[Half-Ready Pods? How Kubernetes Readiness Probes Save You]]></title>
            <link>https://anjana-muthuanayake.medium.com/half-ready-pods-how-kubernetes-readiness-probes-save-you-f63f755dd959?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/f63f755dd959</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[rolling-updates]]></category>
            <category><![CDATA[kubernetes-updates]]></category>
            <category><![CDATA[kubernetes-probes]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Sun, 23 Nov 2025 17:20:16 GMT</pubDate>
            <atom:updated>2025-11-23T17:20:16.644Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you’re trying to make a cup of coffee using a coffee machine. The machine is on, you grab your cup, and pour… but only hot milk comes out! Where’s the coffee? The machine was “on,” so it seemed ready to serve, but inside, the coffee wasn’t available. You didn’t get the perfect cup because, even though the machine appeared ready, it wasn’t truly ready to serve coffee. Just like in Kubernetes, before sending traffic to a Pod, you need to make sure it has all the necessary “ingredients” inside to serve requests properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r_m7NPkXtL2uj9P4dBW__w.png" /></figure><p>Let’s explore this concept by first looking at a normal Deployment <strong>without a readiness probe</strong>.</p><h3>Let’s Explore Pods Without a Readiness Probe</h3><p>Before diving into readiness probes, let’s see what happens with a normal Deployment without any health checks.</p><h4>Creating the Deployment</h4><p>We’ll start with this YAML configuration for an NGINX deployment:</p><pre># nginx-deploy-baseline.yaml<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  strategy:<br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxSurge: 1<br>      maxUnavailable: 0<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>        - name: nginx<br>          image: nginx:1.21.1<br>          ports:<br>            - containerPort: 80<br>          resources:<br>            requests:<br>              cpu: &quot;100m&quot;<br>            limits:<br>              cpu: &quot;200m&quot;</pre><p>Next, we’ll apply this configuration to create the Deployment:</p><pre>kubectl apply -f nginx-deploy-baseline.yaml</pre><p>Here’s the output after creating the deployment;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/487/1*NtebrDRWDcTMp9pSYfFrOA.png" /><figcaption>Deployment successfully created</figcaption></figure><p><strong>Checking the Deployment</strong></p><p>After deployment, check the rollout status:</p><pre>kubectl rollout status deployment/nginx-deployment</pre><p>Here’s the rollout status cheking output for this deployment;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*EdiTuGLHX7XWJcEp-79uBQ.png" /><figcaption>Roollout status of the deployment</figcaption></figure><p>Now, we’ll check the pods that were created and inspect their properties:</p><pre>      kubectl get pods -l app=nginx -o wide<br>* kubectl get pods --&gt; list the pods<br>* -l app=nginx --&gt; selects pods with the label app=nginx<br>* -o wide --&gt; shows more details like node, IP, and status</pre><p>Why are we listing pods with the label app=nginx?</p><ul><li>This is because in our Deployment configuration, we told Kubernetes to select pods with the label app=nginx:</li></ul><pre>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: nginx  # This is why we filter pods using this label</pre><ul><li>By doing this, we ensure we’re looking at the exact pods managed by this Deployment.</li></ul><p>Here’s the output we get when we run the command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Qo4MUispHUbltjP6pFLWQ.png" /><figcaption>output from the ‘kubectl get pods -l app=nginx -o wide’ command</figcaption></figure><p>We can see both pods listed as READY 1/1 and STATUS Running.</p><h4>But Are These Pods Really Ready?</h4><p>Here’s the catch: <strong>READY = 1/1 only tells us the container process is running</strong>.</p><p>Containers are essentially processes. As soon as the container starts, Kubernetes marks the pod as ready. But inside the container, the NGINX application still has work to do:</p><ul><li>Boot the app</li><li>Parse configuration files</li><li>Warm caches</li><li>Possibly wait for other dependencies</li></ul><p>Without any health checks, Kubernetes has no way to know if the app inside the container is actually ready to serve requests.</p><p>Think of it like our coffee-machine analogy: the machine is <strong>on</strong>, but it doesn’t have all the ingredients. It might pour hot milk without coffee. Similarly, the pod is running, but the app isn’t ready yet.</p><h4>The Solution: Readiness Probes</h4><p>To solve this, Kubernetes provides <strong>readiness probes</strong>.</p><p>A readiness probe ensures that <strong>both the container and the app inside it</strong> are fully ready before marking the pod as ready to receive traffic.</p><p>This prevents Kubernetes from sending requests to a pod that’s technically running but not fully operational.</p><h3>Let’s Explore Readiness probes</h3><p><strong>Readiness probe!</strong> Don’t get confused by the fancy name , there’s no rocket science here. We’re just <strong>sending a simple request</strong> to the app inside the container and checking if it’s actually running and ready to serve users. That’s it!</p><p>Now it’s time to make our deployment smarter. We’ll update the previous deployment configuration by <strong>adding a readiness probe</strong>. Here’s the updated YAML:</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: nginx-deployment<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: nginx<br>  strategy:<br>    type: RollingUpdate<br>    rollingUpdate:<br>      maxSurge: 1<br>      maxUnavailable: 0<br>  template:<br>    metadata:<br>      labels:<br>        app: nginx<br>    spec:<br>      containers:<br>        - name: nginx<br>          image: nginx:1.21.1<br>          ports:<br>            - containerPort: 80<br>          readinessProbe:<br>            httpGet:<br>              path: /<br>              port: 80<br>            # Tuning for quick feedback but avoiding false alarms<br>            initialDelaySeconds: 2<br>            periodSeconds: 5<br>            timeoutSeconds: 1<br>            failureThreshold: 3<br>            successThreshold: 1<br>          resources:<br>            requests:<br>              cpu: &quot;100m&quot;<br>            limits:<br>              cpu: &quot;200m&quot;</pre><h4><strong>Let me explain what are we going to do here:</strong></h4><p>Basically, this readiness probe works by sending a small HTTP request to the app inside the container. Kubernetes looks at the response to decide whether the app is ready to serve traffic. If the app responds correctly (like returning a 200 OK), the Pod is considered ready. If not, the Pod stays NotReady, and Kubernetes won’t send any traffic to it yet. Think of it as checking if your coffee machine actually has all the ingredients before serving your cup, just being “on” isn’t enough.</p><h4>What Changed in the config file?</h4><p>We added a readinessProbe inside the container spec:</p><pre>containers:<br>        - name: nginx<br>          image: nginx:1.21.1<br>          ports:<br>            - containerPort: 80<br>          readinessProbe:<br>            httpGet:<br>              path: /<br>              port: 80<br>            # Tuning for quick feedback but avoiding false alarms<br>            initialDelaySeconds: 2<br>            periodSeconds: 5<br>            timeoutSeconds: 1<br>            failureThreshold: 3<br>            successThreshold: 1</pre><p>Let’s break it down:</p><pre>ports:<br>            - containerPort: 80</pre><ul><li>First, we open port 80 in the container. This is where our readiness probe will send HTTP requests.</li></ul><pre>readinessProbe:</pre><ul><li>This tells Kubernetes how to check if our NGINX app inside the container is actually ready.</li></ul><pre>httpGet:<br>  path: /<br>  port: 80</pre><ul><li>Here, Kubernetes will send a simple HTTP GET request to the / path on port 80 of the container.</li></ul><pre>initialDelaySeconds: 2</pre><ul><li>“Hey Kubernetes, wait 2 seconds after the container starts before sending the first probe.” This gives the app a tiny warm-up time.</li></ul><pre>periodSeconds: 5</pre><ul><li>Send readiness probe every 5 seconds after the initial delay.</li></ul><pre>timeoutSeconds: 1</pre><ul><li>If the container doesn’t respond within 1 second, consider this probe as failed.</li></ul><pre>failureThreshold: 3</pre><ul><li>If 3 consecutive probes fail, Kubernetes marks the Pod as NotReady (ready = False).</li></ul><pre>successThreshold: 1</pre><ul><li>After 1 successful probe, Kubernetes marks the Pod as Ready (ready = True).</li></ul><p>Think of it as a <strong>traffic light</strong> for Kubernetes:</p><pre>Condition                             Status<br>Probe fails 3 times in a row          Red light → Pod NotReady<br>Probe succeeds once                   Green light → Pod Ready</pre><p><em>This setup ensures that the Pod is not just “running” but </em><strong><em>truly ready</em></strong><em> to serve requests before Kubernetes considers it healthy.</em></p><p>Now, let’s apply this updated configuration to create the new Deployment with the readiness probe:</p><pre> kubectl apply -f nginx-deployment-readiness.yaml</pre><h4>Listing the Pods Created by the Updated Deployment</h4><p>Once the Deployment is applied, let’s list the Pods managed by it:</p><pre>kubectl get pods -l app=nginx</pre><p>Actual output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*Qk7KXkWvC-iJdpXIVX5k6A.png" /><figcaption>List pods after readiness probe configuration</figcaption></figure><ul><li>This time, we can confidently say that the Pods created by this Deployment are fully Ready, not partially ready like before.</li></ul><h4>Inspecting One of the Pods</h4><pre>kubectl describe pods nginx-deployment-79f87f48d8-kqcsh</pre><ol><li>Inspect the Container Section</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2NsNbJDsirXC683Y_dgDyQ.png" /><figcaption>Container section of the pod description</figcaption></figure><ul><li>In the container details you can see; Ready:True</li><li>This means the readiness probe has passed, and Kubernetes considers this Pod ready to handle traffic.</li><li>The container isn’t just running , it’s actually ready to serve users.</li></ul><p>2. Inspect the Events Section</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fyn0lHaJtmVzBT2jqF2pyQ.png" /><figcaption>Events section of the pod description</figcaption></figure><p>So what can we understand from the Events section?</p><p>Here’s the lifecycle you can observe:</p><ol><li><strong>Scheduler assigns the Pod</strong><br>The Kubernetes Scheduler selected the first-worker node as the best place to run this Pod. The scheduler sends those instructions to that node’s kubelet.</li><li><strong>Kubelet receives instructions</strong><br>The kubelet then takes over and is responsible for actually creating the Pod on that node.</li><li><strong>Container runtime creates the container</strong><br>Kubelet passes the request to the container runtime (like containerd), which pulls the image and starts the container.</li><li><strong>Readiness probe kicks in</strong><br>After the container starts, kubelet begins running the readiness probe checks.<br>It keeps probing until the app responds correctly, only then the Pod becomes Ready.</li></ol><h3>How Does a Readiness Probe Actually Work?</h3><p>Now that we added a readiness probe to our Deployment, let’s quickly understand how this whole thing works internally.</p><p>Step-by-Step What Happens Behind the Scenes:</p><p>1️⃣ <strong>Who sends the readiness probe request?</strong></p><ul><li>It’s not your app, not your container, not the Deployment.</li><li>It’s the Kubelet, the small agent running inside every Kubernetes node.</li></ul><p>Whenever your Pod is scheduled to a node, the kubelet in that node takes responsibility for checking:</p><pre>&quot;Hey container, are you actually ready to serve traffic?&quot;</pre><p>So kubelet is the one who sends the readiness probe request.</p><p>2️⃣ <strong>Where does the probe request go?</strong></p><ul><li>Kubelet doesn’t send this request outside the cluster.</li><li>It doesn’t talk to the public IP.</li><li>It doesn’t even leave the node.</li><li>It sends the probe directly inside the Pod’s network namespace, targeting:</li></ul><p>1. The Pod’s internal IP</p><p>2. The container’s port (ex: 80)</p><p>3. The path you defined (ex: /)</p><ul><li>Basically:</li></ul><pre>kubelet → pod internal IP → container port → app endpoint</pre><ul><li>All of this happens inside the node itself.</li></ul><p>3️⃣ <strong>Who decides Ready vs NotReady?</strong></p><ul><li>After sending the probe, kubelet waits for a response from the application.</li><li>Here’s how kubelet decides:</li></ul><ol><li>If the app returns a successful response (like <strong>200 OK</strong>) →<br> ✔️ <strong>Container is Ready</strong></li><li>If the app returns an error or does NOT respond within the timeout →<br> ❌ <strong>Container is NotReady</strong></li></ol><h4>Readiness Probe: Behind-the-Scenes Flow</h4><pre>Kubelet (running on the node)<br>        │<br>        ▼<br>Pod Network Namespace<br>        │<br>        ▼<br>Container Port (example: 80)<br>        │<br>        ▼<br>Application Endpoint <br>        │<br>        ▼<br>Kubelet marks Pod Ready / NotReady</pre><h4>❌ Let’s Break the Readiness Probe on Purpose (To See What Really Happens)</h4><p>So far our pods were always Ready, nice and clean.<br>But that doesn’t teach us what happens when things go wrong, right?</p><p>So let’s do a small trick: we’ll intentionally break the readiness probe and observe how Kubernetes reacts.</p><p><strong>Breaking the readiness probe:</strong></p><p>All we are going to do is change the probe path to something that does not exist.</p><pre>          readinessProbe:<br>            httpGet:<br>              path: /does-not-exist   # break readiness on purpose<br>              port: 80<br>            initialDelaySeconds: 2<br>            periodSeconds: 5<br>            timeoutSeconds: 1<br>            failureThreshold: 3<br>            successThreshold: 1</pre><p><strong>What happens here;</strong></p><p>path: /does-not-exist</p><ul><li>Did we configure this path in our NGINX app? ❌ No</li><li>Does this path exist inside the container? ❌ No</li></ul><p>So when kubelet sends the readiness probe request to:</p><pre>http://&lt;pod-ip&gt;:80/does-not-exist</pre><p>The app will obviously NOT return 200 OK.</p><p>Instead, kubelet will keep getting:</p><ul><li>404 Not Found, or</li><li>timeout</li></ul><p>And since our probe is configured to fail after 3 tries, kubelet will mark the container as NotReady.</p><p><strong>Apply the broken configuration</strong></p><pre> kubectl apply -f nginx-readiness-broken.yaml</pre><p><strong>Now check the rollout status:</strong></p><p>I added --timeout=60s || true<br>because otherwise the command will keep waiting forever since the rollout will never complete.</p><pre>kubectl rollout status deployment/nginx-deployment --timeout=60s || true</pre><p><strong>Actual output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*uVy4iiY0yy62qFMrjpyeNA.png" /><figcaption>rollout status of updated deployment</figcaption></figure><ul><li>As expected rollout timed out.</li><li>Kubernetes is waiting for ready pods… but none ever become ready.</li></ul><p><strong>Check the pods</strong></p><pre>kubectl get pods -l app=nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*qCZCHT1SU_TnRzTCRup3cQ.png" /><figcaption>inspect pods created from the deployment</figcaption></figure><p>Look closely at the highlighted pod:</p><ul><li>STATUS: <strong>Running</strong></li><li>READY: <strong>1/0</strong></li></ul><p>That 1/0 is very important.</p><p><strong>What does READY 1/0 mean?</strong></p><p>It means:</p><ul><li>the container is <em>running</em></li><li>but 0 containers passed readiness probe</li></ul><p>So the pod is alive…<br> but NOT allowed to serve traffic.</p><p><strong>Kubernetes is basically saying:</strong></p><p><em>“I know the container is running, but it’s not healthy enough to send traffic to.”</em></p><ul><li>This is why from this rollout, zero ready pods were created,<br>the only available pods are from the previous successful deployment.</li></ul><p><strong>Let’s inspect the failing pod</strong></p><pre>kubectl describe pod nginx-deployment-5fdd5f49c-n7244</pre><p><strong>Let’s see the container section first;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dU6TrMgZ5Vz4a6MmPlG57g.png" /><figcaption>Container section of failing pod</figcaption></figure><p>You can see clearly:</p><p><strong>Ready: False</strong></p><p>That means:<br>The readiness probe test failed → Pod stays NOT ready.</p><p><strong>Events section;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHAZzIcowg-v3Bu9zjq9Ng.png" /><figcaption>Events section of failing pod</figcaption></figure><p>Here you can see the exact reason:</p><p><strong>“Readiness probe failed with status code: 404”</strong></p><p>Which makes perfect sense;<br> → we told kubelet to send a request to a path that does not exist.</p><h4>Readiness Probe with Rolling Updates</h4><p>Now that we’ve seen how a broken readiness probe stops a rollout, let’s fix things and see how readiness probes behave during an actual rolling update.</p><p><strong>Step 1: Fix the broken path</strong></p><p>Go back to the readiness probe and change:</p><pre> path: /does-not-exist</pre><p>back to:</p><pre>path: /</pre><p>Then reapply the deployment so Kubernetes can get healthy pods again.<br>Once applied, your pods will return to the lovely state of <strong>Ready = True</strong>.</p><p><strong>Step 2: Trigger a rolling update</strong></p><p>Let’s update the image version:</p><pre>kubectl set image deploy/nginx-deployment nginx=nginx:alpine</pre><p>Now check the rollout status:</p><pre>kubectl rollout status deploy/nginx-deployment</pre><p>Actual rollout status:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*WaBaS8_OCf4di8y3-MeBdA.png" /><figcaption>Rollout status</figcaption></figure><p>This output clearly shows what’s happening:</p><ul><li>New pods are created</li><li>Old pods are gracefully terminated</li><li>Rollout completes only when new pods become Ready</li></ul><p>This is exactly how rolling updates should behave.</p><p><strong>Step 3: Check the ReplicaSets created</strong></p><pre>kubectl get rs -l app=nginx</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*Esju-Y8GWV5txuizKEqnDA.png" /><figcaption>created replicaset</figcaption></figure><p>You can see the new ReplicaSet at the bottom.<br>Its DESIRED, CURRENT, and READY values all show <strong>2</strong>, which means:</p><ul><li>2 pods should exist</li><li>2 pods were created</li><li>2 pods passed readiness probe</li></ul><p>Perfect rollout ✨</p><p><strong>Step 4: Inspect the new pods</strong></p><pre>kubectl get pods -l app=nginx -o wide</pre><p>Output;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t9Fs9nJuH1yk26jGHqK7Ww.png" /><figcaption>inspect new pods</figcaption></figure><p>Both pods:</p><ul><li>are <strong>Running</strong></li><li>show <strong>1/1 Ready</strong></li><li>live on different worker nodes</li><li>passed readiness probe</li></ul><p>That means these pods are <strong>actively serving traffic</strong>.</p><p><strong>Step 5: Inspect one of the new pods</strong></p><pre>kubectl describe pod nginx-deployment-7f6879cf48-stb7c</pre><p>In the Events section, you’ll see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zZxNdCm-fzekNzWxAxwHBw.png" /><figcaption>Events section of new pod</figcaption></figure><p><strong>What does this tell us?</strong></p><ul><li>The Scheduler picked a node (first-worker)</li><li>It passed instructions to that node’s kubelet</li><li>Kubelet asked the container runtime to:</li></ul><ol><li>pull the new image</li><li>create the container</li><li>start the container</li></ol><ul><li>Then kubelet ran the readiness probe</li><li>Only after passing the probe → Pod becomes Ready</li></ul><p>This is the exact flow every time a pod is created or updated.</p><h4>A small but important fact</h4><p>A pod can have multiple containers.<br>In such cases:</p><ul><li>each container gets its own readiness probe</li><li>the pod becomes Ready only if <em>all</em> containers pass their readiness checks</li></ul><p>Even if one container fails → the whole Pod stays NotReady.</p><p><em>See? Nothing magical. No rocket science.<br>Just Kubernetes politely asking your app:<br> “Hey… you good to serve traffic now?”</em></p><p><em>When your pods proudly say </em><strong><em>YES</em></strong><em>, your rollouts become smooth, clean, and elegant, just like you want them.<br>So go ahead, make your pods ready, not moody.</em></p><p><em>Catch you in the next article - where we keep leveling up, one YAML at a time! 😎☕💙</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f63f755dd959" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Private VMs Internet-Ready with Azure Networking ➡️]]></title>
            <link>https://anjana-muthuanayake.medium.com/making-private-vms-internet-ready-with-azure-networking-%EF%B8%8F-3d90418183b2?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d90418183b2</guid>
            <category><![CDATA[private-subnet]]></category>
            <category><![CDATA[nat-gateway]]></category>
            <category><![CDATA[azure-cloud]]></category>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[azure-bastion]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Thu, 02 Oct 2025 19:47:33 GMT</pubDate>
            <atom:updated>2025-10-03T03:23:01.776Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey, imagine you spin up a VM on the cloud. Simple, right? Give it a public IP, SSH into it, install your app, build your app,and boom - done! But wait… what if that VM doesn’t have a public IP? Suddenly, that VM is sitting inside a private subnet - cut off from the internet and unreachable directly from your laptop.</p><p>Now you’re stuck with a puzzle:</p><ul><li>How do you access it?</li><li>How do you install updates or fetch packages when it can’t reach the internet?</li><li>And most importantly, how do you make your shiny new app inside that VM visible to the world?</li></ul><p>That’s where the magic of Azure networking comes in. Buckle up - we’re about to turn this invisible VM into a world-accessible app.</p><h3><strong>Step 1: Log in to the Azure Portal</strong></h3><p>First, go to the <strong>Azure Portal</strong> and sign in to your account. This is where you’ll manage all your Azure resources - VMs, virtual networks, subnets, and Load Balancers.</p><p>💡 <strong>Tip:</strong> Double-check you’re in the correct subscription before creating resources.</p><h3><strong>Step 2: Create a Resource Group</strong></h3><p>Before we start creating VMs, networks, and Load Balancers, we need a <strong>Resource Group (RG)</strong>. Think of it as a folder that keeps all related resources together - makes management, monitoring, and deletion way easier.</p><p>💡 <strong>Why create one?</strong> It’s better to create a fresh RG for each project or experiment. Keeps everything neat, organized, and easy to manage.</p><p><strong>Quick things to keep in mind:</strong></p><ul><li><strong>Region matters:</strong> Pick a region that supports all the resources you plan to create. No point choosing a place where your VM or Load Balancer can’t exist.</li><li><strong>Subscription check:</strong> Make sure you’re creating it under the correct Azure subscription.</li></ul><p><strong>Screenshot time! Here’s how we create our project’s resource group:</strong></p><ol><li><strong>Starting Your Resource Group Creation:</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*dueGGo2xQnQap-hpWuUE6Q.jpeg" /><figcaption>Navigate to <strong>Resource Groups</strong> in the Azure portal and click <strong>Create</strong></figcaption></figure><p>2. <strong>Setting Up Resource Group Basics</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*yklRG_Ua8PuVcQ-FtxMEAA.jpeg" /><figcaption>Configure the basics: choose <strong>Subscription</strong>, enter <strong>Resource Group Name</strong>, and select the <strong>Region</strong></figcaption></figure><p>Boom! Your RG is ready, and now we have a neat home for all the resources we’re about to create.</p><h3>Step 3: Create a Virtual Network (VNet)</h3><p>Next up, we need a <strong>Virtual Network (VNet)</strong>. Think of a VNet as your cloud’s private neighborhood - a space where all your VMs, subnets, and other resources live and can talk to each other securely. Without a VNet, your resources would have no organized network to connect through.</p><p>💡 <strong>Why do we need a VNet?</strong></p><ul><li>It keeps your resources <strong>isolated and secure</strong>.</li><li>Lets you <strong>control traffic flow</strong> between subnets and resources.</li><li>Enables integration with <strong>load balancers, VPNs, and other network services</strong>.</li></ul><p><strong>Things to consider when creating a VNet:</strong></p><ul><li><strong>CIDR Range:</strong> Decide the IP range for your network (e.g., 10.0.0.0/16). This defines how many IPs are available for your subnets and VMs.</li><li><strong>Resource Group:</strong> Make sure you select the correct RG you just created.</li><li><strong>Subscription:</strong> Always double-check - you don’t want to accidentally create it under the wrong subscription.</li><li><strong>Region:</strong> Pick a region close to your users or other resources for lower latency.</li></ul><p><strong>Let’s take a visual tour of our VNet setup:</strong></p><ol><li><strong>Start Creating a Virtual Network (VNet)</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6L97W9ejbadkENjkAgiXA.jpeg" /><figcaption>Navigate to <strong>Virtual Networks</strong> in the Azure portal and click <strong>Create VNet</strong>.</figcaption></figure><p>2. <strong>Set Up VNet Basics</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*ooXfnp1owUGlEI9LoBI5Rw.jpeg" /><figcaption>Configure the basics: select the <strong>Subscription</strong>, choose your <strong>Resource Group</strong>, give your <strong>VNet a name</strong>, and pick the <strong>Region</strong>.</figcaption></figure><p>Awesome! We’re halfway through setting up our VNet. Next up, it’s time to carve out subnets and fine-tune their features so each VM knows exactly where to live.</p><h3><strong>Step 4: Private VM? No Problem! Bastion to the Rescue</strong></h3><p>Ever wondered how to reach a VM trapped in a private subnet? Enter the Bastion Host - your secure jumping-off point! 🏰 This is just another VM, but with a special role: it gives you secure SSH or RDP access to your private VMs over TLS (port 443).</p><p>Here’s the magic : the Bastion Host itself has a public IP and DNS, so you connect to it first. From there, you can “jump” into your private VMs without ever exposing them directly to the internet.</p><p>But wait, Bastion needs its own little home, so we create a dedicated Bastion subnet inside our VNet. Why? Azure requires it for isolation and security, so our Bastion can safely act as the bridge without exposing the private VMs directly to the internet.</p><p>Problem solved - private VM? No worries, we’ve got the secure bridge!</p><p>Here’s how we bring our Bastion Host to life: configure its security settings, assign a public IP, and check out the dedicated Bastion subnet inside our VNet. 🔍</p><ol><li><strong>Configure Bastion Host</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*ySJlYW9LDbnsZtD1lMpUPw.jpeg" /><figcaption>Configure Security Section: Enable Bastion Host and set its name, Create a Public IP Address for Bastion Host</figcaption></figure><p>2. <strong>View Bastion Subnet in the VNet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*8OJ62ak8lacbl4h1V6fM2A.jpeg" /><figcaption>View the dedicated Bastion subnet inside the VNet</figcaption></figure><h3>Step 5: Public Subnet - Our Gateway to the Internet 🌐</h3><p>Before our private VMs can fetch software updates or talk to the outside world, they need a buddy with internet access. Enter the <strong>public subnet</strong> - a subnet with a direct connection to the internet.</p><p>Here’s what we do:</p><ol><li>Edit your VNet’s default subnet and turn it into a <strong>public subnet</strong> - this gives your resources a direct path to the internet. Or, if you prefer, delete the default subnet and create a brand-new public subnet from scratch.</li><li>Make sure it has a route to the internet</li><li>Resources in this subnet can now directly access the internet, and resources in private subnets can use it as a bridge when needed.</li></ol><p><strong>Here’s how we turn our default subnet into a public subnet so our VMs can talk to the internet:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GnTr9LDm4zCv4ZReRH0GdA.jpeg" /><figcaption><em>Select ‘✏️’ mark to edit default subnet, Give subnet name, CIDR range &amp; Save</em></figcaption></figure><h3><strong>Step 6: Creating the Private Subnet - Your Secure Hideout</strong></h3><p>Next, we create a <strong>private subnet</strong>. This subnet keeps your VMs isolated from the internet, ensuring sensitive apps or databases stay secure. Only resources like the Bastion Host can access it - think of it as a safe, behind-the-scenes area for your network.</p><p>Here’s how we carve out a private subnet for our VMs, keeping them safe and isolated while still connected to the network.</p><ol><li><strong>Add a New Subnet</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/782/1*TFXJB4AfUhdlgGD_i0waPw.jpeg" /><figcaption>Select ‘+ Add a subnet’</figcaption></figure><p>2. <strong>Configure Subnet Name &amp; CIDR Range</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*uRlEmxY11mnBAI8vEgkM8A.jpeg" /><figcaption><em>Give subnet name &amp; CIDR range</em></figcaption></figure><p>3. <strong>Enable Private Subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*DD-qAoT8Grh_N93TvBjshA.jpeg" /><figcaption>Enable private subnet</figcaption></figure><p>Great, our private subnet is halfway ready - secure and isolated. Let’s move on to the next steps!</p><h3>Step 7: NAT Gateway - Giving Private Subnets Internet Access 🌐</h3><p>Now we can reach our private VMs through the Bastion Host - nice! But wait… does this solve our whole problem? Can these VMs still access the internet to fetch updates or install software? Nope.</p><p>Enter the NAT Gateway (Network Address Translation). By attaching a NAT Gateway to our private subnet and linking it to a public IP in our public subnet, our private VMs get a way to reach the internet securely. The NAT Gateway translates the private IPs of our VMs into a public IP for outbound traffic, letting them install packages, download updates, or communicate with external services - all without exposing the VMs directly to the internet.</p><p>💡 Let’s create a NAT Gateway and attach it to our private subnet - the next essential step in getting our private VMs online.</p><ol><li><strong>Create a New NAT Gateway</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*6t1nnIYjhyAm6iwNhyi2SA.jpeg" /><figcaption><em>Select NAT gateway &amp; ‘Create new’</em></figcaption></figure><p>2. <strong>Set NAT Gateway Details and Assign Public IP</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*HXX6WyEWA_l62zcuDZsH8g.jpeg" /><figcaption>Configure NAT gateway name, Select New Public IP address</figcaption></figure><p>3. <strong>Add the subnet to the vnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*o2ThaXNSX8tR-bz2vTFlcQ.jpeg" /><figcaption><em>View the created NAT gateway &amp; select ‘Add’ to add the subnet to the vnet</em></figcaption></figure><h3>Step 8: <strong>Private VM in Action: Access via Bastion Host</strong></h3><p>Now it’s time to see our setup in action! 🚀 Let’s create a VM in the <strong>private subnet</strong> and test accessing it through our trusty <strong>Bastion Host</strong>. This is where all the pieces we’ve configured so far come together - the private VM, the Bastion subnet, and secure access over TLS.</p><p><strong>Step 8.1: Create the Private VM</strong></p><p>Time to bring our private subnet to life! 🎉 Let’s spin up a VM inside it. This VM won’t have a public IP, so you won’t be able to reach it directly from your laptop. That’s why we have our trusty Bastion Host ready.</p><p>When creating the VM, make sure to:</p><ul><li>Select the <strong>private subnet</strong> you created earlier.</li><li>Pick a <strong>Linux image</strong> of your choice.</li><li>Configure <strong>username and authentication</strong> (password or SSH key).</li><li>Keep <strong>no public IP</strong> - remember, we want to test Bastion access!</li></ul><p><strong>Follow these steps to spin up a VM in the private subnet.</strong></p><ol><li><strong>Kickstart Your VM Creation</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8gfI4a_9-gtqNB-LXUcS7Q.jpeg" /><figcaption>Navigate to the Virtual Machines page and click ‘Create’</figcaption></figure><p>2. <strong>Set the Basics: Subscription, RG, Name &amp; Region</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*RM0U-rcu7aLrSlV00Z1buA.jpeg" /><figcaption>Create VM: select subscription, resource group, VM name, and region</figcaption></figure><p>3. <strong>Pick Your Zone, OS &amp; Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*m4qx0Mn87BcDDyPKNLhelQ.jpeg" /><figcaption>Select Availability Zone, OS image &amp; VM architecture</figcaption></figure><p>4. <strong>Size It &amp; Configure Your Admin Credentials</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*KRDGTC98_fR42_IIoNeWoQ.jpeg" /><figcaption>Select VM size and configure admin account (username &amp; password)</figcaption></figure><p>5. <strong>SSH &amp; HTTP Access</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*1leUPOBmOd7G4NgMh2Xaxw.jpeg" /><figcaption>Configure inbound port rules: allow SSH (22) and HTTP (80)</figcaption></figure><p>6. <strong>Plug Into the Network: Private Subnet, No Public IP</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*A9ahrzGUerd2xbA8Mclj5A.jpeg" /><figcaption>Configure Networking: choose VNet, private subnet, No Public IP, set inbound ports</figcaption></figure><p>7. <strong>It’s Time to Review Before Create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*bjINxojxxRUugeN_utdgTQ.jpeg" /><figcaption>Select ‘Review + create’</figcaption></figure><p>8. <strong>Deploy the VM</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/1*wb4xEiXDJZDn7oxQ9aZBfw.jpeg" /><figcaption>Final step: Validation passed ✔️, hit Create to deploy the VM</figcaption></figure><p>And that’s it - our private VM is deployed and ready. Next, we’ll access it securely through the Bastion Host.</p><p><strong>Step 8.2: Access the Private VM via Bastion Host</strong></p><p>Now comes the moment of truth - let’s access our VM in the private subnet. Remember, it has no public IP, so direct SSH or RDP is impossible. That’s where our Bastion Host steps in.</p><p>From the Azure portal:</p><ol><li>Go to <strong>Virtual Machines</strong> and select your private VM.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4dmSDZOS-nLpIhnp4bBcg.jpeg" /><figcaption>Go to your private VM</figcaption></figure><p>2. Click <strong>Connect</strong> → <strong>Bastion</strong>.</p><p>3. Enter the admin username and password you set when creating the VM.</p><p>4. Hit <strong>Connect</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*QujRk-Vpt1QVlG0hrUNBDQ.jpeg" /><figcaption>Go to connect &amp; Select ‘Bastian’, Give admin username &amp; password &amp; select ‘connect’</figcaption></figure><p>5. Connect to VM via Bastion Host in a new browser window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*oTZtqoiy2hBP6YlPveFnKA.jpeg" /><figcaption>Connect to VM via Bastion Host in a new browser window</figcaption></figure><p>Mission accomplished - we’ve reached our private VM through Bastion, no public IP required!</p><h3>Step 9: Installing NGINX — Making Our Private VM a Web Server</h3><p>Now that we’ve successfully accessed our private VM via the Bastion Host, it’s time to put it to work. Remember, this VM sits in a private subnet with <strong>no public IP</strong>, so direct internet access is impossible. How do we update it or install software? That’s where our <strong>NAT Gateway</strong> steps in. 🌐</p><p>The NAT Gateway acts as a bridge between the private subnet and the internet. When our VM reaches out to download packages or software like <strong>NGINX</strong>, the NAT Gateway translates its private IP into a public IP. This allows the VM to fetch everything it needs safely, without ever exposing itself directly to the outside world.</p><p>Here’s what we do next:</p><ol><li>Open the browser-based terminal connected to the private VM via the Bastion Host.</li><li>Update the package list to make sure the VM can pull the latest software:</li></ol><pre>sudo apt update</pre><p>If you see the packages being updated, voilà! 🌐 The NAT Gateway we configured earlier is doing its job - our private VM can now reach the internet.</p><p>3. Install <strong>NGINX</strong> to turn this VM into a web server:</p><pre>sudo apt install -y nginx</pre><p><strong>Why NGINX? </strong>Installing NGINX turns our private VM into a simple web server. This lets us test in the next steps whether our VM is accessible from the internet -serving content even though it started off completely hidden in a private subnet.</p><p>4. Start NGINX and enable it to run at boot:</p><pre>sudo systemctl start nginx<br>sudo systemctl enable nginx</pre><p>5. Check the status of NGINX:</p><pre>sudo systemctl status nginx</pre><p>If you see active: running, congratulations - your VM is now a web server and ready to serve content!</p><h3>Step 10: External Load Balancer -Opening the Gateway 🌐</h3><p>Now that our VM can access the internet, we’ve installed NGINX and turned it into a web server. But here’s the question: can someone else access it through their browser? The answer is <strong>no</strong>.</p><p>Why not? There are a couple of reasons:</p><ul><li>Our VM doesn’t have a <strong>public IP</strong> or <strong>public DNS</strong>, so it’s invisible to the outside world.</li><li>It resides in a <strong>private subnet</strong>, which keeps it isolated from external traffic.</li></ul><p>This is where the <strong>External (Public) Load Balancer</strong> comes to the rescue. By creating a public load balancer and adding our VM to its backend pool, we can expose our VM to the internet safely. The load balancer gets a <strong>public IP</strong> and acts as the gateway: when someone accesses the load balancer’s public IP, it routes the traffic to our VM in the private subnet.</p><p>In short: <strong>private VM + NGINX + external load balancer = a web server that’s now accessible from the internet!</strong></p><p>Time to flip the switch! ⚡ Let’s give our hidden VM a public face with an external load balancer.</p><ol><li><strong>Navigate to Load Balancers → Create → Standard Load Balancer</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1WSpNiy_IDCAtaoKt2maQ.jpeg" /><figcaption><em>Navigate to load balancers select ‘Create’ -&gt; Standard Load Balancer</em></figcaption></figure><ul><li>This is where we start creating our external load balancer that will give our private VM a public endpoint.</li></ul><p><strong>2. Configure Load Balancer Basics</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*ebvyf-RcNItIMnm0vaGXKQ.jpeg" /><figcaption>Select subscription, resource group, elastic load balancer name, region, type-public, select ‘Next’</figcaption></figure><ul><li>In this step, we set the essentials for our external load balancer: choose the subscription, resource group, give it a name, select the region, and set the type to <strong>Public</strong>. Once done, click <strong>Next</strong> to proceed with further configuration.</li></ul><p><strong>3. Configure Frontend IP</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*YQRlXSPJ-keqP5co1DlFlQ.jpeg" /><figcaption>Frontend IP config - IP name, select ‘Public IP address’-&gt; ‘Create new’</figcaption></figure><ul><li>The <strong>frontend IP</strong> is the public-facing entry point of the load balancer. Here, we create a new public IP address that will be used by the load balancer to receive traffic from the internet. This is where external users will connect to access our private VM indirectly.</li></ul><p><strong>4. Save Public IP Configuration</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*elmk0qW5aWna1l0F7k9ugg.jpeg" /><figcaption>Created public IP address, select ‘Save’</figcaption></figure><ul><li>After creating the public IP, we save the configuration so that the load balancer can use this IP as its frontend. This ensures that any incoming traffic to this IP will be directed through the load balancer to our backend VMs.</li></ul><p><strong>5. Create Backend Pool</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*IHHC77NVNr5r-dEM7MZrfw.jpeg" /><figcaption>Select ‘Add backend pool’</figcaption></figure><ul><li>Here, we simply create the backend pool. This acts as a container for the VMs that will receive traffic from the load balancer. In the next step, we’ll configure which VMs go into this pool.</li></ul><p><strong>6. Configure Backend Pool</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IhmsbaOslgT_vnBYhez2tw.jpeg" /><figcaption><em>Give backend pool details</em></figcaption></figure><ul><li>In this step, we define the backend pool by giving it a name, selecting the VNet, and specifying the IP addresses of the VMs that will handle incoming traffic. This tells the load balancer exactly where to forward requests.</li></ul><p><strong>7. Add Load Balancing Rule</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WS07DDQh7_W2c-TzsYXkIw.jpeg" /><figcaption>Configure ‘Inbound rules’, select ‘Add load balancing rule’</figcaption></figure><ul><li>Click <strong>Add load balancing rule</strong> to start configuring how incoming traffic will be distributed to your backend VMs. This is the first step before defining ports, protocol, and target backend pool.</li></ul><p><strong>8. Configure Load Balancing Rule</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*V4pZ-6fSHqAkT97J5BFXSw.jpeg" /><figcaption><em>Set name, frontend IP address, backend pool, backend port</em></figcaption></figure><ul><li>Here, we define the specifics of the load balancing rule: give it a name, select the frontend IP (public endpoint), assign the backend pool (our private VM), and set the backend port. This ensures traffic hitting the public IP is properly routed to the VM.</li></ul><p><strong>9. Create Health Probe</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*8PEYDWRRrv_b7cdTte_pVw.jpeg" /><figcaption>Go to ‘Health probe. &amp; select ‘Create new’</figcaption></figure><ul><li>Here, we start setting up the health probe. Creating a new probe is the first step to later monitor the VM’s health so the load balancer can send traffic only to healthy, responsive instances.</li></ul><p><strong>10. Configure Health Probe</strong></p><p>In this step, we configure the health probe for our load balancer. Screenshot of the health probe setup is not captured, but here’s what we configured:</p><ul><li><strong>Protocol:</strong> HTTP (so the probe can check the web server’s response)</li><li><strong>Port:</strong> 80 (NGINX default web port)</li><li><strong>Path:</strong> / (the root of the web server)</li><li><strong>Interval &amp; Unhealthy threshold:</strong> How often the probe checks the VM and how many consecutive failures mark the VM as unhealthy</li></ul><p>The health probe continuously monitors the VM and ensures the load balancer only sends traffic to healthy VMs.</p><p><strong>11. View Created Health Probe &amp; Save</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*JIatZ-WAq1TngOrGzZkA7w.jpeg" /><figcaption>View created health probe &amp; Save</figcaption></figure><ul><li>Here we can see the name of the health probe we created. This confirms that the probe exists and is ready to monitor the backend VM’s status once the load balancer is active. Then we save the configuration.</li></ul><p><strong>12. Validation Passed &amp; Create Load Balancer</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/798/1*MVJlRiZGtMmQTGKAUrdLZA.jpeg" /><figcaption>Validation passed &amp; select ‘Create’</figcaption></figure><ul><li>After configuring all the settings - frontend IP, backend pool, load balancing rules, and health probe - Azure validates the configuration. Once it passes, selecting <strong>Create</strong> deploys the external load balancer, giving our private VM a public endpoint.</li></ul><h3>Step 11: Test Your Web Server from the Internet</h3><p>Now that our external load balancer is up and running, it’s time for the ultimate test: can anyone access our private VM from the internet?</p><p>Here’s how we do it:</p><ol><li>Go to your crated Load Balancer in the Azure portal.</li><li>Copy the public IP assigned to your load balancer.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gI9VLT9dtRvNsUNXApdHSw.jpeg" /><figcaption>Go to load balancer &amp; View Public IP &amp; Copy it</figcaption></figure><p>3. Open a browser and type http://&lt;public IP&gt; into the address bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d1ybeKN_Ww5y4BvS_nB_hQ.jpeg" /><figcaption>Verify in browser using load balancer public IP</figcaption></figure><p>If everything is configured properly, you should see the default NGINX page - proof that our private VM is now safely reachable via the internet.</p><p>And there we have it! What started as a VM tucked away in a private subnet, completely unreachable - now serves content to the world 🌍. From setting up the VNet and subnets, to bringing in our Bastion Host, configuring the NAT Gateway, and finally exposing it through an external load balancer, we’ve turned the invisible into the visible. Azure networking isn’t just about moving bits and bytes - it’s about solving real problems in smart, secure, and elegant ways. So go ahead, experiment, break things (safely!), and build your cloud magic! ✨</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8DHo_jDmBD9rISeZbPRbbA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d90418183b2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Click Less, Automate More: Deploying a Highly Available Web App on AWS with CloudFormation ☁️]]></title>
            <link>https://anjana-muthuanayake.medium.com/click-less-automate-more-deploying-a-highly-available-web-app-on-aws-with-cloudformation-%EF%B8%8F-fa493174048a?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa493174048a</guid>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-cloudformation]]></category>
            <category><![CDATA[high-availability]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Thu, 25 Sep 2025 20:20:58 GMT</pubDate>
            <atom:updated>2025-09-25T20:20:58.268Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine this: you’re asked to deploy a web application on an EC2 instance. Not too bad, it’s a two-tier setup with a web server and an RDS database. You carefully go through the steps, configure everything, and proudly complete the deployment.</p><p>Then comes the twist -<em>“Can you create two more of the same setup?”</em> Sure, you think, why not? You start again, step by step, but halfway through the second deployment… bam 💥, an error! Turns out you forgot to create a security group for the web server. No worries, you fix it and keep going.</p><p>Now you’re on the third one. Things seem smooth - until the app fails to connect to the database. Why? You forgot to configure the RDS credentials in your app. 😅 It’s not that you don’t know the steps - it’s that repeating the same manual process over and over is exhausting, and let’s be honest, humans <em>will</em> make mistakes when it gets repetitive.</p><p>By now, you’re tired, frustrated, and probably thinking: <em>“There has to be a better way, right?”</em> And then you remember that golden line you once heard: <strong>“If something is repetitive, automate it.”</strong> 💡</p><p>That’s when you discover the magic of <strong>AWS CloudFormation</strong>. Instead of manually building each piece, you write your infrastructure in a simple YAML/JSON file, upload it, click a ‘Submit’ button, and… AWS handles the rest. No forgotten security groups, no missed DB configs, no endless clicks - just automation at its best. 🚀</p><p>Wanna know how I did it? Let me walk you through my journey with CloudFormation…</p><h3><strong>Step 1: Pick Your Favourite Text Editor ✍️💻</strong></h3><p>Before diving into CloudFormation, you’ll need a comfy spot to write your template. If you’re on Linux, you can go with classics like vi, vim, or nano. On Windows, even Notepad will do the job.</p><p>I personally choose <strong>Visual Studio Code</strong> because it’s super convenient, easy on the eyes, and comes with handy extensions that save me from YAML headaches 😅. But at the end of the day, this is <em>all about your preference</em> - pick the editor you vibe with most, because that’s where you’ll be spending your time.</p><h3><strong>Step 2: Create Your template File 📝</strong></h3><p>Now that you’ve got your favorite text editor, it’s time to create your CloudFormation template, either in <strong>JSON</strong> or <strong>YAML</strong> format. And yes, I know what you’re thinking: <em>“Which one should I pick?”</em></p><p>Honestly, go with what feels comfortable to you. Both have their quirks:</p><ul><li><strong>YAML</strong> is super readable and neat, but you need to nail the indentation perfectly - one wrong space and your template throws a fit 😅.</li><li><strong>JSON</strong> is more strict with syntax: brackets everywhere, brackets inside brackets, brackets inception-style. Imagine a really long template -you’ll feel like Buzz Lightyear saying, “To infinity… and beyond!” 🚀, juggling all those brackets at once.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/297/1*lcWQsjXbF9KXXYpPvMiUKQ.png" /></figure><p>Personally, I lean towards <strong>YAML</strong> for my automation scripts. It just feels cleaner and easier to read. But fun fact: you don’t have to stress too much about picking the “right” format. There are plenty of tools out there that will automatically check your syntax, fix indentation issues, and rescue you from bracket nightmares.</p><p>So, pick your format, breathe, and let’s dive into creating your first CloudFormation template! 🌟</p><h3><strong>Step 3: Set the Stage with a Format Version</strong></h3><p>Alright, now that you’ve picked your file format and editor, it’s time to officially start your CloudFormation template. First thing on the list: the <strong>format version</strong>.</p><p>Think of it like putting a date on your homework or a version number on your favorite game, it tells AWS, <em>“Hey, this is the ruleset I’m following!”</em></p><p>For CloudFormation, we use:</p><pre>AWSTemplateFormatVersion: &quot;2010-09-09&quot;</pre><p>This line basically says, <em>“I’m using the 2010–09–09 version of the CloudFormation format.”</em> Simple, right? It doesn’t create any resources by itself.</p><p><strong>Fun fact:</strong> this version has been used for years, so you don’t have to worry about it. 🚀</p><p>And yes - including this line is totally optional! But adding it makes your template look neat and future-proof, so I recommend keeping it.</p><h3><strong>Step 4: Plan What We’re Going to Build 🏗️</strong></h3><p>Before we start creating resources in CloudFormation, let’s take a moment to <strong>plan out what our template will do</strong>. Think of this step as drawing the blueprint before building a house , it makes the whole process smoother and helps avoid mistakes later.</p><p>Here’s what our template will create:</p><ol><li><strong>VPC with public and private subnets in two Availability Zones (AZs)</strong></li></ol><ul><li>A secure network split across two AZs for high availability.</li><li>Public subnets will host the load balancer and NAT Gateway; private subnets will host the web servers and database</li></ul><p><strong>2. Internet Gateway &amp; NAT Gateway</strong></p><ul><li>Public subnets can talk to the internet via the Internet Gateway.</li><li>Private subnets can securely access the internet through the NAT Gateway.</li></ul><p><strong>3. Route Tables</strong></p><ul><li>Public and private route tables to control traffic routing.</li></ul><p><strong>4. Security Groups</strong></p><ul><li>ALB Security Group: Allows HTTP/HTTPS traffic from the internet.</li><li>Web Server SG: Allows traffic only from the ALB.</li><li>Database SG: Allows MySQL traffic only from the web servers.</li></ul><p><strong>5. Application Load Balancer (ALB)</strong></p><ul><li>Distributes incoming traffic across multiple web servers for better reliability.</li></ul><p><strong>6. Target Group &amp; Listener</strong></p><ul><li>Target group registers our web servers and monitors their health.</li><li>Listener forwards HTTP requests from the ALB to the target group.</li></ul><p><strong>7. Launch Template &amp; Auto Scaling Group (ASG) for Web Servers</strong></p><ul><li>Launch Template defines the EC2 configuration (AMI, instance type, security groups, and UserData to install Apache).</li><li>ASG ensures the web servers automatically scale up or down based on demand, with minimum, maximum, and desired capacities.</li></ul><p><strong>8. Database (RDS)</strong></p><ul><li>Multi-AZ MySQL database for high availability.</li><li>Private subnets, secure access via security groups, and automated backups.</li></ul><p><strong>9. Outputs</strong></p><ul><li>Exposes key information such as VPC ID, subnet IDs, ALB DNS, ASG name, and database endpoint.</li><li>Useful for connecting other services or verifying your deployment.</li></ul><p>So, in this step, we’re essentially <strong>mapping out our entire infrastructure</strong> before writing each resource. Once we finish creating all the resources, we can add a <strong>Description</strong> at the top of the template summarizing exactly what we’ve built. This makes it clear for anyone reading your template later - it’s like leaving a “this is what we built” note for the future you or anyone else!</p><p>Here’s a quick summary of the key networking components and configurations for our highly available web application setup:</p><pre>                         <br>VPC: 10.0.0.0/16<br>Public Subnets: 10.0.0.0/24 (AZ1), 10.0.2.0/24 (AZ2)<br>Private Subnets: 10.0.1.0/24 (AZ1), 10.0.3.0/24 (AZ2)<br>Internet Gateway (IGW) → connects public subnets to internet<br>NAT Gateway → allows private subnets to access internet securely<br>Security Groups: ALB SG, Web Server SG, Database SG<br>Route Tables: Public RT, Private RT</pre><h3><strong>Step 5: Define Parameters 🛠️</strong></h3><p>In CloudFormation, <strong>parameters are like input fields</strong>, they let you customize your template without touching the actual code. Imagine you want to add things like instance types, passwords, or resource names. You <em>could</em> hard-code them, but what if you want to use this template in another AWS region or account? Hard-coded values like AMIs might break because they’re different from region to region.</p><p>That’s where parameters come in. They make your template <strong>flexible, consistent, and reusable</strong>. Instead of manually changing values every time, the template can dynamically fetch or accept the right values when you launch it. You simply set the parameters at runtime, and CloudFormation takes care of the rest - smooth, error-free, and ready to go anywhere.</p><p><strong>Let’s break down the parameters in our template:</strong></p><p>First things first, we need to add the main block called Parameters.</p><p>Under this main block, we add the actual parameters according to <strong>YAML indentation rules</strong>.</p><p>Our first parameter is <strong>AppPrefix</strong>. Here’s how we define it in the template:</p><pre>Parameters:<br>  AppPrefix:<br>    Description: Prefix for all resources (VPC, Subnets, SGs, ALB, ASG, RDS)<br>    Type: String<br>    Default: HA-APP-</pre><p>You might be wondering, why so many spaces? Some lines seem more indented than others - what’s going on? 🤔</p><p>It’s all about <strong>indentation</strong>. In YAML:</p><ul><li>Parameters is the <strong>parent</strong> block.</li><li>AppPrefix is a <strong>child</strong> of Parameters.</li><li>Description, Type, and Default are <strong>children of AppPrefix -</strong>basically its sub-items and they are <strong>siblings</strong> to each other</li></ul><pre>👪 Parameters       ← Parent<br>   🧒 AppPrefix     ← Child<br>      👶 Description ← Child of AppPrefix (sibling to Type &amp; Default)<br>      👶 Type        ← Child of AppPrefix (sibling to Description &amp; Default)<br>      👶 Default     ← Child of AppPrefix (sibling to Description &amp; Type)</pre><p>So the rule is simple:</p><ul><li><strong>Children are indented from parents</strong></li><li><strong>Siblings stay at the same indentation level</strong></li></ul><p>Don’t let the term “indentation” scare you, it just means adding spaces. By convention, <strong>2 spaces per level</strong> is recommended. That’s it! 😄</p><h3>AppPrefix 🏷️</h3><p><strong>Our first parameter is </strong><strong>AppPrefix.</strong></p><p><strong>Why this parameter?</strong><br> We use AppPrefix as a common prefix for all the resources in the template. This keeps names consistent, avoids collisions across stacks, and makes the template reusable.</p><p>Template definition:</p><pre>Parameters:<br>  AppPrefix:<br>    Description: Prefix for all resources (VPC, Subnets, SGs, ALB, ASG, RDS)<br>    Type: String<br>    Default: HA-APP-</pre><p><strong>What I defined here:</strong></p><ul><li>AppPrefix parameter can be used as a prefix for all resources</li><li>It’s default value is “HA-APP-”</li><li>It can be changed per stack at launch if needed.</li></ul><p><strong>How to use this parameter</strong></p><p>Say you want to name your VPC HA-APP-VPC. There are two ways:</p><ol><li><strong>Hardcode it:</strong> Just type &quot;HA-APP-VPC&quot; directly in the template.</li><li><strong>Use </strong><strong>AppPrefix:</strong> Reference the parameter dynamically using !Sub:</li></ol><pre>Value: !Sub &quot;${AppPrefix}VPC&quot; </pre><ul><li>Using AppPrefix is cleaner and more flexible. You can change the prefix for different stacks without editing the template itself.</li></ul><p>Here’s a simple visual representation of how our AppPrefix parameter is applied to all the main resources in the template:</p><pre>┌─────────────────────┐<br>│ HA-APP-VPC          │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-PubSub1AZ1   │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-PubSub2AZ2   │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-PriSub1AZ1   │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-PriSub2AZ2   │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-ALB          │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-WebServerSG  │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-DatabaseSG   │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-WebServer    │<br>└─────────────────────┘<br><br>┌─────────────────────┐<br>│ HA-APP-Database     │<br>└─────────────────────┘</pre><p>Think of it like <strong>sticking your personalized label on everything</strong> - easy to spot and organized!</p><h3><strong>DatabasePassword 🔒</strong></h3><p>Our next parameter is <strong>DatabasePassword</strong>, and as the name suggests, it’s the <strong>secret key to your database kingdom</strong>. Instead of hardcoding your password in the template (which would be a big security no-no 😅), we define it as a parameter so CloudFormation can handle it safely.</p><p>Here’s how it looks in the template:</p><pre>DatabasePassword:<br>  Type: String<br>  NoEcho: true<br>  Description: Secret password for your RDS MySQL database<br>  MinLength: 10<br>  MaxLength: 25<br>  AllowedPattern: &quot;[a-zA-Z0-9]*&quot;<br>  ConstraintDescription: Password must be 10-25 characters long and contain only letters and numbers</pre><p><strong>Why it’s useful:</strong></p><ul><li><strong>NoEcho: true</strong> → hides the password in the AWS console so no one can peek at it. 🕵️‍♀️</li><li><strong>MinLength / MaxLength</strong> → ensures your password is strong enough (10–25 characters).</li><li><strong>AllowedPattern</strong> → In here only letters and numbers are allowed.</li></ul><p><strong>How it works:</strong><br> When you launch your stack, CloudFormation will <strong>prompt you to provide a password</strong> (or you can leave it blank to use a default if defined). This password is then automatically applied to your RDS instance.</p><p>💡 Think of it like a <strong>magic key</strong>: CloudFormation keeps it safe, and you never have to manually type it into the database setup.</p><p><strong>Referencing it in the template:</strong></p><pre>MasterUserPassword: !Ref DatabasePassword</pre><p>This tells CloudFormation: “Use whatever secret password the user provided when creating the stack.”</p><h3><strong>WebServerInstanceType 💻</strong></h3><p>Next up, we have <strong>WebServerInstanceType</strong>, which decides the <strong>size and power of your EC2 web servers</strong>. Instead of hardcoding an instance type in the template, we make it a parameter so you can <strong>easily adjust it later</strong> depending on your needs - like upgrading from a small laptop to a workstation if your traffic grows.</p><p>Here’s how it’s defined in the template:</p><pre>WebServerInstanceType:<br>  Description: EC2 instance type for web servers (Free Tier eligible)<br>  Type: String<br>  Default: t2.micro<br>  ConstraintDescription: Must be Free Tier eligible</pre><p><strong>Why it’s useful:</strong></p><ul><li><strong>Flexibility:</strong> You can change the instance type without editing the template. For example, go from t2.micro to t3.medium if your app needs more memory or CPU.</li><li><strong>Free Tier friendly:</strong> The default t2.micro is Free Tier eligible, so beginners can experiment without extra cost.</li><li><strong>Consistency:</strong> Keeps your web servers uniform across the stack by letting you define the type in <strong>one place</strong>.</li></ul><p><strong>How it works:</strong><br> When you launch the stack, CloudFormation will use the value you provide (or the default) for the EC2 instances in your <strong>Auto Scaling Group or Launch Template</strong>.</p><p><strong>Referencing it in the template:</strong></p><pre>InstanceType: !Ref WebServerInstanceType</pre><p>This tells CloudFormation to <strong>dynamically assign the EC2 instance type</strong> you chose when creating the stack.</p><h3><strong>WebServerAMI 🖥️</strong></h3><p>Finally, we have <strong>WebServerAMI</strong>, which decides <strong>which Amazon Machine Image (AMI) your web servers will use</strong>. Think of it as <strong>picking the operating system and baseline software</strong> your EC2 instances will start with.</p><p>Here’s how it’s defined in the template:</p><pre>WebServerAMI:<br>  Description: Select an Amazon Linux 2023 AMI for your region<br>  Type: String<br>  Default: Amazon Linux 2023 AMI 2023.8.20250915.0 x86_64 HVM kernel-6.1  # replace with your region’s AMI<br>  AllowedValues:<br>    - Amazon Linux 2023 AMI 2023.8.20250915.0 x86_64 HVM kernel-6.1 # AZ1<br>    - Amazon Linux 2023 AMI 2023.8.20250915.0 x86_64 HVM kernel-6.12  # another option<br>  ConstraintDescription: Must select a valid Amazon Linux 2023 AMI</pre><p><strong>Why it’s useful:</strong></p><ul><li><strong>Region flexibility:</strong> AMI IDs can differ from region to region, so instead of hardcoding, you select the right one for your region.</li><li><strong>Consistency:</strong> Ensures all your EC2 web servers run the same OS version, avoiding unexpected errors.</li><li><strong>Control:</strong> Lets you upgrade to a newer AMI in the future without changing the whole template.</li></ul><p><strong>How it works:</strong><br> When launching the stack, CloudFormation will use the AMI you specify to <strong>spin up your EC2 instances</strong>. This ensures your web servers are ready with the OS and baseline software right from the start.</p><p>Referencing it in the template:</p><pre>ImageId: !Ref WebServerAMI</pre><p>This tells CloudFormation: “Use the AMI you selected when launching the EC2 instances.”</p><h3>Step 6: Define Resources: The Heart of Your Template ❤️</h3><p>Now that we’ve defined all our parameters, it’s time to move to the <strong>Resources</strong> section - this is the <strong>mandatory main block in any CloudFormation template</strong>. Think of it as the <strong>“blueprint” for all the AWS components</strong> you want to create.</p><h3>Common Things for the Resources Section 🧩</h3><p>When working with the <strong>Resources</strong> block in CloudFormation, there are a few patterns you’ll notice repeating across multiple resources. Let’s highlight them once, so you don’t get confused later:</p><ol><li><strong>Comments (</strong><strong>#)</strong> 📝</li></ol><ul><li>Comments are added with the # symbol.</li><li>They don’t affect the template - they’re purely for humans to read.</li><li>Use them generously to explain <em>why</em> something is being created or <em>what role</em> it plays.</li><li>This is especially useful in long templates where future-you or teammates might otherwise get lost.</li><li>Example:</li></ul><pre># Step 1: VPC &lt;-- This is a comment<br>HAVPC:<br>  Type: AWS::EC2::VPC</pre><p><strong>2. Resource Type (</strong><strong>Type:)</strong></p><ul><li>Every resource in CloudFormation must declare a <strong>resource type</strong>, written as:</li></ul><pre>Type: AWS::ServiceName::Resource</pre><ul><li>Example:</li></ul><pre>Type: AWS::EC2::VPC</pre><ul><li>This tells CloudFormation <em>exactly</em> which AWS service and resource you want to create.</li><li>These resource types are standardized and documented in the <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html"><strong>AWS CloudFormation Resource Reference</strong>.</a></li><li>Think of Type as the blueprint’s <strong>title, </strong>it says <em>what kind of building block you’re about to create</em> (VPC, EC2, S3 Bucket, IAM Role, etc).</li></ul><p><strong>3. Logical IDs</strong> 🔖</p><ul><li>You can provide a <strong>Logical ID for the resources you declare </strong>(e.g., HAVPC, HAIGW).</li><li>This is a unique identifier <em>within the template</em>.</li></ul><p>Example:</p><pre>HAVPC: &lt;-- This is a logical ID<br>  Type: AWS::EC2::VPC</pre><p>Here HAVPC is the logical ID.</p><p><strong>4. Referencing with </strong><strong>!Ref</strong></p><ul><li>Logical IDs act like <strong>nicknames</strong> for resources. Instead of hardcoding AWS-generated IDs, logical IDs can be referenced anywhere in the template.</li><li>you just !Ref the logical ID.</li><li>Later, if a subnet needs the VPC which has logical ID -HAVPC, you can simply write:</li></ul><pre>VpcId: !Ref HAVPC</pre><p>This tells CloudFormation: “Use the VPC I defined above” - no need to hardcode any IDs.</p><p>👉 This makes the template reusable.</p><p><strong>5.Properties: Customizing the Resource</strong></p><ul><li>Right under Type, we usually see a Properties block.</li><li>This is where you set configuration details like CIDR blocks for VPCs, AMI IDs for EC2, or bucket policies for S3.</li><li>Think of this as filling out the <strong>specification sheet</strong> for that resource.</li></ul><p><strong>6. Tags for Naming &amp; Organization</strong></p><ul><li>Most AWS resources support tagging.</li><li>A common pattern is to give each resource a Name tag for easier identification in the AWS console.</li><li>In our template, the Name tag value uses the AppPrefix parameter to keep naming consistent across environments.</li></ul><p>Example:</p><pre>Tags:<br>  - Key: Name<br>    Value: !Sub &quot;${AppPrefix}ResourceName&quot;</pre><p>👉 This ensures resources are automatically labeled and grouped by your application prefix.</p><p><strong>7. Dynamic Naming with </strong><strong>!Sub</strong></p><ul><li>The !Sub intrinsic function allows us to substitute variables directly inside strings.</li><li>We use it to combine the AppPrefix parameter with a resource-specific suffix.</li></ul><p>Example:</p><pre>Value: !Sub &quot;${AppPrefix}VPC&quot;</pre><p>👉 If AppPrefix = HA-APP-, the resource name becomes HA-APP-VPC.</p><p><strong>Step 1: Creating the VPC</strong></p><p>First, we need a <strong>VPC (Virtual Private Cloud)</strong> - the core network where all our resources will live.</p><p>Template snippet:</p><pre># Step 1: VPC<br>HAVPC:<br>  Type: AWS::EC2::VPC<br>  Properties:<br>    CidrBlock: 10.0.0.0/16<br>    EnableDnsHostnames: true<br>    EnableDnsSupport: true<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}VPC&quot;</pre><p>🔎 <strong>What’s happening here:</strong></p><ul><li>Logical ID → HAVPC</li><li>Resource Type → AWS::EC2::VPC</li><li><strong>Tags</strong> → HA-APP-VPC</li><li><strong>CidrBlock: </strong><strong>10.0.0.0/16</strong> → Defines the private IP range for this VPC, giving us <strong>65,536 usable addresses</strong>. This is the pool from which all subnets and resources inside the VPC will pull IPs.</li><li><strong>EnableDnsHostnames: true</strong> → Makes sure instances get human-friendly hostnames instead of raw IPs.</li><li><strong>EnableDnsSupport: true</strong> → Lets resources inside the VPC resolve domain names (like amazon.com) without relying on external DNS.</li></ul><p><strong>In short:</strong> We now have a brand-new VPC with plenty of IPs, DNS enabled, and a clean prefix-based name tag. The perfect foundation for everything else we’ll build.</p><p><strong>Step 2: Internet Gateway 🌐</strong></p><p>Our VPC is ready, but right now it’s cut off from the outside world. To open it up, we need an <strong>Internet Gateway (IGW)</strong> - think of it as the main door that connects your private VPC to the public internet.</p><p>Template snippet:</p><pre># Step 2: Internet Gateway<br>HAIGW:<br>  Type: AWS::EC2::InternetGateway<br>  Properties:<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}IGW&quot;</pre><p>🔎 <strong>What’s happening here:</strong></p><ul><li>Logical ID → HAIGW</li><li>Resource Type → AWS::EC2::InternetGateway</li><li>Tag → HA-APP-IGW</li></ul><p><strong>In short:</strong> We’ve created an Internet Gateway - the entry/exit point for internet traffic. Right now, it’s just built, but not yet connected to our VPC (that comes in the next step).</p><p><strong>Step 2.1 Attaching the Internet Gateway to the VPC </strong>🔗</p><p>We’ve built our Internet Gateway, but it’s not doing much on its own yet. Think of it like buying a Wi-Fi router - you still need to plug it into your home network. This step “plugs in” the IGW to our VPC, letting it actually send and receive traffic from the internet.</p><p><strong>Template snippet:</strong></p><pre># Step 2.1: Attach IGW to VPC<br>HAIGWAttachment:<br>  Type: AWS::EC2::VPCGatewayAttachment<br>  Properties:<br>    VpcId: !Ref HAVPC<br>    InternetGatewayId: !Ref HAIGW</pre><p>🔎 What’s happening here:</p><ul><li><strong>Logical ID:</strong> HAIGWAttachment</li><li><strong>Resource Type:</strong> AWS::EC2::VPCGatewayAttachment</li><li><strong>VpcId:</strong> !Ref HAVPC → Tells CloudFormation which VPC to attach the IGW to.</li><li><strong>InternetGatewayId:</strong> !Ref HAIGW → Specifies which Internet Gateway we’re connecting.</li></ul><p><strong>In short: </strong>We’re linking the IGW to the VPC. Now our VPC has a proper “door” to the internet! And because we’re using logical IDs, we avoid hardcoding any values, keeping the template reusable and neat.</p><p><strong>Step 3 Public Subnets (for ALB &amp; NAT) </strong>🏙️</p><p>Our VPC now has a gateway to the internet, but we still need “spaces” inside it where internet-facing resources like the ALB or NAT Gateway can live. That’s where public subnets come in. We’ll create <strong>two public subnets across two Availability Zones (AZs)</strong> for high availability.</p><p><strong>Template snippet (Public Subnet 1):</strong></p><pre># Step 3: Public Subnets (for ALB &amp; NAT)<br>HAPublicSubnet1:<br>  Type: AWS::EC2::Subnet<br>  Properties:<br>    VpcId: !Ref HAVPC<br>    AvailabilityZone: !Select [0, !GetAZs &quot;&quot;]<br>    CidrBlock: 10.0.0.0/24<br>    MapPublicIpOnLaunch: true<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}PubSub1AZ1&quot;</pre><p><strong>🔎 What’s happening here:</strong></p><ul><li><strong>Logical ID:</strong> HAPublicSubnet1</li><li><strong>Resource Type:</strong> AWS::EC2::Subnet</li><li><strong>VpcId:</strong> !Ref HAVPC → Connects the subnet to our VPC.</li><li><strong>AvailabilityZone: !Select [0, !GetAZs “”]</strong> → Picks the <strong>first availability zone</strong> in the region.</li></ul><p>1. !GetAZs &quot;&quot; → Returns a <strong>list of all AZs</strong> in the region.</p><p>2. !Select [0, ...] → Selects the <strong>first AZ</strong> from that list.</p><ul><li><strong>CidrBlock: 10.0.0.0/24</strong> → Defines the <strong>IP range</strong> for this subnet, enough space for resources inside it.</li><li><strong>MapPublicIpOnLaunch: true</strong> → Any EC2 instance launched here automatically gets a <strong>public IP</strong>, so it can communicate with the internet.</li><li><strong>Tag → </strong>HA-APP-PubSub1AZ1</li></ul><p><strong>Template snippet (Public Subnet 2):</strong></p><pre>HAPublicSubnet2:<br>    Type: AWS::EC2::Subnet<br>    Properties:<br>      VpcId: !Ref HAVPC<br>      AvailabilityZone: !Select [1, !GetAZs &quot;&quot;]<br>      CidrBlock: 10.0.2.0/24<br>      MapPublicIpOnLaunch: true<br>      Tags:<br>        - Key: Name<br>          Value: !Sub &quot;${AppPrefix}PubSub2AZ2&quot;</pre><p><strong>Differences for Subnet 2:</strong></p><ul><li>Picks the second AZ (!Select [1, !GetAZs &quot;&quot;]).</li><li>Uses a different IP range (10.0.2.0/24).</li><li>Tag → HA-APP-PubSub1AZ2</li></ul><p><strong>In short: </strong>We now have two public subnets, each in a different AZ, ready to host internet-facing resources. Using logical IDs (HAPublicSubnet1 / HAPublicSubnet2) allows us to reference them easily later for attaching route tables, NAT Gateways, or the ALB.</p><p><strong>Step 4 - Private Subnets</strong></p><p>With our public subnets ready, it’s time to create the <strong>private subnets</strong>. These are the secure zones in our VPC where resources like EC2 web servers will live <strong>without direct internet exposure</strong>. Think of them as private rooms in a house - they can reach the outside world, but only through controlled doors (like a NAT Gateway).</p><p><strong>Template snippet (Private Subnet 1):</strong></p><pre># Step 4: Private Subnets<br>HAPrivateSubnet1:<br>  Type: AWS::EC2::Subnet<br>  Properties:<br>    VpcId: !Ref HAVPC<br>    AvailabilityZone: !Select [0, !GetAZs &quot;&quot;]<br>    CidrBlock: 10.0.1.0/24<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}PriSub1AZ1&quot;</pre><p><strong>What’s happening in Private Subnet 1:</strong></p><ul><li><strong>Logical ID:</strong> HAPrivateSubnet1</li><li><strong>Resource Type:</strong> AWS::EC2::Subnet</li><li><strong>VpcId:</strong> !Ref HAVPC → Places the subnet in our VPC</li><li><strong>AvailabilityZone:</strong> !Select [0, !GetAZs “”] → Picks the <strong>first AZ</strong> in the region.</li><li><strong>CidrBlock:</strong> 10.0.1.0/24 → Assigns the range of private IPs for resources in this subnet.</li><li><strong>Tag</strong> → HA-APP-PriSub1AZ1</li></ul><p><strong>Template snippet (Private Subnet 2):</strong></p><pre>HAPrivateSubnet2:<br>  Type: AWS::EC2::Subnet<br>  Properties:<br>    VpcId: !Ref HAVPC<br>    AvailabilityZone: !Select [1, !GetAZs &quot;&quot;]<br>    CidrBlock: 10.0.3.0/24<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}PriSub2AZ2&quot;</pre><p><strong>Differences for Subnet 2:</strong></p><ul><li><strong>AvailabilityZone:</strong> !Select [1, !GetAZs “”] → Uses the <strong>second AZ</strong> for high availability.</li><li><strong>CidrBlock:</strong> 10.0.3.0/24 → Different internal IP range to avoid conflicts.</li><li><strong>Tag</strong> → HA-APP-PriSub1AZ2</li></ul><p><strong>In short: </strong>We’ve created two private subnets across two Availability Zones. These are secure zones where our web servers will live without direct internet access. They can still reach the outside world through a NAT Gateway later. Using two AZs ensures high availability.</p><p><strong>Step 5: Public Route Table</strong></p><p>Now that our public subnets exist, we need a <strong>map</strong> to tell them how to send traffic - this is where a <strong>route table</strong> comes in. For public subnets, it ensures that resources like the ALB or NAT Gateway can reach the internet.</p><p><strong>Template snippet:</strong></p><pre># Step 5: Public Route Table<br>HAPublicRouteTable:<br>  Type: AWS::EC2::RouteTable<br>  Properties:<br>    VpcId: !Ref HAVPC<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}PubRT&quot;</pre><p><strong>🔎 What’s happening here:</strong></p><ul><li><strong>Logical ID:</strong> HAPublicRouteTable</li><li><strong>Resource Type:</strong> AWS::EC2::RouteTable</li><li><strong>VpcId:</strong> !Ref HAVPC → Connects this route table to our VPC</li><li><strong>Tag</strong> → HA-APP-PubRT</li></ul><p><strong>In short: </strong>We’ve created a route table that will act as a traffic map for public subnets. Instances here now have a clear path to the internet once we add the routes. It’s a small but essential piece for keeping our network organized and functional.</p><p><strong>Step 5.1 Default Route to Internet Gateway</strong></p><p>With our public route table ready, we need to tell it where to send all internet-bound traffic. That’s exactly what this route does - think of it as giving the subnet a “go-to” path for anything outside the VPC.</p><p><strong>Template snippet:</strong></p><pre># Step 5.1: Default route to IGW<br>HAPublicRoute:<br>  Type: AWS::EC2::Route<br>  DependsOn: HAIGWAttachment<br>  Properties:<br>    RouteTableId: !Ref HAPublicRouteTable<br>    DestinationCidrBlock: 0.0.0.0/0<br>    GatewayId: !Ref HAIGW</pre><p>🔎 What’s happening here:</p><ul><li><strong>Logical ID:</strong> HAPublicRoute</li><li><strong>Resource Type:</strong> AWS::EC2::Route</li><li><strong>DependsOn:</strong> HAIGWAttachment → Ensures the Internet Gateway is attached before adding this route.</li><li><strong>RouteTableId:</strong> !Ref HAPublicRouteTable → Links the route to our public route table.</li><li><strong>DestinationCidrBlock:</strong> 0.0.0.0/0 → “Send all unknown traffic to the internet.”</li><li><strong>GatewayId:</strong> !Ref HAIGW → Uses the Internet Gateway as the exit point.</li></ul><p><strong>In short:</strong> This step gives public subnets a clear exit to the internet. Without this, resources like ALB or NAT Gateway wouldn’t be able to communicate externally.</p><p><strong>Step 5.2 Connect Public Subnet to the Pulic Route Table</strong></p><p>Now that we have a public route table with a default route to the Internet Gateway, we need to tell our public subnets to use this route table. This step essentially says: “Hey subnet, here’s your path to the internet!”</p><p><strong>Template snippet (Subnet 1 association):</strong></p><pre># Step 5.2: Associate public subnets with public route table<br>HAPublicSubnet1RouteAssoc:<br>  Type: AWS::EC2::SubnetRouteTableAssociation<br>  Properties:<br>    SubnetId: !Ref HAPublicSubnet1<br>    RouteTableId: !Ref HAPublicRouteTable</pre><p><strong>What’s happening in Subnet 1 association:</strong></p><ul><li>Logical ID → HAPublicSubnet1RouteAssoc</li><li>Resource Type → AWS::EC2::SubnetRouteTableAssociation</li><li>SubnetId → !Ref HAPublicSubnet1 → Connects the first public subnet to the route table.</li><li>RouteTableId → !Ref HAPublicRouteTable → Attaches it to our public route table.</li></ul><p><strong>Template snippet (Subnet 2 association):</strong></p><pre>HAPublicSubnet2RouteAssoc:<br>  Type: AWS::EC2::SubnetRouteTableAssociation<br>  Properties:<br>    SubnetId: !Ref HAPublicSubnet2<br>    RouteTableId: !Ref HAPublicRouteTable</pre><p><strong>Differences for Subnet 2 association:</strong></p><ul><li>SubnetId → !Ref HAPublicSubnet2 → Points to the second public subnet in AZ2.</li><li>Everything else remains the same as Subnet 1.</li></ul><p><strong>In short:</strong> Each public subnet is now linked to the public route table, giving instances in both subnets a defined path to the internet.</p><p><strong>Step 6: NAT Gateway (for private subnet internet access)</strong></p><p>Our public subnets can already reach the internet, but private subnets still need a secure way to access it. That’s where the NAT Gateway comes in - a secret tunnel for your private EC2 instances. They can go out to the internet for updates or external services, but no one can reach them directly.</p><p><strong>Template snippet (Elastic IP for NAT):</strong></p><pre># Step 6: NAT Gateway (for private subnet internet access)<br>HANATEIP:<br>  Type: AWS::EC2::EIP<br>  Properties:<br>    Domain: vpc</pre><p><strong>What’s happening with Elastic IP for NAT</strong>:</p><ul><li>Logical ID → HANATEIP</li><li>Resource Type → AWS::EC2::EIP</li><li>Domain → vpc (ensures this Elastic IP is allocated for use inside our VPC)</li><li>Purpose → Elastic IP is a static public IPv4 address. Unlike a regular public IP that can change, EIPs remain the same until released. Perfect for NAT Gateways, where a consistent address is needed.</li></ul><p><strong>Template snippet (NAT Gateway):</strong></p><pre>HANATGateway:<br>  Type: AWS::EC2::NatGateway<br>  Properties:<br>    AllocationId: !GetAtt HANATEIP.AllocationId<br>    SubnetId: !Ref HAPublicSubnet1<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}NATGateway&quot;</pre><p><strong>What’s happening with HANATGateway:</strong></p><ul><li>Logical ID → HANATGateway</li><li>Resource Type → AWS::EC2::NatGateway</li><li>AllocationId → !GetAtt HANATEIP.AllocationId (links the Elastic IP to this NAT Gateway)</li></ul><p>Why !GetAtt instead of !Ref?</p><ul><li>When you attach an <strong>Elastic IP (EIP)</strong> to a <strong>NAT Gateway</strong>, AWS needs the <strong>Allocation ID</strong> of that EIP, not just the public IP address.</li><li><strong>!Ref HANATEIP</strong> → Gives the <strong>public IP address</strong> of the EIP (like 3.25.145.10).</li><li><strong>!GetAtt HANATEIP.AllocationId</strong> → Gives the <strong>Allocation ID</strong>, which is a unique identifier for that EIP inside AWS. The NAT Gateway needs this Allocation ID to know exactly which EIP to use.</li><li>SubnetId → !Ref HAPublicSubnet1 (NAT must live in a public subnet to reach the internet)</li><li>Tag → HA-APP-NATGateway</li></ul><p><strong>In short:</strong> The NAT Gateway lets private subnet instances securely access the internet while keeping them hidden from the public. It’s the VIP pass for your private servers.</p><p><strong>Step 7: Private Route Table (with NAT Gateway route)</strong></p><p>Our private subnets are secure, but they need a controlled way to reach the internet. That’s where a private route table comes in - it directs traffic from private subnets through the NAT Gateway, giving them safe internet access without exposing them publicly.</p><p><strong>Step 7a Private Route Table</strong></p><p>Private subnets need a dedicated map to direct traffic safely. That’s what a <strong>route table</strong> does - it’s like giving your subnet a GPS so it knows where to send its traffic.</p><p><strong>Template snippet:</strong></p><pre># Step 7: Private Route Table (with NAT Gateway route)<br>HAPrivateRouteTable:<br>  Type: AWS::EC2::RouteTable<br>  Properties:<br>    VpcId: !Ref HAVPC<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}PriRT&quot;</pre><p><strong>What’s happening here:</strong></p><ul><li>Logical ID: HAPrivateRouteTable</li><li>Resource Type: AWS::EC2::RouteTable</li><li>VpcId: !Ref HAVPC → Links this route table to the VPC we created.</li><li>Tag → HA-APP-PriRT</li></ul><p><strong>Step 7b: Private Route (to NAT Gateway)</strong></p><p>The route table alone doesn’t do anything without rules. That’s where the <strong>route</strong> comes in - it’s the instruction that says, “All traffic to the internet goes through the NAT Gateway.”</p><p><strong>Template snippet:</strong></p><pre>HAPrivateRoute:<br>  Type: AWS::EC2::Route<br>  DependsOn: HANATGateway<br>  Properties:<br>    RouteTableId: !Ref HAPrivateRouteTable<br>    DestinationCidrBlock: 0.0.0.0/0<br>    NatGatewayId: !Ref HANATGateway</pre><p><strong>What’s happening here:</strong></p><ul><li><strong>Logical ID:</strong> HAPrivateRoute</li><li><strong>Resource Type:</strong> AWS::EC2::Route</li><li><strong>DependsOn:</strong> HANATGateway → Ensures NAT Gateway exists before creating this route.</li><li><strong>RouteTableId:</strong> !Ref HAPrivateRouteTable → Attaches the route to the private route table.</li><li><strong>DestinationCidrBlock:</strong> 0.0.0.0/0 → “Send all outbound traffic to the internet.”</li><li><strong>NatGatewayId:</strong> !Ref HANATGateway → Routes traffic through the NAT Gateway.</li></ul><p><strong>Step 8: Associate private subnets with private route table</strong></p><p>Private subnets now have a route table pointing to the NAT Gateway, but we need to <strong>connect each private subnet to that table</strong>. This step tells each subnet, “Use this route table for outbound traffic.”</p><p><strong>Template snippet (Private Subnet 1 association):</strong></p><pre>HAPrivateSubnet1RouteAssoc:<br>  Type: AWS::EC2::SubnetRouteTableAssociation<br>  Properties:<br>    SubnetId: !Ref HAPrivateSubnet1<br>    RouteTableId: !Ref HAPrivateRouteTable</pre><p><strong>What’s happening here:</strong></p><ul><li><strong>Logical ID:</strong> HAPrivateSubnet1RouteAssoc</li><li><strong>Resource Type:</strong> AWS::EC2::SubnetRouteTableAssociation</li><li><strong>SubnetId:</strong> !Ref HAPrivateSubnet1 → Points to the first private subnet (AZ1).</li><li><strong>RouteTableId:</strong> !Ref HAPrivateRouteTable → Connects it to the private route table from Step 7</li></ul><p><strong>Template snippet (Private Subnet 2 association):</strong></p><pre>HAPrivateSubnet2RouteAssoc:<br>  Type: AWS::EC2::SubnetRouteTableAssociation<br>  Properties:<br>    SubnetId: !Ref HAPrivateSubnet2<br>    RouteTableId: !Ref HAPrivateRouteTable</pre><p><strong>Differences for Subnet 2:</strong></p><ul><li><strong>SubnetId:</strong> !Ref HAPrivateSubnet2 → Points to the second private subnet in AZ2.</li><li>Everything else remains the same, reusing the private route table we just created.</li></ul><p><strong>In short: </strong>Both private subnets now have a secure path to the internet through the NAT Gateway. Instances inside them can reach external resources safely - no public IPs needed. It’s like giving them a VIP tunnel for outbound traffic while keeping them hidden from the public.</p><p><strong>Step 9: Security Groups Configuration</strong></p><p>Security Groups act as virtual firewalls controlling inbound and outbound traffic for your resources. Let’s configure them step by step.</p><p><strong>9.1 ALB Security Group</strong></p><p>Template snippet:</p><pre># ALB Security Group<br>HAALBSG:<br>  Type: AWS::EC2::SecurityGroup<br>  Properties:<br>    GroupName: !Sub &quot;${AppPrefix}ALBSG&quot;<br>    GroupDescription: Security group for the public-facing load balancer<br>    VpcId: !Ref HAVPC<br>    SecurityGroupIngress:<br>      - IpProtocol: tcp<br>        FromPort: 80<br>        ToPort: 80<br>        CidrIp: 0.0.0.0/0<br>        Description: Allow HTTP traffic from the internet<br>      - IpProtocol: tcp<br>        FromPort: 443<br>        ToPort: 443<br>        CidrIp: 0.0.0.0/0<br>        Description: Allow HTTPS traffic from the internet</pre><p><strong>What’s happening:</strong></p><ul><li><strong>Logical ID:</strong> HAALBSG</li><li><strong>Resource Type:</strong> AWS::EC2::SecurityGroup</li><li><strong>Security Group Name: </strong>HA-APP-ALBSG</li><li><strong>VpcId:</strong> !Ref HAVPC → Creates the SG inside our VPC.</li></ul><p>In AWS Security Groups, <strong>ports</strong> define which network ports are allowed for inbound (or outbound) traffic</p><p><strong>* FromPort</strong> → The starting port of the allowed range.</p><p><strong>* ToPort</strong> → The ending port of the allowed range.</p><p>So when you write: FromPort: 80, ToPort: 80 It means Only <strong>port 80</strong> (HTTP) is allowed. Incoming traffic is permitted <strong>exactly on port 80</strong>.</p><ul><li><strong>SecurityGroupIngress:</strong> Allows inbound web traffic only on <strong>ports 80 and 443</strong> from anywhere (0.0.0.0/0).</li></ul><p><strong>9.2 Web Server Security Group</strong></p><p>Template snippet:</p><pre># Web Server Security Group<br>HAWebServerSG:<br>  Type: AWS::EC2::SecurityGroup<br>  Properties:<br>    GroupName: !Sub &quot;${AppPrefix}WebServerSG&quot;<br>    GroupDescription: Security group for EC2 web servers<br>    VpcId: !Ref HAVPC<br>    SecurityGroupIngress:<br>      - IpProtocol: tcp<br>        FromPort: 80<br>        ToPort: 80<br>        SourceSecurityGroupId: !Ref HAALBSG<br>        Description: Only allow HTTP requests from the load balancer</pre><p><strong>What’s happening in Web Server SG:</strong></p><ul><li><strong>Logical ID:</strong> HAWebServerSG</li><li><strong>Resource Type:</strong> AWS::EC2::SecurityGroup</li><li><strong>Security Group Name:</strong> HA-APP-WebServerSG</li><li><strong>VpcId:</strong> !Ref HAVPC → Same VPC as ALB</li><li><strong>SecurityGroupIngress:</strong> Only <strong>port 80</strong> is allowed</li><li><strong>SourceSecurityGroupId:</strong> !Ref HAALBSG → Only the ALB can send traffic.</li></ul><p><strong>In short: </strong>Web servers remain private. They only accept traffic from the ALB while still being able to reach the internet via the NAT Gateway for updates.</p><p><strong>9.3. Database Security Group</strong></p><p>Template snippet:</p><pre>HADatabaseSG:<br>  Type: AWS::EC2::SecurityGroup<br>  Properties:<br>    GroupName: !Sub &quot;${AppPrefix}DatabaseSG&quot;<br>    GroupDescription: Security group for MySQL database<br>    VpcId: !Ref HAVPC<br>    SecurityGroupIngress:<br>      - IpProtocol: tcp<br>        FromPort: 3306<br>        ToPort: 3306<br>        SourceSecurityGroupId: !Ref HAWebServerSG<br>        Description: Allow MySQL connections only from web servers</pre><p><strong>What’s happening for Database SG:</strong></p><ul><li><strong>Logical ID:</strong> HADatabaseSG</li><li><strong>Resource Type:</strong> AWS::EC2::SecurityGroup</li><li><strong>Security Group Name:</strong> HA-APP-DatabaseSG</li><li><strong>VpcId:</strong> !Ref HAVPC → Same VPC as web servers.</li><li>SecurityGroupIngress: Only <strong>port 3306 (MySQL)</strong> is open.</li><li><strong>SourceSecurityGroupId:</strong> !Ref HAWebServerSG → Only web servers can communicate.</li></ul><p><strong>In short: </strong>The database is fully private. Only authorized web servers can access it, keeping your RDS instance safe from the internet or any unknown sources.</p><p><strong>Step 10: Application Load Balancer Setup</strong></p><p>Our VPC, subnets, and security groups are ready. Now it’s time to set up the <strong>Application Load Balancer (ALB)</strong>. Think of the ALB as a <strong>smart traffic controller</strong>: it sits in front of your web servers and distributes incoming requests evenly, keeping your app fast and highly available.</p><p><strong>10.1: Application Load Balancer (ALB)</strong></p><p>Template snippet:</p><pre># Step 10: Application Load Balancer<br>HAALB:<br>  Type: AWS::ElasticLoadBalancingV2::LoadBalancer<br>  Properties:<br>    Name: !Sub &quot;${AppPrefix}ALB&quot;<br>    Subnets:<br>      - !Ref HAPublicSubnet1<br>      - !Ref HAPublicSubnet2<br>    SecurityGroups:<br>      - !Ref HAALBSG<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}ALB&quot;</pre><p><strong>What’s happening:</strong></p><ul><li><strong>Logical ID:</strong> HAALB</li><li><strong>Resource Type: </strong>AWS::ElasticLoadBalancingV2::LoadBalancer</li><li><strong>ALB Name:</strong> HA-APP-ALB</li><li><strong>Subnets:</strong> Deployed in both HAPublicSubnet1 and HAPublicSubnet2 → ensures <strong>high availability</strong> across AZs.</li><li><strong>Security Groups:</strong> Uses HAALBSG → allows only HTTP (80) and HTTPS (443) from the internet.</li><li><strong>Internet-facing:</strong> Being in public subnets means it can receive requests directly from users.</li><li><strong>Tag → </strong>HA-APP-ALB</li></ul><p><strong>10.2 Target Group for Web Servers</strong></p><ul><li>Defines which EC2 instances the ALB sends traffic to and how their health is monitored.</li></ul><p>Template snippet:</p><pre>HAWebServerTG:<br>  Type: AWS::ElasticLoadBalancingV2::TargetGroup<br>  Properties:<br>    Name: !Sub &quot;${AppPrefix}WebServersTG&quot;<br>    Port: 80<br>    Protocol: HTTP<br>    VpcId: !Ref HAVPC<br>    HealthCheckPath: /health<br>    HealthCheckProtocol: HTTP<br>    HealthCheckIntervalSeconds: 30<br>    HealthyThresholdCount: 2<br>    UnhealthyThresholdCount: 3<br>    Tags:<br>      - Key: Name<br>        Value: !Sub &quot;${AppPrefix}WebServersTG&quot;</pre><p>What’s happening:</p><ul><li><strong>Logical ID:</strong> HAWebServerTG</li><li><strong>Resource Type:</strong> AWS::ElasticLoadBalancingV2::TargetGroup</li><li><strong>Target group name: </strong>HA-APP-WebServersTG</li><li><strong>Port &amp; Protocol:</strong> Traffic sent to web servers on HTTP port 80.</li><li><strong>VpcId:</strong> Associates the target group with the same VPC (HAVPC) where your web servers reside.</li></ul><p><strong>Health Checks:</strong></p><ul><li>Path /health → ALB checks this endpoint on each server.</li><li>HealthyThresholdCount: 2 → Two consecutive successful checks make a server “healthy”</li><li>UnhealthyThresholdCount: 3 → Three consecutive failures mark it “unhealthy.”</li><li>IntervalSeconds: 30 → Checks the server status every 30 seconds.</li></ul><p><strong>In short:</strong> Target Group is the <strong>VIP list of web servers</strong>; ALB uses it to know which servers are healthy and ready to receive traffic.</p><p><strong>10.3 ALB Listener</strong></p><ul><li>Defines how the Application Load Balancer (ALB) receives incoming traffic and what it does with it.</li></ul><p>Template snippet:</p><pre>HAALBListener:<br>  Type: AWS::ElasticLoadBalancingV2::Listener<br>  Properties:<br>    LoadBalancerArn: !Ref HAALB<br>    Port: 80<br>    Protocol: HTTP<br>    DefaultActions:<br>      - Type: forward<br>        TargetGroupArn: !Ref HAWebServerTG</pre><p>What’s happening:</p><ul><li><strong>HAALBListener</strong> → Logical ID for the listener.</li><li><strong>Resource Type: </strong>AWS::ElasticLoadBalancingV2::Listener</li><li><strong>LoadBalancerArn: !Ref HAALB → </strong>Connects the listener to our ALB.</li><li><strong>Port &amp; Protocol:</strong> Listens for HTTP traffic on port 80.</li></ul><p><strong>i</strong>. <strong>Type: forward</strong> → Sends traffic to a target group.</p><p><strong>ii. TargetGroupArn: !Ref HAWebServerTG </strong>→ Forwards requests to the target group containing your web servers.</p><p><strong>Step 11 : Launch Template for Web Servers</strong></p><p>Automates EC2 web server configuration, ensuring consistency across all instances. Parameters like AppPrefix, WebServerAMI, and WebServerInstanceType make the template flexible and reusable.</p><p><strong>Template Snippet</strong></p><pre># Step 11: Launch Template for Web Servers<br>  HAWebServerLaunchTemplate:<br>    Type: AWS::EC2::LaunchTemplate<br>    Properties:<br>      LaunchTemplateName: !Sub &quot;${AppPrefix}LaunchTemplate&quot;<br>      LaunchTemplateData:<br>        ImageId: !Ref WebServerAMI # Latest Amazon Linux 2023 Free Tier AMI<br>        InstanceType: !Ref WebServerInstanceType<br>        SecurityGroupIds:<br>          - !Ref HAWebServerSG<br>        UserData:<br>          Fn::Base64: !Sub |<br>            #!/bin/bash<br>            yum update -y<br>            yum install -y httpd<br>            systemctl start httpd<br>            systemctl enable httpd<br>            echo &quot;&lt;h1&gt;Welcome to ${AppPrefix}Web Server&lt;/h1&gt;&quot; &gt; /var/www/html/index.html<br>            echo &quot;Healthy&quot; &gt; /var/www/html/health</pre><p>What’s happening:</p><ul><li><strong>Logical ID:</strong> HAWebServerLaunchTemplate</li><li><strong>Resource Type: </strong>AWS::EC2::LaunchTemplate</li><li><strong>LaunchTemplateName: </strong>HA-APP-LaunchTemplate</li></ul><p>LaunchTemplateData:</p><ul><li><strong>ImageId:</strong> !Ref WebServerAMI → Uses the latest Amazon Linux 2023 Free Tier AMI.</li><li><strong>InstanceType:</strong> !Ref WebServerInstanceType → Sets the instance type dynamically (e.g., t2.micro).</li><li><strong>SecurityGroupIds:</strong> !Ref HAWebServerSG → Associates the web server security group for proper inbound/outbound rules.</li><li><strong>UserData:</strong> Base64-encoded Bash script executed at instance launch:</li><li>yum update -y → Updates all packages to the latest version.</li><li>yum install -y httpd → Installs Apache HTTP web server.</li><li>systemctl start httpd &amp; systemctl enable httpd → Starts the server and ensures it runs at boot.</li><li>echo &quot;&lt;h1&gt;Welcome to ${AppPrefix}Web Server&lt;/h1&gt;&quot; &gt; /var/www/html/index.html → Creates a simple homepage displaying the app prefix.</li><li>echo &quot;Healthy&quot; &gt; /var/www/html/health → Prepares the ALB health check endpoint (/health)</li></ul><p><strong>In short: </strong>This launch template ensures every EC2 web server instance is automatically configured, secure, and ready to serve traffic with a working homepage and ALB health check endpoint. It saves time and avoids manual configuration errors.</p><p><strong>Step 12: Auto Scaling Group for Web Servers</strong></p><p>Automatically manages the number of EC2 web server instances, ensuring high availability, scalability, and fault tolerance.</p><p><strong>Template Snippet:</strong></p><pre>HAWebServerASG:<br>    Type: AWS::AutoScaling::AutoScalingGroup<br>    DependsOn: HAWebServerLaunchTemplate<br>    Properties:<br>      AutoScalingGroupName: !Sub &quot;${AppPrefix}WebServerASG&quot;<br>      VPCZoneIdentifier:<br>        - !Ref HAPrivateSubnet1<br>        - !Ref HAPrivateSubnet2<br>      LaunchTemplate:<br>        LaunchTemplateId: !Ref HAWebServerLaunchTemplate<br>        Version: !GetAtt HAWebServerLaunchTemplate.LatestVersionNumber<br>      MinSize: 2 # Minimum 2 instances<br>      MaxSize: 3 # Maximum 3 instances<br>      DesiredCapacity: 2<br>      TargetGroupARNs:<br>        - !Ref HAWebServerTG<br>      HealthCheckType: ELB<br>      HealthCheckGracePeriod: 300<br>      Tags:<br>        - Key: Name<br>          Value: !Sub &quot;${AppPrefix}WebServer&quot;<br>          PropagateAtLaunch: true</pre><p>Template Breakdown:</p><ul><li><strong>Logical ID:</strong> HAWebServerASG</li><li><strong>Resource Type:</strong> AWS::AutoScaling::AutoScalingGroup</li><li><strong>ASG Name: </strong>HA-APP-WebServerASG</li><li><strong>DependsOn:</strong> HAWebServerLaunchTemplate → Ensures the ASG is created only after the launch template is ready, avoiding dependency issues.</li><li><strong>VPCZoneIdentifier: </strong>→ Launches instances in <strong>two private subnets</strong> for better security and fault tolerance.</li></ul><p>LaunchTemplate:</p><ul><li><strong>LaunchTemplateId:</strong> !Ref HAWebServerLaunchTemplate → Ensures all instances use the configuration defined in the launch template.</li><li><strong>Version:</strong> !GetAtt HAWebServerLaunchTemplate.LatestVersionNumber → Always uses the <strong>latest version</strong> of the launch template.</li></ul><p>Scaling Configuration:</p><ul><li><strong>MinSize = 2</strong> → Always maintain at least <strong>2 running web servers</strong>.</li><li><strong>MaxSize = 3</strong> → Can scale up to <strong>3 instances</strong> when demand increases</li><li><strong>DesiredCapacity = 2</strong> → Runs <strong>2 instances </strong>all the time</li></ul><p>Load Balancer Integration:</p><ul><li><strong>TargetGroupARNs:</strong> !Ref HAWebServerTG<br> → Automatically registers EC2 instances with the <strong>ALB Target Group</strong>, so traffic is distributed evenly.</li></ul><p><strong>Health Checks:</strong></p><ul><li><strong>HealthCheckType:</strong> ELB<br> → Uses ALB’s health checks to monitor instance health.</li><li><strong>HealthCheckGracePeriod:</strong> 300 seconds<br> → Gives new instances <strong>5 minutes</strong> to start up and pass health checks before being considered unhealthy</li></ul><p><strong>Tags:</strong></p><ul><li><strong>PropagateAtLaunch: true</strong><br> → Applies consistent tags to every new EC2 instance launched by the ASG, making them easier to identify.</li></ul><p><strong>In short: </strong>This Auto Scaling Group ensures you always have at least <strong>two healthy web servers</strong> running in private subnets, connected to your ALB. It can scale up if needed, replaces failed instances automatically, and keeps resource naming consistent.</p><p><strong>Step 13 : Database</strong></p><p><strong>Step 13.1: Database Subnet Group</strong></p><p>Defines which <strong>private subnets</strong> the RDS instance can be deployed in, ensuring the database is isolated and not publicly accessible.</p><p>Template Snippet</p><pre> HADBSubnetGroup:<br>    Type: AWS::RDS::DBSubnetGroup<br>    Properties:<br>      DBSubnetGroupName: !Sub &quot;${AppPrefix}DBSubnetGroup&quot;<br>      DBSubnetGroupDescription: Subnet group for RDS database<br>      SubnetIds:<br>        - !Ref HAPrivateSubnet1<br>        - !Ref HAPrivateSubnet2<br>      Tags:<br>        - Key: Name<br>          Value: !Sub &quot;${AppPrefix}DBSubnetGroup&quot;</pre><p><strong>Key Properties:</strong></p><ul><li><strong>Logical ID: </strong>HADBSubnetGroup:</li><li><strong>Resource Type:</strong> AWS::RDS::DBSubnetGroup</li><li><strong>DBSubnetGroupName:</strong> HA-APP-DBSubnetGroup</li><li><strong>SubnetIds:</strong></li><li>!Ref HAPrivateSubnet1</li><li>!Ref HAPrivateSubnet2<br> → Ensures the DB is deployed in private subnets across <strong>two Availability Zones</strong> for security and resilience.</li><li><strong>Tag: </strong>HA-APP-DBSubnetGroup</li></ul><p><strong>Result:</strong> The database will only run in secure, private subnets instead of public-facing ones.</p><p><strong>Step 13.2: RDS Database Instance</strong></p><p>Creates a <strong>highly available MySQL database</strong> with automatic backups, security controls, and deletion protection.</p><p>Template snippet:</p><pre>HADatabase:<br>    Type: AWS::RDS::DBInstance<br>    Properties:<br>      DBInstanceIdentifier: !Sub &quot;${AppPrefix}Database&quot;<br>      DBInstanceClass: db.t3.micro<br>      Engine: mysql<br>      EngineVersion: &quot;8.0.35&quot;<br>      MasterUsername: admin<br>      MasterUserPassword: !Ref DatabasePassword # &lt;-- use the top-level parameter<br>      AllocatedStorage: 20<br>      DBSubnetGroupName: !Ref HADBSubnetGroup<br>      VPCSecurityGroups:<br>        - !Ref HADatabaseSG<br>      MultiAZ: true # Ensures high availability (note: Multi-AZ will incur extra cost)<br>      BackupRetentionPeriod: 7<br>      DeletionProtection: true<br>      Tags:<br>        - Key: Name<br>          Value: !Sub &quot;${AppPrefix}Database&quot;</pre><p><strong>Key Properties:</strong></p><ul><li><strong>DBInstanceIdentifier:</strong> !Sub &quot;${AppPrefix}Database&quot; → HA-APP-Database</li><li><strong>DBInstanceClass:</strong> db.t3.micro → Small, cost-effective instance type.</li><li><strong>Engine:</strong> MySQL</li><li><strong>EngineVersion:</strong> &quot;8.0.35&quot; → Specific version of MySQL.</li></ul><p><strong>Credentials:</strong></p><ul><li><strong>MasterUsername:</strong> admin</li><li><strong>MasterUserPassword:</strong> !Ref DatabasePassword<br> → Password provided via a <strong>top-level parameter</strong> for flexibility and security.</li></ul><p><strong>Storage &amp; Placement:</strong></p><ul><li><strong>AllocatedStorage:</strong> 20 GB</li><li><strong>DBSubnetGroupName:</strong> !Ref HADBSubnetGroup → Deploys the DB only in private subnets.</li><li><strong>VPCSecurityGroups:</strong> !Ref HADatabaseSG → Controls which resources (e.g., app servers) can connect.</li></ul><p><strong>High Availability &amp; Safety:</strong></p><ul><li><strong>MultiAZ:</strong> true → Database runs across two AZs for fault tolerance.</li><li><strong>BackupRetentionPeriod:</strong> 7 days → Automated daily backups retained for recovery.</li><li><strong>DeletionProtection:</strong> true → Prevents accidental database deletion.</li></ul><p><strong>Tag: </strong>HA-APP-Database</p><p><strong>Result:</strong> A secure, fault-tolerant MySQL RDS instance with automated backups, running inside private subnets and protected by strict security groups.</p><p><strong>Step 14: Outputs</strong></p><p>Outputs provide <strong>important resource details</strong> after the stack is created. These values help you connect, monitor, and reuse resources without manually searching in the AWS console.</p><p>Template snippet:</p><pre># Step 14: Outputs<br>Outputs:<br>  HAVPCId:<br>    Description: VPC ID of the HA Application<br>    Value: !Ref HAVPC<br><br>  HAPubSub1AZ1Id:<br>    Description: First Public Subnet ID (AZ1)<br>    Value: !Ref HAPublicSubnet1<br><br>  HAPubSub2AZ2Id:<br>    Description: Second Public Subnet ID (AZ2)<br>    Value: !Ref HAPublicSubnet2<br><br>  HAALBDNSName:<br>    Description: DNS Name of the Application Load Balancer<br>    Value: !GetAtt HAALB.DNSName<br><br>  HAWebServerASG:<br>    Description: Auto Scaling Group Name for Web Servers<br>    Value: !Ref HAWebServerASG<br><br>  HADatabaseEndpoint:<br>    Description: Endpoint address of the RDS Database<br>    Value: !GetAtt HADatabase.Endpoint.Address</pre><h4>Key Outputs:</h4><p><strong>HAVPCId</strong></p><ul><li><strong>Value:</strong> !Ref HAVPC</li><li>Useful when referencing the VPC for other stacks or integrations.</li></ul><p><strong>HAPubSub1AZ1Id</strong> &amp; <strong>HAPubSub2AZ2Id</strong></p><ul><li><strong>Value:</strong> !Ref HAPublicSubnet1, !Ref HAPublicSubnet</li><li>Helpful when launching new public-facing resources or debugging subnet placement.</li></ul><p><strong>HAALBDNSName</strong></p><ul><li><strong>Value:</strong> !GetAtt HAALB.DNSName</li><li>This is the URL you can use to access your web application in a browser.</li></ul><p><strong>HAWebServerASG</strong></p><ul><li><strong>Value:</strong> !Ref HAWebServerASG</li><li>Useful for monitoring scaling activity or attaching scaling policies.</li></ul><p><strong>HADatabaseEndpoint</strong></p><ul><li><strong>Value:</strong> !GetAtt HADatabase.Endpoint.Address</li><li>Applications use this address to securely connect to the MySQL database.</li></ul><p><strong>In Short: </strong>Outputs act as <strong>“quick reference notes”</strong> for your stack. Instead of hunting through the AWS console, you immediately get the most important values: <strong>VPC ID, Subnet IDs, ALB DNS, ASG Name, and Database Endpoint.</strong></p><p><strong>Step 15: Description of the template</strong></p><p>At the very top of the CloudFormation template, right after the AWSTemplateFormatVersion, we can add a <strong>Description</strong> field.</p><pre>AWSTemplateFormatVersion: &quot;2010-09-09&quot;<br>Description: CloudFormation template to deploy a highly available web application infrastructure, including a VPC with public and private subnets in two AZs, Internet and NAT Gateways, Security Groups, an Application Load Balancer, an Auto Scaling Group, and EC2 web servers.</pre><p><strong>🔎 Why this matters:</strong></p><ul><li><strong>Placement</strong> → The description always comes at the top of the template, so anyone opening it sees the purpose immediately.</li><li><strong>Purpose</strong> → It provides a human-readable summary of what the template will build - like a quick project overview.</li><li><strong>Collaboration</strong> → If multiple people are working on the template (or if you revisit it months later), this line saves time by reminding you what the template is for.</li><li><strong>Best Practice</strong> → While not required by AWS, adding a description is recommended for clarity and documentation.</li></ul><p>🚀 <strong>Deploying the Application on AWS</strong></p><p>Now that our <strong>CloudFormation template is ready</strong>, let’s deploy it on AWS and watch the magic happen!</p><p><strong>Step 1: Open CloudFormation &amp; Select Region</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DSKgLJYPKYk78KfAQ5nY2Q.jpeg" /><figcaption>Head over to the <strong>AWS Management Console → CloudFormation</strong>.</figcaption></figure><p><strong>Step 2 :Create stack</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYjk_Pn-RdJAwurKky_B9g.jpeg" /><figcaption>Click <strong>Create Stack</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9A12lE2QDEjCf0WCh2LrIg.jpeg" /><figcaption>Select ‘Choose an existing template’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*df8vsViYdhEDDKuYtUWrYg.jpeg" /><figcaption>Upload crated template file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*K_WcNzQbooHNZeP5cdQR9A.jpeg" /><figcaption>Specify parameters — 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BnUkRtUZHmLkTLCseYjM7g.jpeg" /><figcaption>specify parameters — 2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y6iqESAb8xbF8kMIm8jnQQ.jpeg" /><figcaption>Review the things before deploying</figcaption></figure><p><strong>Step 3 : Create Changeset</strong></p><p>Since I’m working in the <strong>AWS Free Tier</strong>, I didn’t want to deploy the full template directly because some resources, like NAT Gateways or Multi-AZ RDS, can incur charges. While exploring a safe solution, I discovered <strong>Change Sets</strong>. A Change Set allows you to <strong>validate your CloudFormation template without actually creating any resources</strong>. It essentially shows a preview of what changes would be applied if you deployed the stack - like which resources will be created, modified, or deleted. This way, you can <strong>catch errors, check dependencies, and estimate potential costs</strong> before committing anything, making it a safe and practical step for learning and testing in Free Tier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1e7ppUGlfhQD0mC_NQW12g.jpeg" /><figcaption>Select ‘Create change set’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*ttNiByEUb0sFk_7RLkRgRQ.jpeg" /><figcaption>Configure and create change set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1oYlgFAXHBBZ3k4Z2ptItA.jpeg" /><figcaption>Validation error occured</figcaption></figure><p><strong>ValidationError: </strong>Parameter DatabasePassword failed to satisfy constraint: Password must be 10–25 characters long and contain only letters and numbers</p><p><strong>Note: </strong>This error happened because the DatabasePassword parameter did not meet the constraints defined in the CloudFormation template.It must be 10–25 characters long and contain only letters and numbers.</p><p>The mistake made by me is I accidentally added a symbol in the password I provided, I removed it and recreated the change set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2xawAbyuw0CCxVR44S9Xqg.jpeg" /><figcaption><em>Change set created successfully — template validated with no errors</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CI5Qhd0R6eaD8VySaYCl0A.jpeg" /><figcaption><em>Change set details showing pending changes</em></figcaption></figure><p>This screenshot shows the <strong>Change Set preview</strong> in the AWS CloudFormation console. It highlights which resources would be created, modified, or deleted if the template were deployed, allowing you to safely validate your stack before actual deployment.</p><p>Since this is our <strong>initial template</strong>, the Change Set only shows resources that would be <strong>created</strong>. No modifications or deletions are present at this stage.</p><p>And just like that, our CloudFormation adventure comes to a checkpoint! 🚀 While we didn’t hit “deploy” this time, we now have a fully structured, high-availability web app template ready to go. This is where planning meets practice - a perfect playground to learn, tweak, and experiment before launching live. Stay curious, keep building, and let your cloud creations soar! ☁️✨</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*zwgbiMf2XBW835Dm8uTJrw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa493174048a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host Your React App on AWS EC2 -No Server Stress! ]]></title>
            <link>https://anjana-muthuanayake.medium.com/host-your-react-app-on-aws-ec2-no-server-stress-6e0d17aa481d?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e0d17aa481d</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[ubuntu]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 16:02:58 GMT</pubDate>
            <atom:updated>2025-09-16T16:02:58.994Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey friends! I’m at that exciting stage of exploring the amazing world of <strong>AWS Cloud</strong>, and after diving into EC2, I did a hands-on project: <strong>launching a React app on an EC2 instance</strong>. While working on this, I learned so many cool things and wanted to document them for you.</p><p>Here’s the concept: you’ve built a React app, your source code lives on your local machine, and it runs perfectly there. But what if you want the <strong>whole world to see it</strong>? You need a <strong>web server</strong> to serve your app’s files over the internet.</p><p>For this project, I chose <strong>Ubuntu</strong> as my server OS and <strong>Nginx</strong> as the web server software. Fun fact: Ubuntu by itself is just an operating system; it can’t serve websites without a web server installed. That’s where Nginx comes in; it’s fast, lightweight, and perfect for serving static files like your React build folder. With a little configuration, Ubuntu + Nginx becomes a fully functional web server, ready to host your app for the world to access.</p><p>So grab your virtual suitcase, because today we’re taking our React app <strong>on a cloud adventure</strong> with EC2 and Nginx! 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*On2yjRqkYEX13kHe11Xuyw.png" /><figcaption>React app</figcaption></figure><h3>Step 1: Launch Your EC2 Instance 🖥️☁️</h3><p>First things first, we need a cloud playground a.k.a our EC2 instance. Head over to the AWS console, click on <strong>EC2</strong>, and launch a new instance. For this project, I picked <strong>Ubuntu 24.04 LTS</strong>, because it’s stable, lightweight, and perfect for our React app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*JN8Hfq67G4WNKRj3Pbrdtg.jpeg" /><figcaption>Launch instance</figcaption></figure><p>Don’t forget to choose a key pair so you can SSH into your server later. Security groups are your new best friends here, they act like gatekeepers. In your EC2 security group, make sure to allow <strong>HTTP (port 80)</strong> so the world can visit your site, and <strong>SSH (port 22)</strong> so you can hop into your server like a pro.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*RY5LrsflwAymvOkQvMVHvA.jpeg" /><figcaption>Security group rules</figcaption></figure><p>Also, set up the <strong>network settings</strong> for your EC2 instance. You can go with the default network, or attach your own <strong>VPCs and subnets</strong>. Just make sure your instance is in a <strong>public subnet</strong>, because our goal is to make this EC2 a web server accessible from the outside world. 🌍</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bM976mMTkBdEC3096P7U9w.jpeg" /><figcaption>Created EC2 server</figcaption></figure><h3>Step 2: Connect to Your Server 🔑</h3><p>Once your EC2 instance is up and running, the next step is to connect. First, go to the <strong>EC2 dashboard</strong>, select the server you just created, and click on <strong>Connect</strong>. Navigate to the <strong>SSH tab</strong>, and you’ll see a pre-filled prompt for connecting via SSH. You can either <strong>copy that prompt directly</strong> or just <strong>copy the public IP or DNS</strong> of your instance and use it in the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*hyFprbqifwK3_OK8DxMtfw.jpeg" /><figcaption>Connect to instance</figcaption></figure><p>Or, in your terminal, run the SSH command like this:</p><pre>ssh -i &quot;your-key.pem&quot; ubuntu@your-ec2-public-ip</pre><p>And voila! You’re inside your Ubuntu server. Feels like teleportation, right? 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/758/1*kBompEJuG3AGTl5tJg50Ew.jpeg" /><figcaption>ssh to EC2 instance</figcaption></figure><p><strong>Tip:</strong> Make sure your terminal is <strong>in the folder on your local machine where your key pair file is stored</strong> before running the SSH command. Otherwise, you’ll need to provide the <strong>full path</strong> to the key file instead of just its name.</p><p>For example:</p><pre>ssh -i /full/path/to/your-key.pem ubuntu@your-ec2-public-ip</pre><h3>Step 3: Install Node.js and npm ⚙️</h3><p>Before we can serve our React app, we need to make sure our server speaks the React language. That means installing <strong>Node.js</strong> and <strong>npm</strong>. Don’t worry, it’s super easy! On your EC2 terminal, run:</p><pre>sudo apt update<br>sudo apt install -y nodejs npm</pre><p>Once that’s done, let’s check if everything installed correctly:</p><pre>node -v<br>npm -v</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*j1pqK52H7HTgZ1gsveYDWA.jpeg" /><figcaption>verify nodejs &amp; npm versions</figcaption></figure><p>If you see version numbers pop up, congratulations! 🎉 Your server is now ready to build and run React apps. Think of Node.js as the engine and npm as the fuel that powers your React adventure.</p><h3>Step 4: Install and Start Nginx 🌐</h3><p>Now that our server can build React apps, it’s time to give it a <strong>webserver superpower</strong> with Nginx! This is what will actually serve your React app to the world.</p><p>First, update your package lists and install Nginx:</p><pre>sudo apt install -y nginx</pre><p>Next, let’s start Nginx and make sure it launches automatically if the server ever restarts:</p><pre>sudo systemctl start nginx<br>sudo systemctl enable nginx</pre><p>Want to double-check that Nginx is up and running? Use:</p><pre>systemctl status nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*Bn2-fwgO9ZrY57Y-4nJoPA.jpeg" /><figcaption>nginx setup</figcaption></figure><p>If everything looks green, that means Nginx is <strong>active and running properly</strong>, ready to serve web pages. To confirm, <strong>copy your EC2 instance’s public IP</strong> and paste it into a browser. If you see the <strong>default Nginx welcome page</strong>, congratulations! 🎉 Your server is officially a web server, ready to host your React app. Think of Nginx as the friendly doorman letting visitors into your app party. 🥳</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/1*COyoKQfvOxBYNG8hz1Gi2Q.jpeg" /><figcaption>nginx welcome page</figcaption></figure><h3>Step 5: Clone Your React App from GitHub and Personalize It 💻✨</h3><p>Now that our server is ready, let’s bring your React app to life! First, navigate to a temporary directory on your EC2 instance and <strong>clone the GitHub repository</strong>:</p><pre>git clone https://github.com/pravinmishraaws/my-react-app.git<br>cd my-react-app</pre><p>Next, let’s open the <strong>App.js</strong> file to personalize your app. Navigate to the source folder:</p><pre>cd src<br>vi App.js</pre><p>(or use <strong>nano</strong> if that’s your style 🎨)</p><p>Here, you can update the content to show your details. For example:</p><pre>&lt;h2&gt;Deployed by: &lt;strong&gt;Your Full Name&lt;/strong&gt;&lt;/h2&gt;<br>&lt;p&gt;Date: &lt;strong&gt;DD/MM/YYYY&lt;/strong&gt;&lt;/p&gt;</pre><p>Don’t forget to replace <strong>Your Full Name</strong> and <strong>DD/MM/YYYY</strong> with your actual name and deployment date. This little tweak makes your app uniquely yours, like putting your name on a masterpiece! 🖌️</p><h3>Step 6: Install Dependencies and Build the React App 🛠️✨</h3><p>Now that your app is on the server, it’s time to prepare it for the web. First, install all the <strong>required dependencies</strong>:</p><pre>npm install</pre><p>Once everything is installed, it’s time to <strong>build your React app</strong>:</p><pre>npm run build</pre><p>This command generates a <strong>build/</strong> folder containing all the production-ready static files your app needs. Think of it as packing your app into a neat suitcase, fully optimized and ready for the cloud adventure! 🧳🌐</p><h3>Step 7: Deploy Build Files to the Nginx Web Directory 🚀🌐</h3><p>Now that your React app is built and ready, it’s time to <strong>place it where Nginx can serve it</strong>.</p><p>First, let’s clear any existing files in the Nginx web directory:</p><pre>sudo rm -rf /var/www/html/*</pre><p>Next, <strong>copy your React build files</strong> to the Nginx web directory:</p><pre>sudo cp -r build/* /var/www/html/</pre><p><strong>Why do we do this? 🤔</strong><br> Nginx serves websites from the <strong>/var/www/html</strong> folder by default. Our React app’s build folder contains all the optimized, production-ready static files, but Nginx doesn’t automatically know about this folder. By copying the contents into /var/www/html, we’re telling Nginx: <strong>“Here are the files to serve to anyone visiting our site!”</strong> 🌐✨</p><p>Finally, set the <strong>proper permissions</strong> so Nginx can serve the files without any issues:</p><pre>sudo chown -R www-data:www-data /var/www/html<br>sudo chmod -R 755 /var/www/html</pre><p>At this point, your React files are in place, but we still need to <strong>configure Nginx</strong> to handle React’s single-page routing correctly. That’s what we’ll do in the next step.</p><h3>Step 8: Configure Nginx for React ⚙️🌐</h3><p>Now that your React app’s files are in the Nginx web directory, we need to <strong>tell Nginx how to serve them properly</strong>. React apps are single-page applications (SPA), which means all routes are handled client-side. Without proper configuration, refreshing a page or visiting a nested route could result in a <strong>404 error</strong>.</p><p>Here’s how to configure Nginx for React:</p><pre>echo &#39;server {<br>    listen 80;<br>    server_name _;<br>    root /var/www/html;<br>    index index.html;<br>    <br>    location / {<br>        try_files $uri /index.html;<br>    }<br><br>    error_page 404 /index.html;<br>}&#39; | sudo tee /etc/nginx/sites-available/default &gt; /dev/null</pre><p><strong>What’s happening here:</strong></p><ul><li>root /var/www/html; → This tells Nginx where your app files live.</li><li>try_files $uri /index.html; → If a requested route/file doesn’t exist, serve index.html instead. This is essential for React SPAs so routing works correctly.</li><li>error_page 404 /index.html; → Even if a user types a wrong URL, React handles it gracefully instead of showing a server 404 error.</li></ul><p>Finally, restart Nginx to apply these changes:</p><pre>sudo systemctl restart nginx</pre><p>And that’s it! Nginx is now fully aware of your React app and ready to serve it properly to anyone visiting your site. 🚀</p><h3>Step 8: Find Your Public IP and Access the Application 🌍💻</h3><p>To see your React app live, first retrieve the <strong>public IP</strong> of your Ubuntu VM:</p><pre>curl ifconfig.me</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*Kp_9SMMsElGDSHjedLARwQ.jpeg" /><figcaption>retrieve IP address using curl</figcaption></figure><p>Once you have your public IP, open a browser and type:</p><pre>http://&lt;your-public-ip&gt;   OR<br><br>http://&lt;your-public-dns&gt;  } You can find this from the EC2 details in aws mgt console</pre><p>For example, if your public IP is 203.0.113.25, just visit:</p><pre>http://203.0.113.25</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckHXsj1F0WuPQb_nd3-MBA.jpeg" /><figcaption>React app is running</figcaption></figure><p>And… you should see your React app in all its glory! 🎉</p><h3>Step 9: Verify the Deployment ✅</h3><p>To make sure everything is working perfectly, you can also check from the terminal:</p><pre>curl &lt;your-public-ip&gt;</pre><p>If the HTML content of your React app appears, congratulations! Your React application is <strong>successfully live on an Ubuntu VM with Nginx</strong>, accessible from anywhere in the world. 🌐🚀</p><p>And that’s it - your React app is now live and running on Ubuntu with Nginx! 🚀 From local code to a publicly accessible website, you’ve just walked through a real-world deployment process. This is the same foundation used in production environments, so the skills you practiced here will come in handy again and again. Keep experimenting, keep building, and before you know it, you’ll be deploying even bigger and more exciting projects in the cloud! 🌐✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e0d17aa481d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[No Servers Needed: Launch Your Static Website with S3 ]]></title>
            <link>https://anjana-muthuanayake.medium.com/no-servers-needed-launch-your-static-website-with-s3-09a183200874?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/09a183200874</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws-s3-bucket]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-s3]]></category>
            <category><![CDATA[static-website-with-s3]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Tue, 16 Sep 2025 11:11:01 GMT</pubDate>
            <atom:updated>2025-09-16T11:11:01.802Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey, imagine you’ve decided to create your <strong>portfolio website</strong>. Sounds exciting, right? Now you can showcase your work to the world! But what’s the first step?</p><p>Probably something like this:</p><ol><li><strong>Create your own source code</strong> or <strong>choose a suitable website template</strong> and edit it with your information.</li></ol><p>Great! Now you have a <strong>nice and clean portfolio website</strong>. You run it on your local browser, it loads perfectly, looks exactly how you want it. But wait… can others see it? No, not yet. Your website isn’t live because it <strong>hasn’t been hosted on a web server</strong>.</p><p>So, how do we make it accessible? There are several ways:</p><ul><li>Get a physical or virtual server and host it yourself.</li><li>Pay a third-party hosting service to host it for you.</li></ul><p>But hold on! This is just a <strong>simple static website; </strong>a few HTML, CSS, and maybe some images. Do we really need to spend so much effort or money? <strong>Nope!</strong></p><p>As T’Challa said, <em>“We don’t do that here.”</em> 😎</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*qC_vzKniv60pCscYKwSA4w.jpeg" /></figure><p>Instead, we can use <strong>AWS S3</strong>, which provides an <strong>easy-peasy way to host static website content</strong>. You only pay for:</p><ul><li>The <strong>storage</strong> you’re using</li><li>The <strong>requests</strong> made to your website</li></ul><p>Since this is a lightweight site (a few KBs or MBs) and won’t get massive traffic, your hosting cost is probably just a few <strong>cents to a couple of dollars per month, way cheaper than traditional hosting</strong>.</p><p>Now you might be wondering, <strong>what exactly is an S3 bucket?</strong></p><p>Well, an <strong>S3 bucket</strong> is basically a simple <strong>storage service provided by AWS Cloud</strong>. Think of it like a super-organized digital folder where you can store files; images, PDFs, MP3s, and pretty much anything.</p><p>But here’s the magic ✨ it’s <strong>not just for storage</strong>. AWS S3 also allows you to <strong>host static websites</strong>! That means you can serve your HTML, CSS, and JS files directly to users, without needing a server.</p><p>Hosting a static website on S3 is <strong>surprisingly easy</strong>. The basic steps are:</p><ol><li>Upload your website folder into the S3 bucket.</li><li>Enable <strong>Static Website Hosting</strong> in the bucket settings.</li><li>Enable <strong>public access</strong> so anyone can visit your site.</li><li>Copy the <strong>static website endpoint</strong> generated by S3 and paste it into your browser.</li></ol><p>✨ <strong>Voila!</strong> Your website is now live and accessible to the world , all without setting up a traditional web server.</p><p>Now let’s discuss <strong>why we should host our static website on AWS S3</strong>.</p><p>Honestly, this is pretty straightforward. At the end of the day, everything boils down to <strong>dollars 💸</strong>. Hosting your website on S3 is <strong>cost-effective, </strong>you only pay for the storage used and the requests made to your website. No expensive monthly hosting plans or hidden fees!</p><p>The next reason is <strong>simplicity</strong>. Hosting on S3 is as easy as uploading files to <strong>Google Drive</strong>. No complex technical setup is needed, just <strong>upload your website folder → enable static website hosting → enable public access → done!</strong></p><p>But wait, there’s more:</p><h4>Scalable</h4><p>AWS S3 automatically handles <strong>traffic spikes</strong>. That means if suddenly 1,000 people visit your website at the same time, S3 will serve all requests without you needing to do anything. You don’t have to worry about servers crashing or slow load times, <strong>S3 grows automatically with your traffic</strong>.</p><h4>Highly Available</h4><p>S3 stores your files across <strong>multiple data centers in the AWS region</strong>. Even if one data center goes down, your website remains accessible from another location. This ensures your site is <strong>always online and reliable</strong>, without you managing servers or backups.</p><p>So yes, S3 is <strong>cheap, simple, scalable, and highly available </strong>basically everything a static website needs!</p><p>So, when would you actually use static website hosting?</p><ul><li><strong>Portfolio websites:</strong> Ideal for showcasing your work, projects, and skills. Simple, static, and easy to update.</li><li><strong>Landing pages:</strong> Single-page sites designed to capture information from visitors -like emails or sign-ups. Static hosting works perfectly since there’s no need for dynamic processing.</li><li><strong>Documentation sites:</strong> Perfect for guides, tutorials, or manuals where the content is mostly read-only.</li><li><strong>Blogs without dynamic features:</strong> If your blog doesn’t need comments, logins, or interactive content, static hosting is fast, simple, and cost-effective.</li></ul><p>In short, <strong>any website that mostly displays content and doesn’t require server-side processing</strong> is a perfect candidate for S3 static website hosting.</p><p>Uploading files to S3 is one thing, but accessing them is a whole different story. The method depends on whether your bucket is private, public, or serving a static website.</p><p>Usually, we use S3 as a <strong>storage service; </strong>uploading files like images, PDFs, or music to S3 buckets. Whether you use the <strong>AWS Management Console, AWS CLI, or SDK</strong>, behind the scenes, you’re actually making <strong>API calls</strong> to upload, download, or retrieve objects.</p><p>But when we enable <strong>static website hosting</strong> on an S3 bucket, things change a little. S3 now allows the bucket to serve content over the <strong>HTTP protocol</strong>. That means instead of accessing objects with API calls, we (and anyone on the internet) can simply open a web browser and access the files directly via a <strong>static website endpoint</strong>. This is what makes it possible for S3 to act not just as storage, but also as a simple web server for your static site.</p><p>Here’s a quick comparison of the different access scenarios:</p><pre>+-------------------------+---------------------------+---------------------------+--------------------------------------------------+<br>| Bucket Type / Scenario  | Who Can Access            | How Access Happens        | Notes                                            |<br>+-------------------------+---------------------------+---------------------------+--------------------------------------------------+<br>| Private (default)       | IAM users or bucket owner | API calls (CLI, SDK,      | Secure by default; no public access              |<br>|                         |                           | Console)                  |                                                  |<br>+-------------------------+---------------------------+---------------------------+--------------------------------------------------+<br>| Public objects          | Anyone on the internet    | HTTP/HTTPS URL            | Can expose individual objects or full bucket     |<br>+-------------------------+---------------------------+---------------------------+--------------------------------------------------+<br>| Static Website Hosting  | Anyone with website       | HTTP (via static endpoint)| S3 behaves like a web server, serving            |<br>|                         | endpoint                  |                           | HTML/CSS/JS directly                             |<br>+-------------------------+---------------------------+---------------------------+--------------------------------------------------+</pre><p>When we enable <strong>Static Website Hosting</strong> on an S3 bucket, AWS gives us something called a <strong>static website endpoint</strong>. This is basically the special URL we use to access our hosted website.</p><p>Now, here’s the cool part: these endpoints come in <strong>two different formats</strong>, depending on the AWS region:</p><ol><li>Dash Format</li></ol><pre>http://bucket-name.s3-website-Region.amazonaws.com</pre><p>👉 Example:</p><pre>http://my-portfolio.s3-website-us-east-1.amazonaws.com</pre><p>2. Dot Format</p><pre>http://bucket-name.s3-website.Region.amazonaws.com</pre><p>👉 Example:</p><pre>http://my-portfolio.s3-website.ap-south-1.amazonaws.com</pre><p>These small variations happen because AWS handles endpoints slightly differently from region to region.</p><p>But the bottom line is: once you copy this endpoint and paste it into your browser, <strong>boom 💥 your static website is live on the internet!</strong></p><p>Hey, wait… did you notice something unusual about the S3 website endpoint compared to normal website domain names? 👀<br>Instead of looking like www.xyz.com, it has that long AWS-generated format, like:</p><pre>http://my-portfolio.s3-website-us-east-1.amazonaws.com</pre><p>Now, if you want your website to look more professional (something short and clean like www.myportfolio.com), you can totally do that by using <strong>Amazon Route 53</strong>. Route 53 is AWS’s DNS service that lets you map your custom domain name to your S3 bucket endpoint.</p><p>But here’s the important bit 📝 when creating your S3 bucket, make sure the <strong>bucket name exactly matches your custom domain name</strong>. For example:</p><ul><li>If your domain is myportfolio.com, your bucket name must be myportfolio.com.</li><li>If your domain is www.myportfolio.com, then your bucket name must be <a href="http://www.myportfolio.com./">www.myportfolio.com.</a></li></ul><p>That way, Route 53 can properly connect your domain with the S3 bucket, and your visitors will access your static website through a nice, clean URL.</p><p><strong>Curious how to host static website in AWS S3 bucket, Let’s begin;</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yNVHBAZGIE_j3s5PlPsnvA.png" /><figcaption>Step by step guide</figcaption></figure><p><strong>Step 1: Open the AWS Management Console</strong><br>Before we can do anything, we need to log in to the <strong>AWS Management Console</strong>. This is your central hub for managing all AWS services, including S3. Think of it like the dashboard of your car, everything starts here! 🚗💨</p><p>Once you’re in, you’ll be able to navigate to S3 and create your bucket, manage permissions, and enable static website hosting, all from this single place.</p><p><em>Tip:</em> Make sure you’re logged in to the correct AWS account where you want to host your website.</p><p><strong>Step 2: Navigate to the S3 Console</strong><br> Once you’re inside the AWS Management Console, search for S3 in the search bar. S3 is where all the magic happens, this is where we’ll create a bucket to hold our website files.</p><p>Think of the S3 console as your website’s storage locker. From here, you can create buckets, upload files, manage permissions, and even enable static website hosting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBkrbZ_pWo_s8oTlMMLTmQ.jpeg" /><figcaption>Navigate to S3 console</figcaption></figure><p><strong>Step 3: Create Your Bucket and Upload Your Website</strong></p><p>1️⃣ <strong>Create the Bucket</strong></p><ul><li>Click <strong>“Buckets” → “Create bucket”</strong>.</li><li>Give your bucket a <strong>globally unique name</strong>. This name must be unique across all AWS accounts.<br> <em>💡 Tip:</em> If you plan to use a custom domain later, make the bucket name match your domain. This makes routing your domain easier.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RZFT91rYPDqgz9WCnbZi1Q.jpeg" /><figcaption>Buckets → Create Bucket → Bucket name</figcaption></figure><p>2️⃣ <strong>Download a Sample Website Template</strong></p><ul><li>You can either create your own website files or use a ready-made template.</li><li>Some good sources: <a href="https://www.tooplate.com/">Tooplate</a>, HTML5 UP, BootstrapMade.</li><li>For this tutorial, we’ll use the <strong>Mini Finance template</strong> from Tooplate. ( <a href="https://www.tooplate.com/view/2135-mini-finance">https://www.tooplate.com/view/2135-mini-finance</a>)<br> <em>💡 Fun Fact:</em> Templates save tons of time, especially if you just want to test S3 hosting without designing everything from scratch.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uTNKSQt9pOn4qz5LnrcIcw.png" /><figcaption>Sample static website template download</figcaption></figure><p>3️⃣ <strong>Upload Your Website to created S3 bucket</strong></p><ul><li>On your local machine, open a terminal and navigate to your website folder.</li><li>You can upload the files using either:</li><li><strong>AWS Management Console:</strong> drag-and-drop files into the bucket</li><li><strong>AWS CLI (recommended for multiple files):</strong></li></ul><pre>aws s3 sync . s3://&lt;your-bucket-name&gt; --profile &lt;profile-name&gt;</pre><ul><li>Check the S3 console to ensure all files are uploaded correctly.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NiuWrM7zGahfAS3ulehR6w.jpeg" /><figcaption>Website files uploaded to AWS S3</figcaption></figure><p><em>💡 Why CLI? It’s faster for large folders and ensures your local structure stays intact in S3.</em></p><p>4️⃣ <strong>Enable Static Website Hosting</strong></p><ul><li>Go to the <strong>Properties</strong> tab of your bucket.</li><li>Scroll down to <strong>Static Website Hosting</strong>, click <strong>Edit</strong>, and <strong>Enable</strong> it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ieqB_I-m_0E9fy3lcnM7Yg.jpeg" /><figcaption>Enable static website hosting</figcaption></figure><ul><li>Set your <strong>index document</strong> (usually index.html) and save.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*WNKwzKEXvaMJdeS_fbjs_A.jpeg" /><figcaption>Set index document</figcaption></figure><p><em>💡 Tip:</em> The index document is like the “front door” of your website, visitors will always land here first.</p><ul><li>You’ll now see a <strong>website endpoint URL, </strong>this is the link to your live site.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wQ0hFbi1GAvSSKYyo0dR0A.jpeg" /><figcaption>static website endpoint</figcaption></figure><p>5️⃣ <strong>Allow Public Access</strong></p><ul><li>By default, S3 blocks public access. Go to the <strong>Permissions</strong> tab → <strong>Block public access</strong>, and untick the checkbox. Confirm the change.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLKrgXNl5pWWOdox1-gXmw.jpeg" /><figcaption>Allow public access</figcaption></figure><ul><li>Add a <strong>bucket policy</strong> to allow public read access:</li></ul><pre>{   &quot;Version&quot;: &quot;2012-10-17&quot;,   &quot;Statement&quot;: [     {       &quot;Effect&quot;: &quot;Allow&quot;,       &quot;Principal&quot;: &quot;*&quot;,       &quot;Action&quot;: &quot;s3:GetObject&quot;,       &quot;Resource&quot;: &quot;arn:aws:s3:::&lt;your-bucket-name&gt;/*&quot;     }   ] }</pre><ul><li>Save the policy.<br> <em>💡 Why this step? Without public access, your website won’t be visible to anyone on the internet. This is critical for hosting a static site.</em></li></ul><p>6️⃣ <strong>Test Your Website</strong></p><ul><li>Go back to <strong>Static Website Hosting</strong> and copy the <strong>website endpoint URL</strong>.</li><li>Paste it into your browser, <strong>voila!</strong> Your static website is live 🚀<br> <em>💡 Fun Fact:</em> This URL is AWS’s default, but you can later point a custom domain using Route 53 to make it look professional (like <a href="http://www.myportfolio.com)./">www.myportfolio.com).</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vzSnSYP6RG4MlhcFN17P0w.jpeg" /><figcaption>Static website is live</figcaption></figure><p>And there you have it. Just like that, you’ve gone from a simple folder of HTML, CSS, and images on your computer to a <strong>live website hosted in the cloud,</strong> all without dealing with servers or complex setups.</p><p>Hosting your static website on AWS S3 is super <strong>easy, cheap, and scalable</strong>. Whether it’s a portfolio, a landing page, documentation, or a simple blog, S3 has got your back. And the best part? You didn’t need to be a server wizard or spend big bucks, just a few clicks (and a tiny bit of AWS magic ✨) and your website is online.</p><p>So go ahead, show off your work, experiment, and enjoy the feeling of seeing your website live. Let AWS S3 do the heavy lifting. Who knew hosting a website could be this chill? 😎</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=09a183200874" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding SDLC Through a Construction Analogy]]></title>
            <link>https://anjana-muthuanayake.medium.com/understanding-sdlc-through-a-construction-analogy-b2fd6f927f57?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2fd6f927f57</guid>
            <category><![CDATA[sdlc]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[sdlc-model]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Fri, 05 Sep 2025 09:08:46 GMT</pubDate>
            <atom:updated>2025-09-10T13:16:41.328Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey! Ever been involved in a construction project? Even if you haven’t, this scenario will feel familiar.</p><h3>Phase 1: From Idea to Inspiration</h3><p><strong>🏗 Analogy:</strong><br> Meet <strong>Dave</strong> 👷‍♂️ - he has a dream of building his company’s new office with a beautiful interior and exterior.<br> After doing some research, he finds <strong>Archio</strong>, a construction and consultation company that can bring his dream office to life.</p><p><strong>💻 Real-World SDLC:</strong><br> Just like Dave had a dream office in mind, <strong>every software in the world starts with an idea</strong> - someone visualizing a change they want to bring to the world.<br> In SDLC, we call these people <strong>Business Owners or Stakeholders</strong>.<br> And just like Dave picked Archio, these stakeholders look for the <strong>right software company</strong> to turn their idea into a real, working application.</p><p>We call this phase <strong><em>Brainstorming</em></strong> in the software world.</p><h3>Phase 2: Requirements Gathering</h3><p><strong>🏗 Analogy:</strong></p><p>Dave calls Archio and arranges a meeting with <strong>Sam</strong>, the Business Analyst (BA) of Archio.<br>Sam sits down with Dave to discuss his vision and asks a series of clarifying questions:</p><ul><li>How many floors do you want?</li><li>How many rooms?</li><li>Do you prefer an open-plan office or private cabins?</li><li>Any special requirements like a cafeteria, conference rooms, or parking area?</li></ul><p>Sam listens carefully, making sure he fully understands what Dave wants to achieve.<br>After the meeting, Sam writes down all of Dave’s requirements and creates an <strong>Office Requirements Specification Document</strong>. Let’s call it <strong>ORS</strong> Doc.</p><p>In this document, Sam focuses on two main types of requirements:</p><ol><li><strong>Functional Requirements (What to Build)</strong> 🏗️<br>Features and facilities that must exist in the office - the <strong>core functionality</strong>.</li></ol><p><strong><em>Examples:</em></strong></p><ul><li>Number of floors (single or multi-story)</li><li>Room layout (open-plan or cabins)</li><li>Cafeteria, conference rooms, parking space</li></ul><p><strong>2. Non-Functional Requirements (How it Should Perform)</strong> 🛡️<br> <strong>Quality standards</strong> and conditions under which the office must operate.</p><p><strong><em>Examples:</em></strong></p><ul><li>Strong foundation, durable materials</li><li>Safety standards: fire exits, wiring safety, emergency plans</li><li>High availability of utilities (electricity, water, internet)</li><li><strong>Annual Maintenance Contract (AMC):</strong> regular inspections, quick fixes, ongoing support</li></ul><p>Once the document is ready, Sam reviews it with Dave, collects feedback, and updates it if needed.<br> This process ensures <strong>everything is clear before moving to the design</strong> <strong>phase -</strong> usually taking about a month.</p><p><strong>💻 Real-World SDLC:</strong></p><p>Just like Dave met Sam, in the software world <strong>Business Owners (BOs)</strong> meet <strong>Business Analysts (BAs)</strong> to share their vision and requirements, which type of software they need to create.</p><p>The BA asks questions such as:</p><ul><li><strong>What are the features do you need ?</strong></li></ul><p>→ Login, sign-up, product listing, checkout process</p><ul><li><strong>What are the special requirements?</strong></li></ul><p>→ High availability, fault tolerance, specific SLA</p><ul><li><strong>User focus:</strong></li></ul><p>→ Who are your target users? Where are they located?</p><p>The BA listens carefully and then creates a <strong>Software Requirements Specification (SRS) Document</strong> - just like the ORS Doc in construction.</p><p>The SRS Doc also has two main sections:</p><ol><li><strong>Functional Requirements:</strong> the features the software must provide</li></ol><p><strong><em>Examples:</em></strong></p><ul><li>user login</li><li>checkout process</li><li>product listing page</li></ul><p>2. <strong>Non-Functional Requirements: </strong>how the software must perform</p><p><strong><em>Examples:</em></strong></p><ul><li>High Availability</li><li>Fault Tolerance</li><li>99.99% SLA</li><li>Security (encryption, authentication)</li><li>Scalability</li><li>AMC = Maintenance &amp; Support contracts</li></ul><p>Once the SRS is ready, the BA shares it with the BO, gathers feedback, and revises if needed.<br> This process usually takes around <strong>4-8 weeks</strong>, depending on project complexity.</p><h3>Phase 3: Design &amp; Architecture</h3><p>Once Dave approves the requirements, <strong>Sam</strong> hands the Office Requirements Specification Document (ORS Doc) to <strong>Archio’s Architecture Team</strong>.</p><p>This team includes:</p><ul><li><strong>Architects 🏢</strong> - Define the overall building structure: number of floors, layout of rooms, entrances, exits, and how everything connects.</li><li><strong>Interior Designers 🎨</strong> - Plan the interior layout, color schemes, furniture placement, lighting design, and other elements that make the workspace functional and beautiful.</li><li><strong>Exterior Designers 🖼</strong> - decide how the outside of the building will look: facade, windows, parking areas, landscaping, and the surrounding garden.</li><li><strong>Structural Engineers 🏗️</strong> - Design the core structural elements that holds everything together (beams, columns, foundation strength) to ensure the building is safe and stable.</li></ul><p>The team then creates a <strong>Technical Design Document</strong> containing all these details - essentially the blueprint for the dream office.</p><p>Once the document is ready, <strong>Sam meets Dave again</strong>, presents the designs, and gets feedback.<br>If Dave requests changes, the team updates the document until Dave is satisfied and gives final approval.</p><p>This design and approval process takes around <strong>3-4 months</strong>, but it ensures that everyone is aligned before construction begins.</p><p>💻 <strong>Real-World SDLC:</strong><br> Just like Archio’s architects and engineers, the software team now moves into the <strong>Design Phase</strong>:</p><ul><li><strong>Software Architects 🏢</strong> - Just like architects in construction decide the building’s structure, Software Architectures Define the overall system architecture: choose between monolithic or microservices approach, plan integrations, APIs, and determine how different components will communicate.</li><li><strong>UI/UX Designers 🎨🖼</strong> - Just like exterior designers plan how a building will look from the outside, UI/UX Designers<strong> </strong>design how the software will look and feel for users. They create sketches (wireframes) to show where buttons, menus, and pages will go, and choose colors and layouts to make the software easy and pleasant to use.</li><li><strong>Database &amp; System Architects 🏗️</strong> - Just like structural engineers plan the strength and skeleton of a building, database &amp; system architects plan where and how the software will store and organize information, ensuring it’s secure, scalable, and easy to access.Database &amp; System Architects<strong> </strong>Plan where and how the software will store information (database design). They decide what data needs to be saved, how it will be connected (tables and relationships), and what kind of servers or storage are needed so the software runs smoothly even if many users are using it at once.</li></ul><p>When all these designs are complete, they are put together into a <strong>Technical Design Document (TDD)</strong> - just like the final blueprint of Dave’s office.</p><p>Once the document is ready, the <strong>Business Analyst</strong> meets with the <strong>Product Owner</strong> again to review the designs.<br> If the Product Owner suggests any changes or improvements, the team updates the document.<br> This process continues until the Product Owner is fully satisfied and gives the final approval to move forward.</p><h3><strong>Phase 4: Construction (Development)</strong></h3><p>With the design finalized, the Construction Team 👷‍♂️👷‍♀️ starts building the office according to the technical document.</p><p><strong>Preparation:</strong><br>Before construction starts, the team sets up the environment:</p><ul><li>Bring in machines and equipment 🏗️</li><li>Prepare the site and ensure safety measures 🦺</li><li>Arrange all tools needed (cement mixers, cranes, wiring tools, plumbing equipment, etc.)</li></ul><p><strong>Interior Work:</strong></p><ul><li>Walls go up, wiring and plumbing are installed</li><li>Floors are laid, and furniture is arrangedFloors are laid, and furniture is arranged</li></ul><p><strong>Exterior Work:</strong></p><ul><li>The building facade is completed</li><li>Windows and doors are installed</li><li>Surrounding garden and outdoor spaces are built</li></ul><p>While construction progresses, <strong>site engineers</strong> regularly review the work to ensure it meets design specifications, follows best practices, and maintains safety standards.<br> This ensures the office will be fully functional and ready for the customer.</p><p>Construction took around <strong>10 months</strong>, depending on the complexity of the office.</p><p><strong>💻 Real-World SDLC:</strong></p><p>Just like constructors, <strong>developers</strong> start building the software according to the <strong>Technical Design Document (TDD)</strong>.</p><p><strong>Preparation:</strong></p><ul><li>Set up development environments</li><li>Install necessary tools: IDEs, compilers, version control, databases, servers</li></ul><p><strong>Backend Development (Interior Work):</strong></p><ul><li>Developers write backend logic: business rules, database interactions, APIs, authentication, and core functionality</li><li>Ensures the “inside” of the software works correctly</li></ul><p><strong>Frontend Development (Exterior Work):</strong></p><ul><li>Developers implement UI and UX (User Interface &amp; User Experience): screens, layouts, navigation, and interactive features</li><li>Ensures the software is intuitive and visually appealing</li></ul><p><strong>Unit Testing / Code Review:</strong></p><p>When the developers write the code;</p><ul><li>Tech leads or peers review the code for to make sure if the code written well, following the best practices and no security issues.</li><li>They ensure the application is stable, secure, and ready for production</li></ul><p>This development process can take <strong>6–12 months or more</strong>, depending on the software type and complexity.</p><p>In the SDLC, this phase is called the <strong>Coding &amp; Implementation Phase</strong> -where the blueprint is transformed into a working application.</p><h3>Phase 5: Quality Checks (Testing)</h3><p>Once construction is complete, the <strong>Quality Inspectors 🔍</strong> carefully review everything to ensure it matches the approved design:</p><ul><li><strong>Structural Checks:</strong> Are walls, doors, and windows built exactly as planned?</li><li><strong>Safety Checks:</strong> Is wiring and plumbing installed safely and correctly? Are fire alarms, exits, and other safety measures in place?</li><li><strong>Finishing Checks:</strong> Are floors, furniture, and fixtures properly arranged?</li><li><strong>Exterior Checks:</strong> Is the garden and outdoor area completed to standard?</li></ul><p>If any part doesn’t meet the standards, inspectors send it back to the construction team for corrections.<br>This testing and correction process took around <strong>3 months</strong>.</p><p><strong>💻 Real-World SDLC:</strong></p><p>Just like quality inspectors in construction, the <strong>Software Testing Team</strong> checks the developed software to ensure it works correctly, safely, and efficiently.</p><ul><li>Integration testing - Verify that different modules work together properly.</li><li>System testing - Test the entire system against the requirements.</li><li><strong>User Acceptance Criteria (UAC)</strong> -Before real users try the software, the <strong>testing team creates </strong>a checklist of conditions that the software <strong>must meet to be accepted by the user/business owner</strong>.</li></ul><p>Think of it like the testing team creating a checklist of all the things the finished office must meet to be accepted by Dave, the business owner.</p><pre>* Are the rooms the right size?<br><br>* Is the lighting correct?<br><br>* Is the furniture placed properly?<br><br>* Does the AC work as expected?</pre><p>Testers identify <strong>bugs or issues</strong> in the software. If problems are found:</p><ul><li>They report them to the <strong>developers</strong></li><li>Developers fix the issues</li><li>Testers re-test to confirm everything works correctly</li></ul><p>This stage often involves <strong>small iterations</strong> between developers and testers to refine and improve the software.</p><p>This <strong>testing phase usually takes 2–4 months</strong>, depending on the software’s size and complexity.</p><p>In SDLC, this is called the <strong>Testing Phase</strong>, ensuring the final software is reliable, secure, and ready for deployment.</p><h3>Phase 6: Handover (Deployment)</h3><p>After <strong>18 months</strong>, the office is finally ready 🎉.</p><ul><li>Archio conducts a <strong>final walkthrough</strong> with Dave, ensuring every detail matches his expectations.</li><li>Once everything is confirmed, they <strong>hand over the keys 🔑</strong>, and Dave officially moves into his dream office.</li></ul><p><strong>💻 Real-World SDLC:</strong></p><p><strong>Steps in Deployment:</strong></p><ol><li><strong>Prepare the environment:</strong></li></ol><ul><li>System admins set up servers, databases, and network configurations.</li></ul><p><strong>2. Deploy to UAT / Pre-production environment:</strong></p><ul><li>This environment <strong>mirrors the production environment</strong>.</li><li>Users perform User Acceptance Testing (UAT) in this environment to verify that the software works as expected, meets all their requirements, and can handle real-world tasks.</li></ul><p><strong>3. Deploy to Production environment:</strong></p><ul><li>After UAT approval, the software is released to the actual production environment for real users.</li></ul><p><strong>4. Final Validation / Smoke Testing:</strong></p><ul><li>A <strong>smoke test</strong> is a quick check to ensure the main functionalities of the software work correctly in production.</li><li>Example: Can users log in, access main features, and perform critical tasks?</li></ul><p><strong>5. Go Live:</strong></p><ul><li>Customers and users can now access and use the application fully.</li></ul><h3>Phase 7: Maintenance &amp; Support</h3><p>Even after the office is handed over, Archio doesn’t disappear.<br>They sign an <strong>Annual Maintenance Contract (AMC)</strong> with Dave, promising to keep the office in top condition.</p><p>A dedicated <strong>Archio Support Team</strong> including <strong>maintenance engineers and builders</strong> , regularly visits and monitors the building to make sure everything is running smoothly:</p><ul><li><strong>Repairs 🧱:</strong> If a wall develops cracks, the maintenance engineers spot the issue, log it, and forward it to the builders, who quickly fix it.</li><li><strong>Systems ⚙️:</strong> If the AC or lighting stops working, the team repairs or replaces the faulty systems.</li><li><strong>Upgrades 🔧:</strong> If Dave wants a new partition, extra conference room, or small extension, the builders plan and implement the upgrade.</li></ul><p>Every change is inspected again to make sure it still meets quality and safety standards.</p><p><strong>💻 Real-World SDLC:</strong></p><p>Just like Archio maintains Dave’s office, the <strong>Ops (Operations) Team</strong> and <strong>Developers</strong> maintain the software after it’s deployed.</p><ul><li><strong>Monitoring &amp; Issue Fixing 🔍:</strong> Ops team monitors logs, server health, and performance. If they find issues (like downtime or slow responses), they report them to developers, who fix them quickly.</li><li><strong>Bug Fixes 🐞:</strong> Developers patch software bugs as they’re discovered.</li><li><strong>Feature Enhancements ➕:</strong> When business owners request new features or small improvements, developers add them while ensuring the existing system keeps working properly.</li><li><strong>Security &amp; Updates 🔐:</strong> Regular updates are applied to keep the software secure, just like regular building inspections.</li></ul><p>This <strong>maintenance phase is ongoing</strong> for the entire life of the software until it’s retired or replaced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/1*9oCnWezdSjUMxLjgdtxJwQ.png" /></figure><h3><strong>💧 Waterfall Model in Software Engineering</strong></h3><h3>What is the Waterfall Model?</h3><p>No rocket science here 🚀 - the <strong>Waterfall Model</strong> is simply a <strong>step-by-step, sequential approach</strong> to software development.</p><p>The <strong>7 phases of the Waterfall model</strong> are:<br> <strong>1️⃣ Branstroming the idea → 2️⃣ Requirement Gathering &amp; Analysis → 3️⃣ Design &amp; Architecture → 4️⃣ Coding &amp; Implementation → 5️⃣ Testing &amp; QA → 6️⃣ Deployment → 7️⃣ Maintenance &amp; Feedback</strong></p><h3>Why is it called Waterfall?</h3><p>Think of pouring water from the top of a staircase. 🪜💦<br> It flows <strong>step by step</strong>, never skipping a stair.<br> Similarly, in the Waterfall model:<br> ✅ You must <strong>complete one phase</strong> before moving to the next<br> ✅ You <strong>cannot jump ahead</strong> or skip steps</p><h3><strong>Key Points of the Waterfall Model</strong></h3><ol><li><strong>Sequential Approach</strong></li></ol><ul><li>Each phase must be completed before the next begins.</li><li>Example: You can’t start development before finishing the design.</li></ul><p>2. <strong>Easy to Manage</strong></p><ul><li>Very straightforward — just finish one phase, then move to the next.</li><li>Good for projects with clear, fixed requirements.</li></ul><p><strong>3. Limited Flexibility</strong></p><ul><li>Changes are expensive and time-consuming.</li></ul><p><strong>Example 1:</strong></p><ul><li>Months later, the Business Owner adds a new requirement.</li><li>BA updates the SRS ➝ Architects update TDD ➝ Devs code ➝ Testers re-test.</li><li>You basically <strong>restart the process</strong>.</li></ul><p><strong>Example 2:</strong></p><ul><li>During Testing, you find a missing feature in the design.</li><li>You must go back ➝ update TDD ➝ redevelop ➝ retest ➝ redeploy.</li></ul><h3>⚠️ Challenges of the Waterfall Model</h3><ul><li><strong>Less Flexible - </strong>Hard to handle last-minute changes.</li><li><strong>Delayed Feedback - </strong>Business Owners/End Users only see the final product after all phases are done (e.g., 17 months later 😬).</li><li><strong>Long Delivery Cycles - </strong>Takes a lot of time to deliver working software.</li><li><strong>Difficult to Manage Uncertainties - </strong>If something goes wrong, you may need to redo multiple phases, which affects timelines.</li><li><strong>Limited Collaboration - </strong>Teams work in silos (BA → Dev → QA → Deployment), Communication happens mostly at handoff points, not continuously.</li></ul><p>Just like building Dave’s dream office, the Waterfall Model takes a structured, step-by-step approach where every phase builds on the previous one. It works best when requirements are clear from the start, giving teams a solid blueprint to follow. However, just as making last-minute changes to a building can be costly and time-consuming, the Waterfall approach can struggle with flexibility and delayed feedback. By understanding its strengths and limitations, software teams can use this model wisely or combine it with iterative methods to ensure projects are delivered efficiently, safely, and to the satisfaction of all stakeholders , just like handing over a perfectly built office.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2fd6f927f57" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Git — Your Best Friend in Version Controlling]]></title>
            <link>https://anjana-muthuanayake.medium.com/git-your-best-friend-in-version-controlling-9773b87c75a1?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9773b87c75a1</guid>
            <category><![CDATA[version-control-system]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Fri, 29 Aug 2025 20:54:04 GMT</pubDate>
            <atom:updated>2025-09-10T16:12:48.710Z</atom:updated>
            <content:encoded><![CDATA[<h3>Git — Your Best Friend in Version Controlling</h3><p><em>Remember a time when you were working on a college assignment. How did you do it?</em></p><ol><li>You opened Word or another editor.</li><li>You added your answers for the assignment.</li><li>When you felt you were done for the day, you saved your work.</li></ol><p><em>Let’s say you saved the document as </em><strong><em>“Assignment 1.docx.”</em></strong></p><p><em>The next day, you opened it again:</em></p><ul><li>You added new ideas.</li><li>You deleted parts that didn’t fit.</li><li>Then you saved it again,maybe this time as <strong>“Assignment 1-new.docx.”</strong></li></ul><p><em>This process repeated over several days, resulting in a pile of files like:</em></p><pre>Assignment 1.docx<br>Assignment 1-new.docx<br>Assignment 1-new2.docx<br>Assignment 1-final.docx<br>Assignment 1-lastfinal.docx</pre><p><em>All of these are updated versions of the same assignment. Some added new content, some removed old content, and some modified what was already there.</em></p><p><em>Now imagine this: when you’re about to finalize your assignment, you remember that a particular detail from one of the earlier versions would make your work better. But you can’t remember which file contains it. You open file after file, searching for the right piece of information. The assignment is long, and the process is tedious and frustrating.</em></p><p><em>Even worse, just by looking at these file names, can you tell exactly what changes were made in each version? Probably not. They’re just random names you made for convenience.</em></p><p><em>Think about this: How can you keep versions of your document organized? How can you quickly find what you’ve done without digging through countless files? Wouldn’t it be awesome to have a tool that handles this for you?</em></p><p><em>Here’s the good news: There’s a tool that can solve all these problems. It can:</em></p><ul><li>Keep track of every change you make.</li><li>Know exactly what was done and when.</li><li>Easily find any previous version without endless searching.</li></ul><p><em>Introducing </em><strong><em>Git-</em></strong><em>a powerful tool that acts like a personal assistant for version control. With Git, you can:</em></p><ul><li>Track changes to your documents and code.</li><li>View your project history with simple commands.</li><li>Revert to any previous version instantly.</li></ul><p><em>No more messy filenames, no more tedious searching, just clear and organized version control that makes your work easier and more efficient.</em></p><h3>Let’s dive into Git</h3><p><em>Imagine you’re developing a website. For the sake of simplicity, let’s say you’re creating an HTML file. You want to keep your workflow organized and track all the changes you make. So you decided to use git to manage your code properly.</em></p><p><em>To use git, first you need to install it.</em></p><p><em>Let’s see how to do it:</em></p><p><strong>You have to follow these steps to install git:</strong></p><ol><li>Open your web browser.</li><li>Search for <strong>“Download Git”</strong>.</li><li>Select the version suitable for your operating system.</li><li>Download the setup file.</li><li>Install it using the simple <strong>Next → Next → Finish</strong> process-no complicated configuration needed.</li></ol><p><strong>Now, let’s verify if we successfully installed git:</strong></p><ol><li>Open your terminal or command line interface.</li></ol><p>Run:</p><pre>git --version</pre><p><em>Now, if it displays the version of the git, you’ve successfully installed git.</em></p><p><em>Let’s look at an example output:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*cMXkfx9BNOQixY5-XUZ4bg.png" /><figcaption>git version</figcaption></figure><p><em>Now to track your code using git, you need to convert your normal project folder into a git repository.</em></p><p><strong>What is a Git Repository (Git Repo):</strong></p><p>It’s nothing but a storage space where git keeps all the versions of your code.</p><p><strong>Now, let’s convert your normal project folder into git repository:</strong></p><p>Here are the steps:</p><ol><li>Open your terminal.</li><li>Navigate to your project folder. (Let’s take your folder path as Desktop/my website)</li></ol><pre>cd Desktop/my website</pre><p>3. Type <em>“git init”</em>, This will initialize a Git Repo:</p><pre>git init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*qGfaA35aQ8J1gfDAPxH8MA.png" /><figcaption>Initialize a git repository</figcaption></figure><p>Voila! Now your normal project folder is converted into a git repository.</p><p>But.. what happened? Did you notice any visible change in your project folder?</p><p>Probably your answer will be <em>“No”</em></p><p>Let’s inspect our project folder:</p><ul><li><em>Let’s list the files and folders inside our project folder:</em></li></ul><ol><li>If you’re using Linux or Mac OS, type:</li></ol><pre>ls</pre><p>2. If you’re using windows, type:</p><pre>i. dir <br>    OR<br>ii. Get-ChildItem</pre><p>Output:</p><p>→ The output shows nothing.</p><ul><li>Now let’s inspect if there any hidden folders we missed, using “ls -a” command:</li></ul><ol><li>If you’re using Linux or Mac OS:</li></ol><pre>ls -a</pre><p>2. If you’re using windows:</p><pre>cmd → dir /a<br><br>PowerShell → ls -Force</pre><p>Ouput:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*4JYsA7zVJgulkrvyXEUkfA.png" /><figcaption>Hidden folder — .git</figcaption></figure><p>→ Now you can see there’s a new hidden folder created (.git folder) after we initialized git</p><p>Why is it there ?</p><ul><li>When you initialize a git repository, git will create a hidden folder called .git in your project folder.</li><li>This <strong>.git</strong> folder is the silent hero of your repository.</li><li>It quietly keeps track of every change you make, so you can focus on coding without worrying about losing any work.</li></ul><p>Now let’s make some changes in your project folder.</p><p>Then we can check how does git track those changes.</p><p>Let’s create index.html file and add some sample code into it.</p><ol><li>Create index.html file</li><li>Add the sample code as follows:</li></ol><pre>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;title&gt;My First Git Project&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>    &lt;h1&gt;Hello, Git!&lt;/h1&gt;<br>    &lt;p&gt;This is my very first file tracked by Git.&lt;/p&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><p>Now, it’s time to run `git status` command:</p><pre>git status</pre><p>When we run git status command, we’re simply asking Git;</p><pre>&quot;Hey Git, what’s going on in my repository right now?&quot;</pre><p>Then git replies us with some important things like:</p><ul><li>Which branch you are currently on.</li><li>Whether your branch is up-to-date with the remote branch (if any)</li><li>Which files are modified but not yet staged</li><li>Which files are staged and ready to commit</li><li>Any untracked files in the working directory</li></ul><p>Let’s run git status command within our repository:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/1*3TOfUjj60_cpAe5aCFpkWw.png" /><figcaption>git status</figcaption></figure><p>What does this mean?</p><p>👉 Git has <strong>noticed</strong> that you created a new file called index.html</p><p>👉 But right now, it’s in the <strong>untracked</strong> state,which means Git is not keeping an eye on its changes yet.<br> 👉 Git is basically saying:</p><pre>Hey, I can see a new file named index.html in the repository. <br>If you’d like me to start tracking it, please let me know by running `git add index.html`.</pre><p>As we want Git to track our files, we need to inform it by running git add command.</p><pre>git add index.html</pre><p>Now, let’s check if Git has started tracking our file by running git status command:</p><pre>git status</pre><p>Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*LI5yDRpwgchXix-s-5QBNg.png" /><figcaption>git status output</figcaption></figure><p>Now the ‘Untracked file’ status changed to ‘Changes to be comitted’</p><p>What does it mean:</p><p>When we run git add command, git starts tracking the changes in our files and places those files in a special area called staging area</p><p>What is staging :</p><p>Staging is like preparing a parcel before sending it;</p><ol><li>You add everything you want to send.</li><li>You wrap it carefully.</li><li>Now the parcel is ready to be delivered.</li></ol><p>Similarly, in Git:</p><ol><li>You add the files you want to track into the <strong>staging area</strong>.</li><li>Then, git started to track changes in these files.</li><li>Now the changes of those files are being tracked and they are ready to be permenantly saved in your repository.</li></ol><p><strong>Unstaging a File</strong></p><p>If you’ve added a file to the staging area but decide <strong>not to track it</strong>, Don’t worry, you can reverse the process using the command below:</p><pre>git rm --cached index.html</pre><p>This removes the file from the staging area but keeps it in your working directory.</p><p><strong>Ignoring Files You Never Want to Track</strong></p><p>Sometimes there are files or folders you <strong>never want Git to track.</strong></p><p>Why don’t you need them to be tracked:</p><ul><li>They contain sensitive information like passwords or keys</li><li>They are unnecessary to track</li></ul><pre>Ex: node_modules folder</pre><p>To ignore these files/folders, you can put them into .gitignore file.</p><p>Steps to create and use a .gitignore file:</p><ol><li>Create a file named .gitignore in your project folder.</li><li>Open it in any text editor.</li><li>Simply add the names of the files/folders you don’t need to track</li></ol><p>Examples:</p><pre>node_modules/<br>secret_config.txt</pre><p>Now, Git will <strong>ignore these files</strong> and won’t track them in your repository.</p><p><strong>Let’s save the tracked changes in our repository:</strong></p><p>To <strong>save the tracked changes permanently</strong> in our repository, we use <strong>commits</strong>.</p><p>What is a commit?</p><p>A commit is a snapshot of your files in the <strong>staging area</strong>. It allows you to save changes permanently in your Git repository.</p><p>When we make a commit, we save it with meaningful message describing what we did. → With this, we don’t need to remember what we’ve done.</p><p>How to make a commit:</p><ol><li>Run git status and check what changes are ready to be committed in the staging area.</li><li>Save your changes using below command:</li></ol><pre>git commit -m &quot;meaningful message&quot;</pre><p>Output of the command:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*S-uuZZUPPnqntGfRmNdvpQ.png" /><figcaption>git commit</figcaption></figure><p>Let’s understand this output:</p><pre>3b10b73 --&gt; Commit ID / commit hash (Actually this is abbreviated)<br>        --&gt; This is a unique identifier for each commit<br>        --&gt; We can re-access these commits using commit hashes.<br><br>1 file changed --&gt; We changed 1 file(index.html)<br><br>10 insertions --&gt; We added 10 lines to our index.html file<br><br>100644 --&gt; 100 - indicates a regular file<br>       --&gt; 644 - Represents the file permissions for the tracked file</pre><p>What is a Branch in Git?</p><p>Think of your project as a <strong>storybook</strong>:</p><ul><li>You have a <strong>main storyline</strong>, which is the original book.</li><li>You can also create <strong>side stories</strong> starting from a page in the main story.</li><li>These side stories are not yet a part of the main story, but if you feel like they’re good, you can merge them back into the main storyline.</li></ul><p>Same thing happens in git;</p><ul><li>You have main branch to keep the main code of your project.</li><li>This main branch is created automatically when you first initialized your git repository. So it’s the default branch of your git repo.</li><li>You can create <strong>feature or side branches</strong> from any commit in the main branch.</li><li>You can do experiments with these branches and those changes will not affect the main branch until you merge them to the main branch.</li></ul><p><strong>What is the HEAD in git?</strong></p><p>HEAD is like a <strong>bookmark in your book</strong>:</p><ul><li>It shows the page you are currently on.</li></ul><p>Same applies in git;</p><ul><li>HEAD shows <strong>where you currently are in your git repository</strong>.</li><li>Usually it points to the latest commit of the current branch you’re in.</li></ul><p>Technically:</p><ul><li>HEAD usually points to the <strong>current branch</strong>, and the branch points to the <strong>latest commit</strong>.</li><li>As you add new commits, the branch pointer moves forward, and HEAD moves along with it.</li><li>A branch in Git is just a pointer to a specific commit. As you add new commits, the branch pointer moves forward.</li></ul><p>Keeping track of HEAD is important so you know <strong>which commit or branch you are working on</strong> at any moment.</p><p>In Git, How to see what we did?</p><p>We can view the history of our works using git log command.</p><pre>git log</pre><p>Let’s look at sample output of git log command:</p><pre>commit a5593bd12c3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a<br>Author: John Doe &lt;john@example.com&gt;<br>Date:   Thu Aug 29 16:30:00 2025 +0530<br><br>    feat(nav): add Contact Page link to index.html<br><br>commit d84642e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7<br>Author: John Doe &lt;john@example.com&gt;<br>Date:   Wed Aug 28 14:45:00 2025 +0530<br><br>    feat(contact): add contact page with email and phone</pre><p>What are the details we can find from this output?</p><ul><li>Latest commit (git log command sorts the commits from latest to oldest)</li></ul><p>Let’s say we’ve done 4 commits A,B,C,D upto now, If we run git log command, output will be as follows;</p><pre>D<br>|<br>C<br>|<br>B<br>|<br>A</pre><p>Reason for this kind of output;</p><p>git log command displays the output from latest commit to oldest commit.</p><p>Other things it shows us with this commandL:</p><ul><li>commit hash (long version)</li><li>Who did the commit</li><li>When the commit was done</li><li>The commit message</li></ul><p>You can simply view one commit per one line using;</p><pre>git log --oneline</pre><p>Now you can see a simple output as below:</p><pre>a5593bd feat(nav): add Contact Page link to index.html<br>d84642e feat(contact): add contact page with email and phone<br>32c32ce Updated index.html, style.css and added screenshots folder</pre><p>If we need to develop a new feature starting from one of your old commit, first of all we need to take the commit hash for that particular commit using git log command.</p><p>Then we have to navigate to that commit using git checkout &lt;commit hash&gt; command.</p><p>Now, where is our HEAD? It is nowhere. What does that mean, It is floating. When you navigate to a commit, we call it ‘Detached HEAD’ mode.</p><p>If you’re in Detached HEAD mode, it’s useless to add commits. To add commits, we need to create a branch. There are several methods create and switch to a branch;</p><pre>git branch &lt;branch name&gt; --&gt; To create a branch</pre><p>Old methods;</p><pre>git chekout -b &lt;branch name&gt; --&gt; to create and switch to a new branch<br>git chechout &lt;branch name&gt;  --&gt; to switch to a branch</pre><p>Latest methods;</p><pre>git switch &lt;branch name&gt; --&gt; to switch to a branch</pre><p>To view created branches;</p><pre>git branch</pre><p>What does the output of git branch explains us:</p><pre>  feature<br>* main</pre><p>→ Asterisk (*) displays the current branch we’re in</p><p>Let me ask you a question, if you run git log command right after you created a branch, will it show you any output?</p><p>The answer is yes.</p><p>What is the reason?</p><pre>A --&gt; B --&gt; C --&gt; D --&gt; E<br>            |<br>            F                </pre><p>Look at above diagram. We have commits A,B,C,D &amp; E. We started a new branch(branch F) from commit C. No if we run git log command to see history of our commits, it’ll show us the commit history upto the commit we selected.</p><p>git log command output:</p><pre>C<br>|<br>B<br>|<br>A</pre><p>Reason for the output:</p><p>Because it shows us the commits from latest to oldest.</p><p>Let’s explore how to time travel with git:</p><ol><li>How to simply ‘undo’ in git:</li></ol><pre>git revert &lt;commit hash&gt; --&gt; you can simply undo what you did</pre><ul><li>When you run git revert it just creates a commit which undo the effect of the mentioned commit.</li><li>If that commit added a line → git revert remove that line</li><li>If that commit removed line → git revert add that line</li><li>This is preferred on shared projects, because it explains what happened, no surprise for team mates.</li></ul><p>2. How to remove what you did in git:</p><pre>git reset --hard &lt;commit hash&gt;</pre><ul><li>After running this command, all the commits happend after the mentioned commit are deleted.</li></ul><p>Before hard reset ( Imagine we have A,B,C,D,E commits)</p><pre>A --&gt; B --&gt; C --&gt; D --&gt; E</pre><pre>git reset --hard &lt;hash of commit C&gt;</pre><p>After hard reset (Now we have A,B,C commits only)</p><pre>A --&gt; B --&gt; C</pre><p>3. Soft reset:</p><ul><li>Using this method, you can go back and make changes.</li></ul><pre>git reset --soft &lt;commit hash&gt;</pre><p>Before soft reset; (We have A,B,C,D,E commits)</p><pre>A --&gt; B --&gt; C --&gt; D --&gt; E</pre><pre>git reset --soft &lt;commit hash of C&gt;</pre><pre>A --&gt; B --&gt; C &lt;--  Now HEAD is here, D &amp; E are aded to the staging area.</pre><p>Real world use cases of soft reset:</p><ul><li>To change previous commit messages</li><li>To combine commits manually</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*v9seBpcJzVJxsEjyw7dPEw.png" /></figure><p><em>Wrapping it up-Git is more than just a version control system. It’s like your project’s time machine, letting you revisit the past, experiment fearlessly, and collaborate without chaos. At first, the commands may feel tricky, but with practice, they’ll become second nature. What matters most is consistency: the more you use Git, the more natural it feels. So don’t be afraid to commit often, explore branches, and even make mistakes, because every step teaches you something new. With Git by your side, you’re never really stuck, you’re just one commit away from clarity.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9773b87c75a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How a Regular Server Becomes a Web Server with Nginx]]></title>
            <link>https://anjana-muthuanayake.medium.com/how-a-regular-server-becomes-a-web-server-with-nginx-195ca5e13e76?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/195ca5e13e76</guid>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Fri, 22 Aug 2025 20:43:09 GMT</pubDate>
            <atom:updated>2025-08-22T20:43:09.348Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine you have a computer. It’s sitting quietly somewhere, maybe in your home or in a cloud data center. It has all the hardware, the memory, the CPU, everything a computer needs. But here’s the thing: if you try to ask it, “Hey, can I see my website?” it will just stare at you. Blank screen. Confused.</p><p>That’s because <strong>a regular server is just… a server</strong>. It doesn’t know how to talk HTTP, it doesn’t know how to serve your HTML files, CSS, or images. It can’t “serve the world.”</p><p>Enter the <strong>magic</strong>: <strong>web server software</strong>.</p><h3>What is Web Server Software?</h3><p>Think of web server software like a <strong>friendly translator</strong>. It takes requests from the outside world, like someone typing your URL into a browser and translates them into something the server understands. Then it grabs the right files and sends them back.</p><p>In short: <strong>Web server software turns your regular server into a web server</strong>.</p><p>And one of the coolest, fastest, and most popular translators is <strong>Nginx</strong>.</p><h3>Why Nginx is Special</h3><p>Nginx (pronounced “engine-x”) isn’t just any web server software. It’s like a super-efficient post office. Here’s why it’s loved by the tech world:</p><ul><li><strong>Speed</strong>: Handles thousands of requests without breaking a sweat.</li><li><strong>Lightweight</strong>: Doesn’t consume huge amounts of memory.</li><li><strong>Reverse Proxy &amp; Load Balancing</strong>: Can distribute requests across multiple servers,perfect for scaling websites.</li><li><strong>Flexibility</strong>: Works on almost any OS, Linux, Windows, cloud environments like AWS, and even small VPS servers.</li></ul><p>Because of these powers, <strong>Nginx is everywhere, </strong>from small blogs to giant services like Netflix or Dropbox.</p><h3>How Nginx Turns a Server into a Web Server</h3><p>Here’s the magical process:</p><ol><li><strong>Install Nginx</strong><br> On Linux (Ubuntu/Debian):</li></ol><pre>sudo apt update </pre><pre>sudo apt install nginx</pre><p>On Red Hat/CentOS:</p><pre>sudo yum install nginx</pre><pre>sudo systemctl start nginx</pre><pre>sudo systemctl enable nginx</pre><p><strong>2. Nginx Configuration Files</strong></p><p>Nginx has a <strong>main configuration file</strong> (nginx.conf) and sometimes multiple <strong>site-specific configs</strong> (sites-available and sites-enabled).</p><p>Think of these files as the <strong>rulebook</strong>:</p><ul><li>Where should Nginx look for website files?</li><li>Which ports should it listen to (usually 80 for HTTP, 443 for HTTPS)?</li><li>How should it handle errors, redirects, or caching?</li></ul><p>A typical configuration snippet looks like this:</p><pre>server {<br>    listen 80;<br>    server_name example.com www.example.com;<br>    root /var/www/html;<br>    index index.html index.htm;<br>    location / {<br>        try_files $uri $uri/ =404;<br>    }<br>}</pre><h3>What You Need to Change</h3><p>To serve your website:</p><ol><li><strong>Set </strong><strong>root</strong> → This is the folder where your website files live.</li><li><strong>Set </strong><strong>server_name</strong> → Your domain or public IP.</li><li><strong>Restart Nginx</strong> → After making changes:</li></ol><pre>sudo systemctl restart nginx</pre><h3>Where to Put Your Website Files</h3><ul><li><strong>Linux</strong>: Usually /var/www/html for a simple website.</li><li><strong>Cloud servers (AWS EC2, etc.)</strong>: Same as Linux — but sometimes people create /home/ubuntu/mywebsite and point root there in Nginx config.</li><li><strong>Windows</strong>: Can put files anywhere; just update the root path in config.</li></ul><p>💡 Tip: The location can <strong>change from environment to environment</strong>, but as long as root in Nginx points to it, Nginx will serve your website.</p><h3>Why Nginx is Widely Used</h3><p>Imagine thousands of visitors hitting your site at the same time. A regular server will slow down or crash. Nginx? It just <strong>keeps delivering files</strong> efficiently.</p><ul><li>Lightweight → doesn’t hog resources</li><li>Handles many connections simultaneously</li><li>Supports HTTPS easily</li><li>Works as a reverse proxy, caching server, and load balancer</li></ul><p>In short: Nginx makes your website fast, secure, and reliable.</p><h3>The Big Picture</h3><p>Without Nginx or any web server software, your server is like a shop with no open sign, no door, and no way for people to come in. With Nginx, you:</p><ul><li>Open the door (port 80/443)</li><li>Put up the welcome sign (configuration)</li><li>Place your products (HTML, CSS, JS files)</li><li>Serve your visitors smoothly, even if hundreds arrive at once</li></ul><p>In essence: <strong>Nginx is the magic that transforms a quiet, lonely server into a world-facing, ready-to-serve web server.</strong></p><p>✨ Final Thoughts</p><p>Every website you visit almost certainly touches Nginx at some point. It’s fast, reliable, and flexible. Once you understand how it works, how to configure it, where to place your files, and why it’s so special, you realize Nginx isn’t just software. It’s the <strong>engine that powers the web quietly in the background</strong>, making sure every request finds its way home.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=195ca5e13e76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logging Into Remote Servers Made Simple: A Beginner’s SSH Guide]]></title>
            <link>https://anjana-muthuanayake.medium.com/logging-into-remote-servers-made-simple-a-beginners-ssh-guide-705df2380c1b?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/705df2380c1b</guid>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Fri, 22 Aug 2025 20:32:04 GMT</pubDate>
            <atom:updated>2025-08-22T20:32:04.626Z</atom:updated>
            <content:encoded><![CDATA[<h3>How to Log in to Remote Servers using SSH</h3><p>When we think about servers, most people imagine a big computer somewhere far away. But here’s the funny part, servers don’t usually come with monitors, keyboards, or mice. They’re designed to sit quietly in data centers, working behind the scenes. So how do we talk to them? How do we tell them what to do?</p><p>That’s where <strong>remote login</strong> comes in. And the tool that makes it all possible is something called <strong>SSH (Secure Shell)</strong>.</p><h3>Why SSH Matters</h3><p>Imagine you have a magic walkie-talkie that lets you whisper commands directly into a server’s ear, no matter how far away it is. SSH is that walkie-talkie, but way smarter and more secure.</p><p>Before SSH became the hero, people used things like <strong>telnet</strong> or password-only logins. The problem? Those methods sent everything in plain text, which meant hackers could just listen in on the conversation. It was like shouting your ATM PIN in a crowded bus. Not a good idea, right?</p><p>SSH solved that by wrapping everything in a strong <strong>encrypted tunnel</strong>. When you log in with SSH, your words (commands) are scrambled into secret code while traveling over the internet. Anyone who tries to peek in will see only nonsense. That’s why it’s trusted by sysadmins, cloud engineers, and basically anyone who works with servers.</p><h3>The Two Common Ways to Log In</h3><h3>1. Password-based login</h3><p>This one is simple: you type the username and password of the server. But… there’s a catch.</p><ul><li>Passwords can be guessed or stolen.</li><li>If attackers get even one weak password, they can break in.</li></ul><p>That’s why most companies <strong>disable password login</strong> for servers and prefer keys.</p><h3>2. Key-based login (with .pem or .ppk files)</h3><p>Here’s where things get interesting. Instead of typing a password every time, you use a special <strong>key pair</strong>.</p><ul><li>A .pem (Privacy Enhanced Mail) file is often used on Linux/macOS for SSH.</li><li>A .ppk (PuTTY Private Key) file is usually used on Windows with tools like PuTTY.</li></ul><p>Think of these keys as <strong>a special-shaped door key</strong>. Only the right key opens the server’s door. Without it, even if someone knows your username, they’re stuck outside.</p><p>Fun fact: AWS gives you a .pem file when you first create an EC2 server. That’s your “golden key” to enter your instance. If you lose it, you can’t reset that password.</p><h3>What Happens Behind the Scenes (The Cool Part 🤓)</h3><p>Here’s how I like to imagine the SSH process:</p><ol><li>You knock on the <strong>door of port 22</strong> on the remote server. (That’s the special door SSH always listens to.)</li><li>The server peeks out and says: <em>“Who are you? Show me proof.”</em></li><li>You present your key (or password).</li><li>If the key fits, the server opens a secret <strong>portal</strong> just for you.</li><li>This portal is encrypted, meaning even if someone is standing outside, they won’t see what’s happening inside. They’ll just see nonsense.</li></ol><p>From your side, it feels like you’re sitting <em>inside the server itself</em>. You type a command, and boom! it runs over there. It’s almost like teleporting your keyboard into a distant machine.</p><h3>How to Log In with SSH</h3><p>Depending on your operating system, the steps are a little different. Let’s break it down:</p><h3>1. Mac &amp; Linux OS</h3><p>Good news: SSH is built into your terminal! 🎉</p><p><strong>Steps:</strong></p><ol><li>Open your Terminal.</li><li>Navigate to the directory where your security key (.pem file) is located.</li></ol><pre>cd ~/Downloads</pre><p>3. Adjust permissions (Linux/Mac requires strict permissions for keys):</p><pre>chmod 400 key-pair.pem</pre><p>4. Run the SSH command:</p><pre>ssh -i &quot;key-pair.pe,&quot; ec2-user@&lt;pub</pre><p>5. Accept the fingerprint prompt → Boom, you’re inside your server.</p><h3>2. Windows OS (&lt;10) → Using PuTTY</h3><p>Older versions of Windows don’t come with SSH by default. For these, we use <strong>PuTTY</strong>, a free SSH client.</p><p><strong>Steps:</strong></p><ol><li>Download <strong>PuTTY</strong> and <strong>PuTTYgen</strong>.</li><li>Convert your .pem file into .ppk format using PuTTYgen:</li><li>Open PuTTYgen → Load .pem file → Save as .ppk .</li><li>Open PuTTY and enter:</li></ol><ul><li><strong>Host Name</strong>: ec2-user@&lt;public-ip&gt;</li><li><strong>Port</strong>: 22</li><li>Under <em>Connection → SSH → Auth</em>, browse and select your .ppk file.</li><li>Save the session and click <strong>Open</strong>.</li><li>Accept the warning → You’re logged in! 🎉</li></ul><p>💡 Tip: All Windows versions can use PuTTY, but it’s <strong>essential</strong> if you’re on Windows 7/8.</p><h3>3. Windows OS (≥10) → Using Built-in SSH</h3><p>From Windows 10 onward, SSH comes pre-installed in PowerShell and Command Prompt.</p><p><strong>Steps:</strong></p><ol><li>Open PowerShell or Command Prompt.</li><li>Navigate to the folder with your .pem file.</li></ol><pre>cd Desktop</pre><p>3. Run the SSH command:</p><pre>ssh -i &quot;key-pair.pem&quot; ec2-user@&lt;public-ip</pre><p>4. Accept the fingerprint prompt → and you’re inside the server 🚀</p><h3>Basic Things to Keep in Mind</h3><p>When logging into a remote server with SSH, here are the essentials:</p><p>* Be in the correct directory that has your key OR provide the full path.<br> * File names with spaces → wrap them in quotes (“my key.pem”).<br> * Set proper permissions (on Linux/Mac use chmod 400).<br> * Correct security group settings → your server must allow inbound SSH (port 22).</p><h3>Common Issues &amp; Quick Fixes</h3><p>SSH can sometimes feel tricky. Here are the usual suspects:</p><p>❌ <strong>Permission denied (publickey)</strong></p><ul><li>Wrong key file or wrong user.</li><li><strong>Fix</strong>: Double-check the key and use ec2-user for Amazon Linux.</li></ul><p>❌ <strong>Connection timed out</strong></p><ul><li>Likely a firewall or Security Group issue.</li><li><strong>Fix</strong>: Make sure port 22 (SSH) is open for your IP in AWS Security Groups.</li></ul><p>❌ <strong>Unprotected key file error (Linux/Mac)</strong></p><ul><li>Permissions too loose.</li><li><strong>Fix</strong>: Run chmod 400 key.pem.</li></ul><p>❌ <strong>Wrong directory / file not found</strong></p><ul><li>Your terminal isn’t in the right folder.</li><li><strong>Fix</strong>: cd into the directory with the .pem file OR give full path.</li></ul><h3>Why SSH is Widely Used and Trusted</h3><ul><li><strong>Encryption</strong>: Nobody outside can read your messages.</li><li><strong>Authentication</strong>: Keys are way harder to steal than passwords.</li><li><strong>Simplicity</strong>: One terminal window, and you’re in : no need for physical access.</li><li><strong>Universality</strong>: Every major OS and cloud provider supports SSH.</li></ul><p>In short: SSH is the silent hero of the internet. Without it, managing servers securely would be a nightmare.</p><h3>Final Thoughts</h3><p>If you ever spin up a cloud server, whether on AWS, Azure, or anywhere else, SSH is the bridge that connects you to it. Sometimes you’ll log in with a password (for testing), but in the real world, it’s all about .pem or .ppk keys.</p><p>So next time you type ssh user@serverip, remember:</p><ul><li>You’re knocking on port 22.</li><li>Your key is unlocking the door.</li><li>And you’re stepping into a secret, encrypted tunnel where only you and the server know what’s happening.</li></ul><p>That’s the magic of SSH.</p><p>✨ <em>Simple idea, powerful tool. Without SSH, servers would basically be locked black boxes. With SSH, you get the keys to the kingdom.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=705df2380c1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Dive into AWS Regions & AZs with a Pizza Analogy]]></title>
            <link>https://anjana-muthuanayake.medium.com/dive-into-aws-regions-azs-with-a-pizza-analogy-1e27a947c51c?source=rss-20a3d47e8fa6------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e27a947c51c</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws-region]]></category>
            <category><![CDATA[aws-availability-zones]]></category>
            <category><![CDATA[analogy]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Anjana Muthunayake]]></dc:creator>
            <pubDate>Tue, 17 Jun 2025 16:30:13 GMT</pubDate>
            <atom:updated>2025-06-17T17:55:35.458Z</atom:updated>
            <content:encoded><![CDATA[<p>As pizza is the <em>unofficial CEO of analogies</em> 🍕- simple, tasty and everyone gets it. Let me take you through a flavorful story to explain two core AWS concepts: <strong>Regions</strong> and <strong>Availability Zones (AZs)</strong>.</p><p>Let’s dig in!</p><p><strong>You and Your Favorite Pizza :</strong></p><ul><li>Imagine you are someone who loves to eat pizza.</li><li>Your favorite pizza brand is ‘Vito Pizza’.</li><li>You live in a large geographical state called ‘Cheeseland’.</li><li>Cheeseland has 3 main cities:</li></ul><ol><li>Sliceville</li><li>Crustown</li><li>Toppolis</li></ol><ul><li>Each city of Cheeseland state has 3 ‘Vito’ pizza outlets.</li><li>So every time you have a craving for your favorite pizza, you have to visit one of those pizza outlets and enjoy your pizza.</li><li>But over time, you decide to install the ‘Vito’ pizza delivery app and deliver your favorite pizza to your doorstep to make your life easier.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CpzE6NJfaXI8wrgOKdynWQ.jpeg" /><figcaption>Cheeseland and it’s cities</figcaption></figure><p><strong>Pizza Delivery App:</strong></p><ul><li>The name of the pizza delivery app is ‘Vito Delivery’ .</li><li>You installed the ‘Vito Delivery’ app to your phone.</li><li>Now whenever you have a craving for pizza:</li></ul><ol><li>You open the app</li><li>Select your favorite pizza</li><li>Select your favorite toppings on that pizza</li><li>Mention if you need extra cheese</li><li>Place your order</li><li>And after a while, a hot and tasty pizza will be delivered to your door</li></ol><p>But while you enjoy pizza on the couch, let’s peek behind the curtain at how Vito Pizza Company handles your order.</p><p><strong>Vito Pizza Company</strong></p><ul><li>When an order comes in via the app, Vito Pizza Company:</li></ul><ol><li>Identifies the city you’re in</li></ol><p>2. Picks a healthy outlet (one that isn’t overloaded or facing issues)</p><p>3. Routes your order to that outlet</p><p><strong>Vito pizza outlets</strong></p><ul><li>Vito pizza company maintains at least 2 pizza outlets in each city.</li><li>Each outlet has:</li></ul><ol><li>More than 2 ovens</li><li>Backup generators</li><li>Multiple Air Conditioners</li></ol><ul><li>These outlets are:<br> → Physically separate buildings<br> → 5–10 km apart.</li><li>Resilient enough that a fire or failure in one outlet doesn’t affect others</li></ul><p><strong>How Vito pizza’s management handle different failures</strong></p><ul><li>If one oven fails → another oven in the same outlet can take over</li><li>If one outlet fails → another outlet in the same city can take over</li><li>If one city fails → another city in the same state steps in</li><li>If the entire state fails → Vito routes orders to outlets in a different state</li></ul><p><strong>Cities &amp; States</strong></p><ul><li>Each city in Cheeseland is 50–100 km apart</li><li>states (like Cheeseland and neighboring states) are usually 300+ km apart.</li></ul><p><strong>Now let’s map this Vito pizza analogy to AWS cloud:</strong></p><ul><li>Vito Pizza Company → AWS</li><li>Vito Delivery App → AWS Management Console</li><li>Cheeseland (State) → AWS Region</li><li>Cities in Cheeseland → Availability Zones (AZs)</li><li>Pizza Outlets in a City → Data Centers in AZs</li><li>Ovens in Outlets → Servers in Data Centers</li><li>Pizzas → Cloud Services</li></ul><p>💻 <strong>AWS Management Console</strong></p><p>Just like you use the pizza app, when you want to use AWS services:</p><ul><li>You open the AWS Management Console</li><li>Select the service you want (EC2, S3, RDS, etc.)</li><li>Configure the options (e.g: CPU, memory, region)</li><li>Launch the service</li><li>Access it via the internet</li></ul><p>🌍<strong> AWS Regions</strong></p><ul><li>AWS Regions are large geographical areas, like states</li><li>Usually 300+ km apart</li><li>Each region has at least 3 Availability Zones (and sometimes up to 6)</li></ul><p>🧱 <strong>Availability Zones (AZs)</strong></p><ul><li>AZs are clusters of data centers within a Region</li><li>Each AZ is an isolated zone, but connected with other AZs in the same region</li><li>AZs are 50–100 km apart from each other.</li><li>They’re close enough for low-latency and far enough to protect from disasters</li></ul><p><strong>Data Centers in Availability Zones</strong></p><ul><li>AWS maintains at least 2 data centers in each AZ of a Region.</li><li>Each Datacenter has:</li></ul><ol><li>Redundant power supplies</li><li>Independent cooling systems</li></ol><ul><li>These Datacenters are:<br> →Physically separate buildings<br> → Located 5–10 km apart.</li></ul><p><strong>How Does AWS Handle Failures?</strong></p><p>Let’s break it down just like the pizza company:</p><ul><li>Single server fails → AWS shifts work to another server in the same data center</li><li>One data center fails → Other DCs in the same AZ take over</li><li>AZ fails (rare) → Other AZs in the region pick up the load</li><li>Region fails (super rare) → Another region steps in</li></ul><p><strong>Final Slice </strong>🍕</p><p>Just like Vito Pizza ensures your pizza is hot, fresh, and delivered — no matter what’s happening behind the scenes, AWS uses Regions and AZs to deliver cloud services that are highly available, reliable, and scalable.</p><p>📝 <em>This article reflects my understanding as I continue to learn cloud computing. I’ve tried to explain AWS Regions and Availability Zones through a pizza analogy to make it simple and memorable. If you find anything that can be improved or clarified, I’m always open to learning more!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e27a947c51c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>