<?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 Bello Afeez on Medium]]></title>
        <description><![CDATA[Stories by Bello Afeez on Medium]]></description>
        <link>https://medium.com/@werkjober?source=rss-eab516814854------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WUni_2VA0h2DVRQuZIfgQw.jpeg</url>
            <title>Stories by Bello Afeez on Medium</title>
            <link>https://medium.com/@werkjober?source=rss-eab516814854------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:16:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@werkjober/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[Upgrading Production RDS Databases with NO Downtime]]></title>
            <link>https://medium.com/@werkjober/upgrading-production-rds-databases-with-no-downtime-57a53958776d?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/57a53958776d</guid>
            <category><![CDATA[aws-rds]]></category>
            <category><![CDATA[blue-green-deployment]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[amazon]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Tue, 20 Oct 2026 15:45:29 GMT</pubDate>
            <atom:updated>2026-10-20T15:45:29.125Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>How We Upgraded 2 PostgreSQL RDS Databases With Almost No Downtime</em></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgPLCtvNkfI-WQjCjPkTjA.jpeg" /></figure><p>Two teams came to me with the same problem. Both had a production PostgreSQL database on RDS that needed to change. Neither could afford to take it down carelessly.</p><p>My team manages the infrastructure that every team in the company runs on. That is how these requests come up.</p><p>One team was running PostgreSQL 12, which had reached end of life (EOL). AWS was no longer patching it. We were paying for extended support just to keep it running, and that cost was not going away on its own. The fix was to move to a supported version. But this team could not accept <em>any</em> downtime. Not even a failover.</p><p>The other team ran ETL jobs. They had already made their changes in UAT: more storage, a few tuned parameters, but they did it by hand in the AWS console. Doing that in production meant 20 to 30 minutes of downtime, and their jobs would fail while they waited. They could live with 60 to 120 seconds. Not half an hour.</p><p>Same platform, same tooling, opposite constraints. So I used two different methods.</p><p>For the EOL database, the payment and order fulfilment service, <strong>I used Blue/Green deployment</strong>. A major version upgrade cannot be undone once it completes, and with zero downtime allowed, I needed a copy of production to upgrade and test before I switched over.</p><p>For the ETL database, <strong>I used a Multi-AZ reboot with failover</strong>. The change was parameters and an instance upsize, no schema change, no new engine version. I just needed a clean restart, and failover gave me a short, predictable one.</p><p>One upgrade needed a rehearsal. The other needed a fast, clean switch. This article walks through both what I planned, what the console actually showed, and what went wrong along the way.</p><h3>Section 1: The Multi-AZ Reboot</h3><h4>1. First, the Problem Underneath the Problem</h4><p>Before I could access the ETL database, I had to fix something unrelated to the upgrade.</p><p>I started with the Terraform code, because that is where any production change should begin. What I found was messy. The Terraform configuration pointed at the default postgres18 parameter group. But the actual production database was running on a custom parameter group called ***-*****-prod-20251207162338952800000003. That group had been created by hand in the AWS console. Terraform did not know it existed.</p><p>This is <strong>called drift</strong>. The code says one thing. AWS says another. Nobody wrote it down, so nobody noticed until I looked.</p><p>I ran a describe-db-parameters call against the live group to see what was actually set. The values did not match what we wanted. Several parameters were missing. work_mem was not set. random_page_cost was not set. shared_preload_libraries had only pg_stat_statements and pg_tleit was missing auto_explain. And shared_buffers was using a different formula than the one in UAT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkGnt-4e-5ApEkil2w0Ifw.png" /></figure><p>The drift was not only in production. UAT had the same problem. Someone had made the changes directly in the console there, and the Terraform code still pointed at the default group. Dev and test had a different issue: a stale variable in their tfvars file that no longer existed, which caused warnings on every plan.</p><p>I could not apply new parameters on top of a mess. If I did, I would lose track of what was actually running. So I fixed the drift first. That meant doing three things:</p><ol><li>Writing the parameter groups as real Terraform resources, with the correct values.</li><li>Updating the tfvars files in every environment so they pointed at those groups.</li><li>Wiring the module to stop creating its own groups and use the ones I defined.</li></ol><p>Once that was done, the plan was clean. Every environment matched. I could move on.</p><h4>2. Staging the Reboot So It Did Not Surprise Us</h4><p>Some parameters take effect immediately. Others only take effect after a reboot. In PostgreSQL, shared_buffers and shared_preload_libraries are static; the database has to restart before they apply.</p><p>That mattered a lot here. If I ran terraform apply and Terraform decided to reboot the instance on its own, I would lose control of the maintenance window. The ETL jobs would fail whenever the apply happened to run. That was exactly what we were trying to avoid.</p><p>So I set the parameter group to pending-reboot in Terraform. The change would be staged. Terraform would tell AWS &quot;apply this on the next reboot,&quot; but it would not trigger a reboot. That decision stayed with me.</p><p>This one detail changed the whole shape of the project. Instead of a dangerous apply, I had a staged change waiting for a window I controlled.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8YREnewg2v3IaR3CWr46w.png" /></figure><h4>3. The Scope Grew</h4><p>While I was preparing the parameter changes, the team asked for more.</p><p>They wanted the production instance upsized to match UAT. They wanted the replica to have a larger work_mem so heavy reporting queries would not spill to disk. And they wanted hot_standby_feedback turned on for the replica, so long-running read queries would not be cancelled during vacuum on the primary.</p><p>None of these were unreasonable. Each one made sense for their workload. But together, they meant a bigger apply and a longer window.</p><p>Here is what the upsizing looked like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*713Nwary0oDRjA2FWjdu_Q.png" /></figure><p>I bundled it all into one maintenance window. A single apply, a single reboot. Doing it twice would have meant two windows and two sets of risks for no real benefit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*MHhXxQMwPOfe0dSCdFnJHg.png" /></figure><h4>4. The Apply</h4><p>The apply ran through our GitLab CI pipeline as a manual job. That meant nobody could trigger it by accident. I had to click it myself, in the window, when I was ready.</p><p>The job created the new parameter groups, attached them to both the primary and the replica, and changed the instance class and storage. After it finished, both instances showed pending-reboot.</p><p>Nothing had rebooted yet. The database was still running on the old settings. I had staged everything, and now I could choose when to restart.</p><h4>5. The Failover</h4><p>The primary was a Multi-AZ instance. Its standby was in us-east-1b. That meant the reboot could be a failover reboot instead of a plain reboot.</p><p>This is worth explaining, because it is the reason the whole plan worked and because readers who do not already have Multi-AZ enabled need to know this step is not available to them yet.</p><h4><strong>If you do not already have Multi-AZ enabled</strong></h4><p>You cannot do a failover reboot on a Single-AZ instance. The --force-failover flag in the CLI will not work, and the console will not offer the option.</p><p>If your production instance is Single-AZ and you want this kind of short, predictable maintenance window, the first step is to convert the instance to a Multi-AZ DB instance deployment. When you modify a Single-AZ instance to Multi-AZ, RDS takes a snapshot of the primary’s EBS volumes, creates new volumes for the standby from that snapshot, and turns on synchronous block-level replication between the primary and standby. The standby initializes in the background while the instance returns to Available.</p><p>AWS recommends doing this conversion carefully. For production workloads, a safer path than converting the existing primary directly is to create a read replica, enable backups on it, convert that replica to Multi-AZ, and then promote it. But whether you convert in place or build a new standby, you need the standby in place before you can fail over to it.</p><p>You can enable or convert to Multi-AZ from the RDS console, the CLI (modify-db-instance), or the API (ModifyDBInstance). The console shows the standby&#39;s Availability Zone once it exists.</p><p>Further reading: <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZSingleStandby.html">Multi-AZ DB instance deployments for Amazon RDS</a> and <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZSingleStandby.html#Concepts.MultiAZConverting">Converting a DB instance to a Multi-AZ deployment</a>.</p><h4>What the failover actually does</h4><p>A normal reboot restarts the database in place. The instance is down; it comes back up on the same host, and the endpoint does not change. A reboot with failover does something different. AWS switches the primary to the standby first. The standby has already been patched and is ready. The DNS record for the endpoint flips to point at the new primary. The application reconnects to the same hostname, but it lands on a different physical instance.</p><p>That flip is not instant. AWS documentation puts typical failover time at 60–120 seconds, though large transactions or a lengthy recovery process can push it longer. The failover reason in the event log will show “The RDS instance was modified by customer” when the reboot is the trigger.</p><p>In our case, the Terraform apply changed the instance class. That modification required a reboot, and because the instance was already Multi-AZ, RDS performed the reboot with failover automatically. I did not have to trigger a separate manual failover after the apply.</p><p>I watched the Events tab while it ran. The status went from Available to Rebooting. The event log showed the failover starting, then completing. The instance came back in the other AZ. The endpoint had not changed.</p><p>The whole flip took about 40 seconds. The ETL jobs hit a brief connection error, but their retry logic caught it. Nobody had to intervene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*rIdYXemjXtvnEkzPSKjsnA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ARBbYRKg4TdTd06j7qVn-Q.png" /></figure><p>Further reading: <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.MultiAZ.Failover.html">Failing over a Multi-AZ DB instance for Amazon RDS</a> and <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_RebootInstance.html">Rebooting a DB instance</a>.</p><h4>6. The Replica</h4><p>The replica had to be rebooted separately. It could not fail over, because it is not a Multi-AZ primary. It is a read-only instance with no standby.</p><p>This was the easy part. The replica does not serve application traffic. It only serves reporting queries, and those can be retried. No team was waiting on it. No jobs would fail. So I rebooted it after the primary was confirmed healthy, and nobody noticed.</p><p>It came back with the new parameters work_mem at 256 MB, hot_standby_feedback on, and the same shared_preload_libraries as the primary.</p><p>Further reading: <a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html">Working with DB instance read replicas</a>.</p><h4>7. What the ETL Team Saw</h4><p>This is the part I am most proud of.</p><p>The ETL team had set their own maintenance window on their side 10 to 15 minutes just in case. They were prepared for a short outage. They had paused their jobs and told their stakeholders to expect a brief delay.</p><p>They did not need to.</p><p>The failover took about 40 seconds. Their jobs hit a brief connection error and recovered on their own. By the time their maintenance window ended, the database was already back up and running on the new instance class with the new parameters. They never noticed a thing.</p><h3>Section 2: Blue/Green on the EOL Database</h3><h4>8. Why This One Could Not Use the Same Method</h4><p>The payment and order fulfilment database was on PostgreSQL 12, which had reached EOL (End of Life). AWS was no longer issuing security patches for it. We were paying for extended support just to keep it running, and that cost was not going away on its own.</p><p>The fix was clear: upgrade to a supported version. What was not clear was <em>how</em>.</p><p>The ETL approach would not work here. A Multi-AZ failover reboot gives you a 60–120 second window where connections drop and writes fail. The ETL team could absorb that. The payment team could not. A dropped write on an order is a failed transaction, or an order that disappears from the fulfilment queue.</p><p>They needed zero downtime. Blue/Green was the only native RDS option that matched that constraint.</p><h4>9. The Prerequisite: Logical Replication Was Off</h4><p>Before you can create a Blue/Green deployment for PostgreSQL, the Blue instance needs logical replication enabled. AWS requires the instance to be associated with a custom parameter group where rds.logical_replication logical replication is turned on; this carries changes from Blue to Green. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-creating.html">Creating a blue/green deployment in Amazon RDS</a>)</p><p>I checked the parameter group. rds.logical_replication was set to 0.</p><p>So my first task was not the upgrade. It was enabling logical replication on Blue. I created a custom parameter group, set rds.logical_replication = 1, attached it to the Blue instance, and rebooted so the static parameter would take effect.</p><p>That reboot was the one unavoidable interruption in the project. It took about 30 seconds with failover.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IF-VP2KEhAsHZ8Ux_ttggA.png" /></figure><blockquote><strong>The first Blue/Green attempt failed</strong></blockquote><p>I created the deployment. It failed almost immediately with INVALID_CONFIGURATION. The replication parameters were too low for the number of databases on the instance.</p><p>AWS documents this exact failure. Blue/Green deployments need at least one background worker per database, so max_replication_slots, max_wal_senders, max_logical_replication_workers, and max_worker_processes all have to be sized for the number of databases on the instance. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-creating.html">Creating a blue/green deployment in Amazon RDS</a>)</p><p>A failed Blue/Green deployment cannot be retried. There is no resume operation. You delete the deployment and the Green instance, fix the parameters, and create a new one.</p><p>The delete had its own small trap: the Green instance had deletion protection on, so RDS refused to delete it. I had to turn deletion protection off on the Green instance only, delete the deployment with the Green target, and confirm the main Blue instance was untouched.</p><p>This is why I used a separate parameter group for the Green side. If I had reused the test copy’s group, fixing the replication settings would have put the test copy into pending-reboot and interrupted the dev team&#39;s testing.</p><h4>10. The Shared Instance Problem</h4><p>There was a second problem, and it was not an AWS problem. The team was using the same RDS instance for both dev and prod.</p><p>They wanted to upgrade dev first, confirm the application could read and write on the new version, and let QA validate it. But a Blue/Green environment is a read-only replica of Blue while it is being prepared. It has its own endpoint, but it is receiving replication from Blue. You cannot safely write to it, because those writes do not flow back to Blue. So Green could not serve as the dev test database. It was a rehearsal copy, not a sandbox.</p><p>To unblock the team, I took a snapshot of Blue and restored it as a new instance configured for PostgreSQL 17. Then I dropped the production database from that restored copy, because dev did not need production data for this test. I shared the new endpoint with the dev team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kFIEukUS0e-JrQBoYi0Kcw.png" /></figure><p>This gave the team what Blue/Green could not: a writable PostgreSQL 17 database they could test against before switchover.</p><h4>11. The SSL Surprise</h4><p>The dev team updated their application with the new endpoint and deployed. A few minutes later, they came back. The application could not connect.</p><p>The error was:</p><pre>FATAL: no pg_hba.conf entry for host &quot;...&quot;, user &quot;...&quot;, database &quot;...&quot;, SSL off</pre><p>I knew what it was immediately. The application was using node-postgres, and its connection logic did not include an sslmode setting.</p><p>PostgreSQL 12 allowed that. AWS states that rds.force_ssl defaults to 0 for PostgreSQL versions before 15, so SSL is optional on those versions. The application had never needed SSL, and nobody had noticed because the old database was permissive. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html">Using SSL with a PostgreSQL DB instance</a>)</p><p>PostgreSQL 15 and later default rds.force_ssl to 1. SSL is required, and an unencrypted connection is rejected with exactly that error. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Concepts.General.SSL.html">Using SSL with a PostgreSQL DB instance</a>)</p><p>We had two options:</p><ol><li>Set rds.force_ssl = 0 on the new PostgreSQL 17 parameter group. Dynamic parameter, no reboot. But this makes PostgreSQL 17 behave like the old PostgreSQL 12, and it removes encryption.</li><li>Fix the application to use SSL. For node-postgres, this means adding sslmode=require to the connection configuration. (<a href="https://node-postgres.com/features/ssl">node-postgres SSL documentation</a>)</li></ol><p>We chose the second option. Disabling SSL to accommodate an old application is a shortcut that becomes permanent.</p><p>I shared the AWS documentation on SSL and the node-postgres SSL page with the team. They updated their connection configuration, redeployed to dev, and the connection worked. QA validated, and everything passed.</p><h4>12. Creating the Green Environment, Second Attempt</h4><p>With the replication parameters fixed and dev testing unblocked, I created the Blue/Green deployment again, using the separate parameter group i***-*****-pg17-bg.</p><p>The Green instance was created from Blue, converted to Multi-AZ because Blue was Multi-AZ, upgraded to PostgreSQL 17.11, and started replicating. The deployment moved from PROVISIONING to AVAILABLE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-w1nQZW1EMfZIDuUyxxPA.png" /></figure><p>The build took longer than the first attempt because it had to do the actual work: restore, convert to Multi-AZ, upgrade the engine, and catch up replication. Blue/Green preparation is measured in hours, not minutes.</p><h4>13. The Guardrails and the DDL Freeze</h4><p>Before switchover, RDS runs guardrail checks. The most important PostgreSQL-specific guardrail is DDL.</p><p>AWS is explicit: DDL statements such as CREATE TABLE and CREATE SCHEMA are not replicated from the blue environment to the green environment. If RDS detects DDL on Blue, the green database enters a degraded replication state, and the only fix is to delete the deployment and all green databases, then recreate them. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">Blue/Green deployment limitations for RDS for PostgreSQL</a>)</p><p>That means the window between creating the deployment and switching over has to be a DDL freeze. No schema changes on Blue.</p><p>Other PostgreSQL limitations I checked before the window, all from the same AWS limitations page:</p><p>Limitation What it means: DDL is not replicated. Any schema change on Blue can break replication and force a redeployment. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">source</a>)DCL is not replicatedGRANT and REVOKE statements do not reach Green. You will see a warning if they are run on Blue. There is no configuration to change this. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">source</a>)Sequences are not synchronizedNEXTVAL operations are not replicated. During switchover, RDS increments Green&#39;s sequence values to match Blue. A very large number of sequences, such as several hundred thousand, can cause the switchover to time out. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">source</a>)Large objects are not replicated. Creation or modification of a large object in pg_largeobject can put Green into degraded replication and force a redeployment. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">source</a>)Materialized views are not refreshed. Refreshing a materialized view on Blue does not refresh it on Green. You have to refresh manually after switchover with REFRESH MATERIALIZED VIEW. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">source</a>)Tables without a primary keyUPDATE and DELETE are not permitted on tables without a primary key unless REPLICA IDENTITY FULL is set. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-considerations.html">source</a>)</p><p>I also monitored replication lag continuously in the days before switchover. A write burst on Blue can spike Green’s lag, and the guardrail will block the switchover if it is outside the limit.</p><h4>14. The Switchover</h4><p>The switchover timeout can be set between 30 seconds and 3,600 seconds (one hour). The default is 300 seconds. If the switchover exceeds the timeout, every change is rolled back and neither environment is modified. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-switching.html">Switching a blue/green deployment in Amazon RDS</a>)</p><p>I initiated the switchover from the deployment page: Actions → Switch over.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_pKjXKHY2pSe1U01PbBqtg.png" /></figure><p>Before the switchover, RDS runs guardrail checks on both environments. On Green, it checks replication health, replication lag, and active writes. On Blue, it checks external replication, long-running active writes, long-running DDL, and unsupported PostgreSQL changes. If any check fails, the switchover is blocked. (<a href="https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/blue-green-deployments-switching.html">Switching a blue/green deployment in Amazon RDS</a>)</p><p>Once the checks passed, RDS stopped new writes on both environments, dropped connections, waited for Green to catch up, renamed the instances so Green took Blue’s name and Blue got -old1, allowed connections again, and allowed writes on Green.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3UsHtPbcEAzmLCqhM5vD0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*itKOZJKD4Bpal_QjSIJ1ZA.png" /></figure><p>The switchover took about 2 seconds. The application reconnected to the same endpoint and resumed writing. No connection string changed. No deployment was needed.</p><p>That number is worth pausing on. Two seconds. The ETL upgrade needed a 90-second failover window. This one needed almost nothing, because the work had already been done on Green before the switch.</p><h4>15. What the Payment Team Saw</h4><p>Nothing.</p><p>There was no maintenance window on their side. No paused jobs. No retry logic triggered. The endpoint stayed the same, the connection pool reconnected, and writes resumed on PostgreSQL 17.</p><p>The only thing the team did on the day was <strong>push the </strong><strong>sslmode change to the production application</strong> before the switchover. That was deliberate. PostgreSQL 12 accepts <strong>connections with or without SSL</strong>, so the app could run the <strong>SSL-enabled config against the old database without breaking</strong>. Then, when we switched to PostgreSQL 17, which requires SSL, the application was already configured correctly. No window, no error, no failed connection at the worst possible moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*rGLSiMw2azHPVh79IgeRuA.png" /></figure><h3>Section 3: What Went Wrong</h3><p>Both upgrades completed without data loss and without an unplanned outage. Neither went exactly to plan. These are the moments that mattered.</p><p><strong>1. The drift was invisible until I looked.</strong></p><p>The parameter groups in production and UAT had been created by hand in the AWS console. Terraform was still pointing at the default postgres18 group. Nothing was broken, so nobody had checked. I found it because I read the code before touching production. If I had applied the new parameters on top of the drift, I would have lost track of what was actually running. The fix defining the groups in Terraform and cleaning up every environment took longer than the upgrade itself.</p><p><strong>2. The first Blue/Green deployment failed on creation.</strong></p><p>I set rds.logical_replication = 1 and created the deployment. It failed within minutes with INVALID_CONFIGURATION. The replication parameters were too low for the number of databases on the instance. A failed Blue/Green deployment cannot be resumed. I had to delete it and the Green instance, fix the parameters, and create a new one.</p><p>The delete had its own trap. The Green instance had deletion protection on, so RDS refused to delete it. Turning protection off on the Green instance only was the fix, but I had to be careful not to touch the main database.</p><p><strong>3. Dev and prod shared one instance.</strong></p><p>The team used the same RDS instance for both environments. That meant they could not test PostgreSQL 17 safely before the switchover. A Green environment is a read-only replica during preparation, so it cannot serve as a writable test database. I built a separate PostgreSQL 17 copy from Blue, dropped the production database from it, and gave the team that endpoint. Half the project’s complexity came from this one design choice.</p><p><strong>4. The application could not connect to PostgreSQL 17.</strong></p><p>The dev team deployed against the new copy and hit this:</p><pre>FATAL: no pg_hba.conf entry for host &quot;...&quot;, user &quot;...&quot;, database &quot;...&quot;, SSL off</pre><p>The app used node-postgres with no sslmode setting. PostgreSQL 12 allowed that because rds.force_ssl defaults to 0 on versions before 15. PostgreSQL 15 and later default it to 1, so unencrypted connections are rejected. The application had never needed SSL, and nobody had noticed because the old database was permissive.</p><p>We fixed it in the app, not the database. Setting rds.force_ssl = 0 on PostgreSQL 17 would have worked in minutes, but it would have made the shortcut permanent. The team added sslmode=require, redeployed, and QA passed.</p><p><strong>5. Logical replication does not carry DDL.</strong></p><p>Once the Blue/Green deployment existed, any schema change on Blue could have pushed Green into degraded replication and forced a full redeployment. We froze DDL for the whole preparation window. That freeze needs to be written down and owned by a named person, not agreed verbally.</p><h3>Section 4: How I Choose Between the Two</h3><p>The rule is simple. Match the method to the shape of the change, not to the tool you used last time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fGzwLRXWjTbJFnCAabR5MA.png" /></figure><p><strong>Use Multi-AZ failover when</strong> the change is restart-shaped: parameters, instance class, storage, minor version. It is fast, the endpoint does not change, and a team that can tolerate a short window will barely notice it.</p><p><strong>Use Blue/Green when</strong> the change is rehearsal-shaped: a major version upgrade, a schema change, or anything that cannot be undone once it runs. It is slower and more complex to prepare, but it gives you a synchronized copy of production to test against and a switchover that the application survives without a config change.</p><p><strong>Do not use Blue/Green to avoid a short outage</strong>. If the team can accept 60–120 seconds, the failover reboot is simpler, cheaper, and has fewer moving parts. Blue/Green earns its cost only when “zero downtime” is a real requirement.</p><p><strong>Fix the foundations before either one</strong>. Define your parameter groups in Terraform. Enable logical replication before you need it. Size your replication slots for the number of databases on the instance. Test SSL with the same driver your application uses. Separate dev and prod. Every hour spent on those before the window saved a day of firefighting during it.</p><p>Two databases, two methods, one lesson: the upgrade is easy when the preparation is honest.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57a53958776d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Self-Host n8n on AWS EC2 with SSL and Custom Domain (Free Tier Setup)]]></title>
            <link>https://medium.com/@werkjober/how-to-self-host-n8n-on-aws-ec2-with-ssl-and-custom-domain-free-tier-setup-afe60d62e420?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/afe60d62e420</guid>
            <category><![CDATA[n8n-workflow-automation]]></category>
            <category><![CDATA[n8n-self-host]]></category>
            <category><![CDATA[n8n-workflow]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Wed, 02 Jul 2025 18:15:21 GMT</pubDate>
            <atom:updated>2025-07-02T18:15:21.635Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tv0RnOjTlwnB6_O1HWLz7w.png" /></figure><h3>Introduction: Why Self-Host n8n on AWS EC2</h3><p><a href="https://n8n.io/">n8n</a> is an open-source workflow automation tool that lets you connect apps, APIs, and services with powerful logic and data transformations, all without writing much code. Whether you’re automating marketing tasks, syncing data across platforms, or building backend workflows, n8n offers the flexibility and control that make it a compelling alternative to tools like Zapier and Make.</p><p>While n8n Cloud is available as a hosted service, many developers and teams prefer <strong>self-hosting</strong> for better control, cost savings, and full data ownership. One of the most efficient ways to self-host n8n is on <strong>Amazon EC2</strong>, AWS’s scalable and flexible virtual server offering.</p><h3>💡 Why Not Use Hostinger or Shared Hosting?</h3><p>Shared hosting platforms like <strong>Hostinger</strong> might seem attractive due to low monthly pricing, but its is not as cheap as using AWS free tier for 12 months.</p><p><strong>AWS Free Tier</strong> gives you <strong>a full virtual server (EC2 t2.micro or t3.micro)</strong> free for <strong>12 months</strong>, with:</p><ul><li>Full root access</li><li>Ability to install Docker, run containers, and configure your environment exactly how you want</li><li>Enhanced security through private networking and security groups</li><li>Seamless integration with services like Route 53, S3, and IAM</li></ul><p>For the price of <strong>$0/month for the first year</strong>, AWS offers more flexibility and long-term scalability compared to shared hosting solutions.</p><h3>🔧 What You’ll Build in This Guide</h3><p>In this tutorial, you’ll learn how to <strong>deploy n8n on an Amazon EC2 instance (Amazon Linux 2023)</strong> using Docker. You’ll also:</p><ul><li>Allocate and attach a <strong>static (Elastic) IP</strong> to your EC2 instance</li><li>Set up a custom domain using <strong>Route 53 DNS</strong></li><li>Run n8n securely and efficiently using <strong>Docker Compose</strong></li></ul><p>By the end, you’ll have a fully self-hosted automation server accessible via your custom domain — scalable, secure, and ready for real-world use.</p><h3>Prerequisites</h3><p>Before we dive into launching servers and running containers, let’s make sure you have everything you need to follow along smoothly.</p><p>📌 1. AWS Account (Free Tier Eligible)<br>You’ll need an Amazon Web Services (AWS) account to launch the EC2 instance. If you’re new to AWS, sign up and activate the Free Tier, which includes:</p><ul><li>750 hours/month of t2.micro or t3.micro EC2 usage (enough to run 24/7 for a month)</li><li>Free DNS management via Route 53 (you pay only for domain name registration)</li></ul><p>💡 <em>Tip: Stick to t2.micro or t3.micro and regions with Free Tier support to avoid charges.</em></p><p>📌 2. A Domain Name<br>You’ll need a domain name to point to your n8n instance. You can:</p><p>Purchase a domain via Route 53 Or use a domain from another registrar (like Namecheap, GoDaddy, etc.), and update the nameservers to Route 53</p><p>📌 3. Basic Terminal Knowledge<br>This guide uses command-line tools extensively. You should be comfortable with:</p><ul><li>SSH (connecting to EC2 instances)</li><li>Running commands in Linux terminal</li><li>Editing files using nano or vi (or transferring configs via scp)</li></ul><p>📌 4. SSH Key Pair<br>During the EC2 setup, AWS will ask you to create or use an existing SSH key pair. This is necessary for securely accessing your server. If you don’t already have one, AWS will guide you through creating it.</p><h3>Launching the EC2 Instance (Amazon Linux 2023 + Static IP)</h3><p>In this step, you’ll launch an EC2 instance running <strong>Amazon Linux 2023</strong>, configure its security settings, and <strong>attach a static IP (Elastic IP)</strong>, which is crucial for associating your custom domain later.</p><h4>Step 1: Log in to AWS and Go to EC2 Dashboard</h4><ul><li>Visit <a href="https://console.aws.amazon.com/ec2/">https://console.aws.amazon.com/ec2/</a></li><li>In the left menu, click <strong>Instances &gt; Launch Instances</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRsEE3BiJ1quD5S8v6oN1w.png" /></figure><h4>Step 2: Configure Your Instance</h4><p><strong>1. Name</strong>:<br> Give your instance a name (e.g., n8n-server)</p><p><strong>2. Amazon Machine Image (AMI)</strong>:<br> Select <strong>Amazon Linux 2023 AMI (HVM), Kernel 6.x</strong></p><p><strong>3. Instance Type</strong>:<br> Choose t2.small or t3.micro (Free Tier eligible)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Fc_1W9f7LcCxFgh5HIUeA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6WpVIfLrWa7PHcLk3ONIzQ.png" /></figure><p><strong>4. Key Pair</strong>:<br> Choose an existing SSH key pair or create a new one</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jgr0gxu6hFYduTX4OVDcGA.png" /></figure><p><strong>5. Network Settings (Security Group)</strong>: Allow the following inbound rules:<br>- SSH (port 22) from your IP<br>- HTTP (port 80) from Anywhere (0.0.0.0/0)<br>- HTTPS (port 443) from Anywhere (0.0.0.0/0)</p><p><strong>6. Storage</strong>:<br> 8GB (default) is sufficient for basic n8n setup</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7HhpSR976QoEe3qndWhYg.png" /></figure><p><strong>7. Launch</strong> the instance</p><h3>Step 3: Allocate an Elastic IP (Static IP)</h3><p>To ensure your EC2 instance always has the same public IP (essential for domain mapping), we’ll allocate an Elastic IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tzbuQe9g9M8np0lGnGfJaQ.png" /></figure><ol><li>In the EC2 sidebar, go to <strong>Elastic IPs</strong></li><li>Click <strong>Allocate Elastic IP address</strong></li><li>Leave the default options and click <strong>Allocate</strong></li><li>After it’s allocated:</li></ol><ul><li>Select the Elastic IP</li><li>Click <strong>Actions &gt; Associate Elastic IP address</strong></li><li>Choose your EC2 instance under <strong>Instance</strong> and click <strong>Associate</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VneMiCCp8YkKjZCmxK8ezA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nw3R5gs0yles7Y8c758QAQ.png" /></figure><p>Now your instance has a static IP that won’t change, even if you stop/start it.</p><h3>Setting Up DNS with Route 53</h3><p>Now that your EC2 instance has a <strong>static IP</strong>, let’s configure a <strong>domain name</strong> so you can access n8n via a friendly URL like automation.yourdomain.com.</p><h4>Step 1: Open Route 53</h4><ol><li>Go to <a href="https://console.aws.amazon.com/route53/">AWS Route 53 Console</a></li><li>On the sidebar, click <strong>Hosted Zones</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E4ZJJXDj1NNliH4aL9QiCw.png" /></figure><h4>Step 2: Create a Hosted Zone (If You Don’t Have One)</h4><p>If you already have your domain set up in Route 53, skip to the next step.</p><ol><li>Click <strong>Create hosted zone</strong></li><li>Enter your domain name (e.g., yourdomain.com)</li><li>Set <strong>Type</strong> to “Public Hosted Zone”</li><li>Click <strong>Create hosted zone</strong></li></ol><blockquote>📝 If your domain is registered elsewhere (e.g., GoDaddy, Namecheap), you’ll need to copy the <strong>nameservers</strong> from the Hosted Zone and update them in your registrar’s settings. This may take a few minutes to propagate.</blockquote><h4>Step 3: Create a Record Set (A Record)</h4><p>Now we’ll point a subdomain (e.g., automation.yourdomain.com) or the root domain to your EC2’s static IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cPuKj-BGxN90XO9Jn31TXw.png" /></figure><ol><li>In your Hosted Zone, click <strong>Create record</strong></li><li>Configure the new record:</li></ol><ul><li><strong>Record name</strong>: e.g., automation (this will map to automation.yourdomain.com)</li><li><strong>Record type</strong>: A — IPv4 address</li><li><strong>Value</strong>: Your EC2 instance’s Elastic IP</li><li><strong>TTL</strong>: Leave default (e.g., 300)</li><li>Click <strong>Create records</strong></li></ul><p>You can also set up the root domain (@) if you&#39;d prefer using yourdomain.com directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0fvLpnky2LanlKAqthAxw.png" /></figure><h3>SSH into EC2 &amp; Install Docker + Docker Compose (Amazon Linux 2023)</h3><p>Now that your EC2 instance is running and connected to a static IP with a domain name mapped, it’s time to install the necessary tools: <strong>Docker</strong> and <strong>Docker Compose</strong>. These will allow us to easily run and manage n8n.</p><h4>Step 1: SSH into Your EC2 Instance</h4><p>From your local terminal, run:</p><pre>ssh -i /path/to/your-key.pem ec2-user@your-elastic-ip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKUxhfBai_EM5PP-2sMu6A.png" /></figure><p>Replace:</p><ul><li>/path/to/your-key.pem with your actual key path</li><li>your-elastic-ip with the public IP (or domain) of your instance</li></ul><p>You should now be logged into the EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8NhnzPc3iXn-v7fJbrNjbw.png" /></figure><h4>Step 2: Install Docker</h4><p>Amazon Linux 2023 uses dnf instead of yum.</p><p>Run the following commands:</p><pre>sudo dnf update -y<br>sudo dnf install -y docker<br>sudo systemctl enable docker<br>sudo systemctl start docker</pre><p>Verify Docker is working:</p><pre>docker version</pre><h4>Step 3: Add ec2-user to Docker Group</h4><p>This allows you to run Docker without using sudo every time:</p><pre>sudo usermod -aG docker ec2-user</pre><p>Log out and log back in for the group change to take effect:</p><p>Then reconnect:</p><pre>ssh -i /path/to/your-key.pem ec2-user@your-elastic-ip</pre><h4>Step 4: Install Docker Compose Plugin</h4><p>As of Docker 20.10+, Docker Compose is a plugin (not a separate binary). Use the following commands:</p><pre>sudo dnf install -y curl<br>sudo curl -L &quot;https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)&quot; -o /usr/local/bin/docker-compose<br>sudo chmod +x /usr/local/bin/docker-compose</pre><p>Test it:</p><pre>docker compose version</pre><p>You should see something like:</p><pre>Docker Compose version v2.27.1</pre><h3>Installing and Configuring n8n with Docker, NGINX, and SSL (Let’s Encrypt)</h3><p>Now that Docker and Docker Compose are installed, we’ll:</p><ol><li>Set up n8n using Docker Compose</li><li>Install <strong>NGINX</strong> as a reverse proxy</li><li>Use <strong>Certbot</strong> to enable <strong>free SSL (HTTPS)</strong> with Let’s Encrypt</li></ol><h4>Step 1: Install NGINX and Certbot</h4><pre>sudo dnf install -y nginx<br>sudo systemctl start nginx<br>sudo systemctl enable nginx<br>sudo dnf install -y certbot python3-certbot-nginx</pre><h4>Step 2: Set Up n8n with Docker Compose</h4><p>Create a new directory and Docker Compose file:</p><pre>mkdir ~/n8n<br>cd ~/n8n<br>nano docker-compose.yml</pre><p>Paste the following configuration into the file:</p><pre>version: &#39;3&#39;<br>services:<br>  n8n:<br>    image: n8nio/n8n<br>    restart: always<br>    ports:<br>      - &quot;5678:5678&quot;<br>    environment:<br>      - N8N_BASIC_AUTH_ACTIVE=true<br>      - N8N_BASIC_AUTH_USER=admin<br>      - N8N_BASIC_AUTH_PASSWORD=yourStrongPasswordHere<br>      - WEBHOOK_URL=https://yourwebsitedomain/<br>    volumes:<br>      - n8n_data:/home/node/.n8n<br>volumes:<br>  n8n_data:</pre><blockquote><em>🔐 Replace </em><em>yourStrongPasswordHere with a secure password, and </em><em>yourwebsitedomain with your actual domain (e.g., </em><em>automation.yourdomain.com)</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8KshfTBtLmnV4HP_wTyLBQ.png" /></figure><p>Save and exit:</p><ul><li>Ctrl + O, Enter, Ctrl + X</li></ul><p>Start the container:</p><pre>docker-compose up -d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Jpfw3SBsD6jAVf3bWiCJw.png" /></figure><h3>Step 3: Set Up NGINX Reverse Proxy</h3><p>Create an NGINX config file:</p><pre>sudo nano /etc/nginx/conf.d/n8n.conf</pre><p>Paste the following:</p><pre>server {<br>    listen 80;<br>    server_name yourwebsitedomain;<br><br>    location / {<br>        proxy_pass http://localhost:5678/;<br>        proxy_http_version 1.1;<br>        proxy_set_header Upgrade $http_upgrade;<br>        proxy_set_header Connection &quot;upgrade&quot;;<br>        proxy_set_header Host $host;<br>        proxy_set_header X-Real-IP $remote_addr;<br>        proxy_set_header X-Forwarded-Proto $scheme;<br>        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>    }<br>}</pre><blockquote><em>🔁 Replace </em><em>yourwebsitedomain with your actual domain.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i1OLllzIwQRYzRV8fKgosA.png" /></figure><p>Test NGINX config:</p><pre>sudo nginx -t</pre><p>Reload NGINX:</p><pre>sudo systemctl restart nginx</pre><h4>Step 4: Enable HTTPS with Certbot (Free SSL)</h4><p>Issue an SSL certificate:</p><pre>sudo certbot --nginx -d yourwebsitedomain</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pnh8fPIa8uCb1TL-ypLm2A.png" /></figure><p>Certbot will prompt you to:</p><ul><li>Enter your <strong>email address</strong></li><li>Agree to <strong>Let’s Encrypt’s Terms of Service</strong></li><li>Optionally share your email with the EFF</li></ul><p>Follow the prompts. After a few seconds, your SSL certificate will be installed and auto-renewed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Ch_Yb2ZxHs4XnNRT0YfdA.png" /></figure><h4>Final Restart to Apply Everything</h4><p>After enabling HTTPS, restart your services:</p><pre>cd ~/n8n<br>docker-compose down<br>docker-compose up -d<br>sudo systemctl restart nginx</pre><p>🎉 You should now be able to access your self-hosted n8n instance securely at:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cBhzUtFHNJpQLGeSIOdGZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EiHRZP02VfVxSGy2YVAapA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wraLgxCNqwhBE_ltyV4uKw.png" /></figure><h3>Conclusion: Your Self-Hosted n8n is Ready</h3><p>You’ve successfully set up a production-ready, self-hosted <a href="https://n8n.io/">n8n</a> instance on an <strong>Amazon EC2 (Amazon Linux 2023)</strong> server using <strong>Docker</strong>, <strong>NGINX</strong>, and <strong>Let’s Encrypt SSL</strong>. You now have full control over your automation workflows — hosted securely on your own domain and accessible via HTTPS.</p><p>This setup gives you:</p><ul><li><strong>Unlimited workflows</strong> and nodes (after activation)</li><li>Full <strong>data privacy</strong> and <strong>customizability</strong></li><li>Free hosting for 12 months using <strong>AWS Free Tier</strong></li><li>A clean, scalable setup ready to grow with your needs</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W-ROdExlqXjyQSrfO1_Ynw.png" /></figure><h3>Final Step: Activate Unlimited Workflows</h3><p>As of recent updates to the <strong>n8n Community Edition</strong>, you’ll be required to <strong>enter an activation key</strong> sent to your email after setup to unlock unlimited workflows.</p><p>Here’s how to activate:</p><ol><li>Open your n8n URL (e.g., <a href="https://yourdomain.com)/">https://yourdomain.com)</a></li><li>Sign in using your basic auth credentials (admin / your password)</li><li>n8n will prompt you to enter an <strong>activation key</strong></li><li>Check your email inbox for a message from n8n with the key</li><li>Paste it into the prompt — and that’s it!</li></ol><blockquote><em>🔓 After activation, your self-hosted n8n instance will run without limits.</em></blockquote><p>If you ever outgrow the Free Tier or need high availability, you can scale this setup using <strong>EC2 Autoscaling</strong>, <strong>Elastic Load Balancer</strong>, or even container orchestration with <strong>Amazon ECS or EKS</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afe60d62e420" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Setup Ansible Dynamic Inventory for AWS Autoscaling]]></title>
            <link>https://awstip.com/how-to-setup-ansible-dynamic-inventory-for-aws-autoscaling-6f4ce2fb790e?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f4ce2fb790e</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[aws-ec2]]></category>
            <category><![CDATA[ansible-playbook]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Sat, 29 Mar 2025 14:06:30 GMT</pubDate>
            <atom:updated>2025-04-02T16:36:07.730Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*AUnKeF9Y_ivmrK3E4avsWQ.png" /></figure><p>Managing cloud infrastructure efficiently is crucial for DevOps teams. Ansible, a powerful automation tool, simplifies configuration management, but static inventory files fall short in dynamic environments like AWS Auto Scaling Groups (ASGs).</p><p><strong>Ansible Dynamic Inventory</strong> — a solution that automatically discovers and manages AWS EC2 instances, ensuring your automation stays up-to-date as your infrastructure scales.</p><p>In this guide, you’ll learn:<br>✅ How AWS dynamic inventory works<br>✅ Setting up Ansible with AWS<br>✅ Configuring dynamic inventory for Auto Scaling Groups<br>✅ Best practices for reliable automation</p><h3>Why Use Dynamic Inventory?</h3><p>Static inventory files (hosts.ini) require manual updates—a nightmare for auto-scaling environments. <strong>Dynamic Inventory</strong> solves this by:</p><ul><li><strong>Automatically detecting new instances</strong></li><li><strong>Removing terminated instances</strong></li><li><strong>Grouping hosts by tags, regions, or ASGs</strong></li></ul><h3>🔹 Prerequisites</h3><p>Before starting, ensure you have:<br>✅ <strong>AWS Account</strong> with EC2 &amp; Auto Scaling access<br>✅ <strong>Ansible installed</strong> (pip install ansible boto3 botocore)<br>✅ <strong>IAM permissions</strong> for ec2:DescribeInstances and autoscaling:DescribeAutoScalingGroups</p><h3>1. Key Components I Provisioned:</h3><p>Terraform allowed me to define my entire cloud infrastructure in declarative configuration files, ensuring consistency and reproducibility.</p><p><strong>VPC &amp; Networking</strong>:</p><ul><li>Created a multi-AZ VPC with public and private subnets.</li><li>Configured route tables, NAT gateways, and security groups.</li></ul><p><strong>IAM &amp; Security</strong>:</p><ul><li>Defined least-privilege IAM roles for EC2 instances. ec2:DescribeInstances and autoscaling:DescribeAutoScalingGroups</li></ul><p><strong>Ansible Control Server</strong>:</p><ul><li>Deployed a dedicated EC2 instance to run Ansible playbooks.</li><li>Secured it in a public subnet with SSH access.</li></ul><p><strong>Autoscaling Group (ASG)</strong>:</p><ul><li>Defined a <strong>launch template</strong> with the base AMI and instance type.</li><li>Configured scaling policies based on CPU/memory usage.</li><li>Integrated with an <strong>Application Load Balancer (ALB)</strong> for traffic distribution.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O-Vfb4JZsAnPpz0MUUW5tg.png" /></figure><h3>2. Configuring the Ansible Control Server on Amazon Linux 2023</h3><p>After provisioning my Ansible server with Terraform, I needed to set up the automation tools. Here’s how I installed and configured Ansible to manage my AWS infrastructure:</p><h4>Step 1: SSH into the Ansible Server</h4><pre>ssh -i ~/.ssh/my-key.pem ec2-user@&lt;ansible-server-ip&gt;</pre><h4>Step 2: Install Python and Required Packages</h4><p>Amazon Linux 2023 comes with Python 3.9+ pre-installed, but we need pip:</p><pre>sudo dnf install python3-pip -y</pre><h4>Step 3: Install Ansible, Boto3, and Botocore</h4><pre>sudo pip3 install ansible boto3 botocore</pre><h4>Step 4: Verify the Installation</h4><pre>ansible --version<br>python3 -c &quot;import boto3; print(boto3.__version__)&quot;</pre><h4>Step 5: Configure AWS Credentials for Ansible</h4><p>I used IAM roles attached to the EC2 instance for secure access, but you can also configure credentials.</p><h3>3. Setting Up Dynamic Inventory &amp; Testing ASG Connectivity</h3><p>With my Ansible control node ready, I needed to ensure it could discover and communicate with instances in my private autoscaling group. Here’s how I implemented it:</p><h4>1. Ansible Configuration (ansible.cfg)</h4><p>I created /etc/ansible/ansible.cfg with these key settings:</p><pre>[defaults]<br>host_key_checking = False<br>private_key_file = /home/ec2-user/.ssh/client.pem<br>remote_user = ubuntu<br>enable_plugins = aws_ec2</pre><h4>2. Dynamic Inventory Setup</h4><p>Created my_inventory.aws_ec2.yml using the AWS EC2 plugin:</p><pre>plugin: amazon.aws.aws_ec2<br>strict: false # Prevents failure when no instances found<br>hostnames:<br>  - private-ip-address # Best for internal communication<br>regions:<br>  - us-east-1</pre><h4>3. Key Pair Preparation</h4><p>Since my ASG instances use a specific key pair:</p><pre># Copied the ASG&#39;s key pair to Ansible server<br>scp -i ~/.ssh/bastion-key.pem ~/.ssh/client.pem ec2-user@ansible-server:~/.ssh/<br>chmod 400 ~/.ssh/client.pem</pre><h4>4. Testing Connectivity</h4><p>Now let’s test the dynamic inventory configuration by listing the ec2 instances</p><pre>ansible-inventory -i my_inventory.aws_ec2.yml --list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tre8CHU_NfejI1bSyQEwkw.png" /></figure><p>The above command returns the list of ec2 instances with all its parameters in JSON format.</p><p>Execute the following command to test if Ansible is able to ping all the machines returned by the dynamic inventory.</p><pre>ansible all -m ping -i my_inventory.aws_ec2.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_HT0hkS09Wz-9mwlP2nKQ.png" /></figure><h3>4. Automating Web Server Deployment with Ansible on Autoscaling Instances</h3><p>Now that my Ansible control node was properly configured and could communicate with instances in my autoscaling group, it was time to automate the deployment of a complete web server solution. Here’s how I implemented this crucial piece of infrastructure automation.</p><h4>The Web Deployment Playbook</h4><p>I created an Ansible playbook deploy-static-website-cfg.ymlthat would:</p><ol><li>Install and configure Apache web server</li><li>Deploy a static website from GitHub</li><li>Ensure proper permissions and service management</li></ol><pre>- name: Install Apache using become<br>  hosts: all<br>  become: yes # Enable privilege escalation<br><br>  tasks:<br>    - name: Update the EC2 instance<br>      ansible.builtin.apt:<br>        name: &quot;*&quot;<br>        state: latest<br>        update_cache: yes<br><br>    - name: Ensure Apache is installed<br>      apt:<br>        name: apache2<br>        state: present<br><br>    - name: Ensure Unzip is installed<br>      apt:<br>        name: unzip<br>        state: present<br><br>    - name: change directory to the html directory<br>      shell: cd /var/www/html<br><br>    - name: Download Website Asset from Public Github Repo<br>      ansible.builtin.get_url:<br>        url: https://github.com/werkmanne/ovo-bicycle-website/archive/refs/heads/main.zip<br>        dest: /var/www/html/<br><br>    - name: Unzip the downlaoded website assets<br>      ansible.builtin.unarchive:<br>        src: /var/www/html/ovo-bicycle-website-main.zip<br>        dest: /var/www/html/<br>        remote_src: yes<br><br>    - name: copy all website files to /var/www/htm/ directory<br>      shell: cp -r /var/www/html/ovo-bicycle-website-main/* /var/www/html/<br><br>    - name: remove all unneccesary files from /var/www/htm/ directory<br>      shell: rm -rf /var/www/html/ovo-bicycle-website-main /var/www/html/ovo-bicycle-website-main.zip<br><br>    - name: Start service apache2, if not started and enable<br>      service:<br>        name: apache2<br>        state: started<br><br>    - name: Enable service apache2<br>      service:<br>        name: apache2<br>        enabled: yes</pre><h4>Executing the Ansible Playbook</h4><p>After carefully crafting my playbook and configuring dynamic inventory, it was time to put it to the test. I applied the configuration with:</p><pre>ansible-playbook static-website-cfg.yml -i my_inventory.aws_ec2.yml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0OBcI7pHAM31GrLOYcu5Aw.png" /></figure><p>After executing the playbook, I opened my browser and — <strong>wow!</strong> — there it was: my bicycle e-commerce website, perfectly deployed across all instances in my autoscaling group. The moment of truth had arrived, and the automation worked flawlessly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5O6BfsMjYOPedIgblBc0GQ.png" /></figure><h3>Conclusion</h3><p>The synergy between Ansible and AWS shown in this project isn’t just theoretical — it’s a proven pattern that delivers real business value. By embracing infrastructure as code and configuration management, organizations can achieve faster, more reliable deployments while significantly reducing operational overhead.</p><p><strong>Ready to automate your infrastructure?</strong> The tools are waiting, and the results speak for themselves. Your next deployment could be just one playbook away!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f4ce2fb790e" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/how-to-setup-ansible-dynamic-inventory-for-aws-autoscaling-6f4ce2fb790e">How to Setup Ansible Dynamic Inventory for AWS Autoscaling</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host A Dynamic Web App on AWS Elastic Kubernetes Service — EKS]]></title>
            <link>https://medium.com/@werkjober/host-a-dynamic-web-app-on-aws-elastic-kubernetes-service-eks-071ec7f1b164?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/071ec7f1b164</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Tue, 19 Nov 2024 16:43:46 GMT</pubDate>
            <atom:updated>2024-11-19T16:43:46.957Z</atom:updated>
            <content:encoded><![CDATA[<h3>Host A Dynamic Web App on AWS Elastic Kubernetes Service — <strong>EKS</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*PP7eg6XLA2rrpV2tqNc7PQ.png" /></figure><p>Greetings! Welcome back 😃. In the upcoming project, we’ll be focusing on delivering comprehensive tutorial for hosting a dynamic web application on AWS using Docker, Amazon ECR, and Amazon EKS. Throughout this blog, we’ll cover various essential steps, to help understand the end-to end deployment.</p><h3>Objectives</h3><ol><li>Introduction</li><li>Building a Three-Tier AWS Network VPC from Scratch</li><li>Creating NAT Gateways</li><li>Setting up Security Groups in AWS</li><li>Setting up a MySQL RDS Instance in AWS</li><li>Create EC2 Instance Connect Endpoint</li><li>Registering a New Domain Name in Route 53</li><li>Creating a Repository to Store the Application Codes</li><li>Adding the Application Code to the GitHub Repository</li><li>Creating a Repository to Store the Dockerfile</li><li>Creating a Personal Access Token</li><li>Adding Build Arguments and Environment Variables to a Dockerfile</li><li>Creating a Script to Build the Docker Image</li><li>Making Script Executable</li><li>Building the Docker Image</li><li>Installing the AWS Command Line CLI</li><li>Creating an IAM User with Programmatic Access</li><li>Running the AWS Configure Command</li><li>Creating a Repository in Amazon ECR with AWS CLI</li><li>Pushing the Docker Image to the Amazon ECR Repository</li><li>Migrate Database file (Rentzone MySQL)</li><li>Registering for an SSL Certificate in Amazon Certificate Manager</li><li>Create a Secrets in Secret Manager</li><li>Install kubectl, eksctl, and Helm</li><li>EKS Cluster IAM Role Creation</li><li>EKS Cluster Setup</li><li>Modify RDS Security Group</li><li>Worker Node IAM Role Creation</li><li>Worker Node Group Setup</li><li>Creating Kubernetes Manifests File</li><li>Kubernetes Manifests File Deployment</li><li>Adding TLS Listener for the Network Load Balancer</li><li>Creating a Record Set in Route 53</li><li>Cleaning Up Your EKS Project</li></ol><h3>Introduction</h3><p>This project focuses on transitioning the deployment of a LAMP stack application to a robust, Kubernetes-based architecture using AWS Elastic Kubernetes Service (EKS). By moving from a basic DockerHub-based containerization to a scalable and production-grade Kubernetes deployment, this project aims to harness the full potential of cloud-native application management.</p><p>The application will be deployed on a dedicated namespace called <strong>Rentzone</strong> within the EKS cluster, ensuring isolation and streamlined resource allocation. This architecture will enhance scalability, resilience, and security while leveraging the native integrations of AWS services.</p><p>AWS EKS provides a fully managed Kubernetes environment, enabling the team to focus on application development rather than infrastructure management. By utilizing Kubernetes features such as deployments, services, ConfigMaps, and persistent storage, this project ensures a production-ready setup that is optimized for both performance and maintainability.</p><h4>Let’s do this!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Khyyq7DTbjF9PqLf" /></figure><h3>2. Build a Three-Tier AWS Network VPC from Scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Nu1-JvHQPiE_k8-m.png" /></figure><ol><li><strong>VPC</strong> with public and private subnets in 2 availability zones</li><li>An <strong>internet gateway</strong> is used to allow communication between instances in VPC and the internet</li><li>We are using <strong>2 availability zones</strong> for high availability and fault tolerance</li><li>Resources such as NAT gateway, bastion host, and application load balancer use <strong>public subnets.</strong></li><li>We will put the web servers and database servers in the <strong>private subnets</strong> to protect them</li><li>The <strong>public route table</strong> is associated with the public subnets and routes traffic to the internet through the internet gateway</li><li>The <strong>main route table</strong> is associated with the private subnets</li></ol><p>For details on how to build a three-tier AWS network VPC from scratch, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%201%3A%20Build%20a%20Three%2DTier%20AWS%20Network%20VPC%20from%20Scratch"><strong>here</strong></a><strong> </strong>where I explained it thoroughly.</p><h3>3. Create Nat-gateway</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*nnDX82caPs4c3bBK.jpeg" /></figure><ol><li>The <strong>NAT Gateway</strong> allows the instances in the private app subnets and private data subnets to access the internet</li><li>The <strong>Private Route Table</strong> is associated with the private subnets and routes traffic to the internet through the NAT gateway.</li></ol><p>For details on how to create NAT Gateways, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%202%3A%20Create%20NAT%20Gateways"><strong>here</strong></a> where I explained it thoroughly.</p><h3>4. Create Security Groups in AWS</h3><p>We will create 3 security groups for this project.</p><p><strong>SSH Security Group — EICE</strong></p><ul><li>This is the security group that we will use to EICE to ssh into our EC2 instance in the private subnet</li><li>Port: Open outbound on 22 with Source: <strong>VPC cidr </strong>(10.0.0.0/16)</li></ul><p><strong>Database Migration Server Security Group</strong></p><ul><li>This is the security group that we will add to the server in the private app subnets</li><li>Port: 22 with Source: SSH Security Group <strong>— EICE</strong></li></ul><p><strong>Database Security Group</strong></p><ul><li>It will be attached to the RDS instance.</li><li>Ports are 3306</li><li>Type is MySQL/Aurora with <strong>Database Migration Server </strong>security group.</li></ul><p><strong>Note: <em>EKS Security Group will created automatically when creating the eks cluster.</em></strong></p><p>For details on how to create <strong>Security Groups</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%203%3A%20Create%20Security%20Groups"><strong>here</strong></a> where I explained it thoroughly.</p><h3>5. Set up MySQL RDS Instance in AWS</h3><p>We will create our database for this project in the private database subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ldBHHslu1ZaYgkVK.jpeg" /></figure><p>For details on how to create <strong>RDS Instance</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%204%3A%20Create%20the%20RDS%20Instance"><strong>here</strong></a> where I explained it thoroughly.</p><h3>6. Create EC2 Instance Connect Endpoint</h3><p>For details on how to create <strong>EC2 Instance Connect Endpoint</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%205%3A%20Create%20EC2%20Instance%20Connect%20Endpoint"><strong>here</strong></a> where I explained it thoroughly.</p><h3>7. Register a New Domain Name in Route 53</h3><p>For details on how to create <strong>New Domain Name in Route 53</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%2013%3A%20Register%20a%20New%20Domain%20Name%20in%20Route%2053"><strong>here</strong> </a>where I explained it thoroughly.</p><h3>8. Create Repository to Store the Application Codes</h3><p>We will create a repository to store our application code. We will then clone our repository on our computer.</p><h4>Create a GitHub Repository</h4><p>Create a GitHub repository to store your codes. Go to <strong>GitHub Homepage</strong> and <strong>select New.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Nusk_TY6ANFUSmzq.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9E4zXhjLBywVR_ak.png" /></figure><p>After creating the repository, go to SSH tab and click the copy icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*b-zk40OvcIdTDQSe.png" /></figure><p>Open your terminal in my case it’s Windows PowerShell.</p><blockquote>PowerShell always opens to your home directory. If you want to clone your repository in a different directory, first you need to change to that directory.</blockquote><p>To clone the repository we just created in this directory, run git clone &quot;url of the repository&quot; You can verify this by going to your file explorer and follow the path PS C:/Users/Dell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*me5PJkrhwXg_eUaK.png" /></figure><h3>9. Adding the Application Code to the GitHub Repository.</h3><p>We have created the repository where we will use to store our application code and we cloned that repository on our computer.</p><p>We will add our application code into that repository and we will push the changes back to GitHub. Take note of the 2 folder names because we will need them when we build our docker image.</p><p>We have a zip folder called rentzone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*VUN1eBH82MoX3Q5Y.png" /></figure><p>In the folder, we have the unzipped version which is also called rentzone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9tefv0fwS4hrCFSE.png" /></figure><p>Let’s go back to the zip folder and copy it. Go to the directory where we cloned our repository. Paste the application code here.</p><p>Let’s open that repository in visual studio code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*43DRuDzK2NLqGVtN.png" /></figure><p>Push this zip file into the repository in GitHub. We now have the rentzone.zip file in the application-codes repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y36URWJARg1XBC2z.png" /></figure><h3>10. Creating a Repository to Store the Dockerfile</h3><p>We will create another repository that we will use to store our Docker file. Afterwards, we will clone that repository on our computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/0*_JoX2D54WYrcRvDY.png" /></figure><p>Similar to the steps we did previously, create a new repository using your preferred repository name. In my case, docker-projects.</p><p>We’ve successfully created our repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m-mxjO3vyI6IHIzW.png" /></figure><p>Up next, follow the steps that we did previously to clone the repository on our computer.</p><h3>11. Creating a Personal Access Token</h3><p>We will create a personal access token and docker will use this to clone the application code repository where we’ll build our docker image.</p><p>In your GitHub account, go to profile, select settings then go to developer settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*oSBlgG0I_U5BWdOI.png" /></figure><p>Click on personal access tokens and select tokens (classic).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*x54icePAynFEJn15.png" /></figure><p>Click on generate new token then generate new token (classic). You may be asked to confirm access.</p><p>Provide your token name. Select an expiration date, select repo and click generate token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tnpgg7TWBpPy6buu.png" /></figure><p>We’ve successfully created a personal access token that docker will use to clone the application code’s repository.</p><p>Leave the page by clicking tokens (classic). You can view the personal access token we just created including its expiration date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nlPsAvhTegb3BYRr.png" /></figure><h3>12. Adding Build Arguments and Environment Variables to a Dockerfile</h3><p>We will learn how to properly pass secrets to our dockerfile. To start, create a Dockerfile in the rentzone folder. You can access the reference file I created and paste it here. You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Afterwards, save all your file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_kNJBmV4d0ZwmAW2.png" /></figure><p>This is the dockerfile that we will use to build our image. I added some build arguments (line 53 to 63). I also added some environment variables (line 65 to 75). Please don’t edit it yet.</p><h4>Build Arguments</h4><p>The build arguments allow us to build our image locally so that we can push it to amazon ECR. We created build arguments for all the values we don’t want to hard code in this Dockerfile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*UFhxw8pvGN9DOsH0.png" /></figure><p><strong>Environment Variables</strong></p><p>We set each build argument to an environment variable.</p><p>Here’s an example:</p><p>This build argument ARG PERSONAL_ACCESS_TOKEN is equivalent to this environment variable ENV PERSONAL_ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*ngwMV7gCWM41yfv7.png" /></figure><p>After we set each build argument to the environment variable, we can now use the environment variable in our Dockerfile instructions.</p><p>Here’s an example:</p><p>Note the instruction on line 78.</p><ol><li>Instead of hardcoding/entering our personal access token directly, we are now using the environment variable, personal access token.</li><li>Instead of hardcoding/entering our GitHub username directly, we are now using the environment variable, GitHub username.</li><li>Instead of hardcoding/entering our repository name directly, we are now using the environment variable, repository name.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/0*XROs43KOKq4n5A1z.png" /></figure><p>We pretty much did the same thing for all value we don’t want to hardcode on the Dockerfile.</p><p>This is how you can use build arguments and environment variables to pass secrets to a Dockerfile.</p><p>Let me explain about build arguments further.</p><p>Going back to line 78, before we can push our image to amazon ECR we need to build the image locally and when we do, docker still needs the information for our personal access token, GitHub username, and repository name to clone our repository.</p><p>If we don’t include these information when we build our image locally, the build is going to fail. So while you are building your image locally, the build argument allows you to specify the value of your personal access token, GitHub username, repository name, and all the other build arguments you have specified on the Dockerfile.</p><p><strong>Line 66</strong> — we set our build argument to the environment variable. So if I reference the build argument on line 78, that means it denotes environment variable.</p><p>Moreover, the values that we’ve specified for our build arguments while building our image locally, will be only be available to the Dockerfile during the build process and they will be not included in the final image that we built.</p><p>Let’s use the personal access token for example. When we specify the value of our personal access token while building our docker image locally, the value of the personal access token and other build arguments will only be available to help us build our image. Once we have built our image you will no longer see these values on the image we built. On the other hand, the environment variables will be available to the ECS containers we ran from the built image. When we create our task definition in ECS later on, the environment variables that we have set here, we will set the same environment variable in ECS and we’ll be able to add the actual values that we want.</p><p>This is how you use build arguments and environment variables to pass secrets to your Dockerfile. Please do not edit this file yet.</p><h3>13. Creating a Script to Build the Docker Image and creating a Git</h3><p>Now that we’ve created our Dockerfile, we’re going to write a simple script that we’ll use to build our docker image.</p><p>You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Use the build_image.ps1 if your using windows computer and use build_image.sh if you are using Mac.</p><p>In the rentzone folder, create a new file build_image.ps1. This is the name of our script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sExDOuGoCLS3VTIi.png" /></figure><p>In the build_image.ps1 reference file on GitHub, copy all the parameters and paste them here.</p><p>This is the PowerShell script that we will use to build our image and we only have one command — docker build. followed by our build arguments. For every build arguments we’ve listed in our Dockerfile, we need to enter the values here.</p><p><strong>Line 3</strong> — after the = add a ’ then provide your personal access token.</p><p><strong>Line 4 </strong>— after the = add a ’ then provide your GitHub username.</p><p><strong>Line 5</strong> — after the = add a ’ then provide your repository name, Application-Codes.</p><p><strong>Line 6 </strong>— the name of the zip folder that contains our application code, rentzone.zip. After the = add a ’ then enter rentzone.zip.</p><p><strong>Line 7</strong> — this is our web file unzip, after the = add a ’ then enter rentzone.</p><p><strong>Line 8</strong> — we registered a domain name earlier so after the = add a ’ then enter your domain name.</p><p><strong>Line 9 </strong>— after the = add a ’ then provide the RDS endpoint of your database instance. You can find this under the connectivity &amp; security tab of your RDS instance in your AWS account.</p><p><strong>Line 10 </strong>— after the = add a ’ then provide the RDS DB Name. You can find this under the configuration tab of your RDS instance in your AWS account.</p><p><strong>Line 11 </strong>— after the = add a ’ then provide your RDS master username. You can find this under the configuration tab of your RDS instance in your AWS account.</p><p><strong>Line 12 </strong>— after the = add a ’ then provide your RDS DB password.</p><p><strong>Line 13</strong> — this is the tag name that we want to give to our image. Since this application is called rentzone, I will tag this image rentzone. Replace the value &lt;image-tag&gt; with rentzone</p><p>This is all that we need to to create the script that we will use to build the docker image.</p><p>This is how our build_image.ps1 should look like. Go ahead and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VxKjT1dJBcE2ydhd.png" /></figure><p>Please remember that our script contains sensitive information such as our personal access token. We don’t want to commit this script to our GitHub repository so we need to add this to our <strong>.gitignore</strong> file.</p><p>To create a Gitignore file, right click on any open space below and type .gitignore you should see the Git logo beside it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/0*wjufu8afYNuqQtPz.png" /></figure><p>Next, we will add these script to our .gitignore file. Right click on the build_image.ps1 script and select rename so we can copy it.</p><p>Paste it in the .gitignore file</p><p>Let’s save it all again. Notice that our script is no longer tracked.</p><p>Go ahead and push our changes to our GitHub repository.</p><h3>14. Making Script Executable</h3><p>We will make the shell script file that we created previously (to build our docker image) executable. You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Use the commands.txt file.</p><p>If you are using a windows computer, you will run this command Set-ExecutionPolicy -ExecutionPolicy unrestricted in PowerShell as an administrator. If you are using a Mac computer, you will run this command chmod +x build_image.sh in the same directory your shell script file is located in.</p><p>To make the shell script file executable on your windows computer, run Set-ExecutionPolicy -ExecutionPolicy unrestricted in Power Shell. Enter Y after the confirmation message and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*BKw_9xeCfk4QWAA5.png" /></figure><p>Run PowerShell as an administrator</p><p>This is how you make a shell script file executable on a windows computer.</p><h3>15. Building the Docker Image</h3><p>Now that we have made the shell script file executable, we will run the shell script file to build our docker image. Right click on the shell script file (build_image.ps1) and select open in integrated terminal.</p><blockquote>When you right click on the shell script file and select open in integrated terminal, it is going to open the terminal in the same directory as the shell script file because in order to run the shell script file we need to be in the same directory.</blockquote><p>To run the shell script file to build our image run .\build_image.ps1 We are running the shell script file and it is now building the docker image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*flqvN2v2zZdWue4p.png" /></figure><p>We have successfully built the docker image. The blue output corresponds to each instructions on our Dockerfile. It also indicates that each instruction ran successfully when we built the docker image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hr0rBbMvLBe5XFqA.png" /></figure><p>To see the image run docker image ls and you will see the image that we just built. The tag we gave that image is rentzone. It has the image ID and created few minutes ago.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QE0Gihng0OA8ztP9.png" /></figure><p>This is how you use a shell script file to build a docker image. Up next, we will push the image we just built to Amazon ECR.</p><h3>15. Installing the AWS Command Line CLI</h3><p>We will install the AWS command line on our computer.</p><blockquote>For details on how to install the AWS command line on your windows computer, visit AWS documentation <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"><strong>here</strong></a><strong>.</strong></blockquote><h3>16. Creating an IAM User with Programmatic Access</h3><p>The next thing we will do is push the container image we created to the elastic container registry in our AWS account. The ECR in AWS is similar to docker hub. It is a service that allows you to store your container images in AWS. To push the images that we created to ECR, we will create an IAM user with programmatic access then we will use the AWS CLI, user’s access keys, and secret access keys to authenticate with AWS in order to push the container images to ECR.</p><h4>Create IAM User</h4><p>We are going to create an IAM user with programmatic access. Docker will use this IAM user’s credentials to push the images to AWS ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ExkAUtFCM0k0-hlr.png" /></figure><p>On the <strong>IAM dashboard</strong>, go to <strong>users then add users.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*X93NWPCau1yKZtZW.png" /></figure><p>Provide a <strong>name </strong>for your user and put a <strong>check </strong>beside <strong>Provide user access to the AWS Management Console.</strong></p><p>Let’s leave the rest of the settings on this page to <strong>default </strong>and click <strong>next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*5lw_KCWHN8pg6SFl.png" /></figure><p>Select <strong>Attach policies directly.</strong> Search and select administrator access in permissions policies and hit next. You can review the S<strong>ummary </strong>before <strong>Creating user.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lfvdqNdH3Q26ZOLF.png" /></figure><p>After you created your user, Goto to User you created, click on it and toggle <strong>Security Credentials</strong> to create and download the <strong>csv file containing the access key and password.</strong> This is the only time that your credentials can be viewed or downloaded. You cannot recover it later. <strong>Please keep them private and in a safe place</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-vs_PtkbFBrserz7.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*ppGoMnEOCCgjIEix.png" /></figure><p><strong>Create access key</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*68Fnv5OhDL3VgfDZ.png" /></figure><p>Select <strong>Third-party service,</strong> check <strong>I understand the above recommendation and want to proceed to create an access key and click next.</strong></p><h3>17. Running the AWS Configure Command</h3><p>We will configure the access key ID and secret access key on our computer. Configuring the user’s credentials on our computer will allow us to authenticate with our AWS account programmatically.</p><p>Open the command prompt and run aws configure Enter your AWS access key ID followed by secret access key ID and default region name, us-east-1. Press enter after default output format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/0*xUbeFQHy_QkHC-iY.png" /></figure><p>I’ve included the location of the user’s credentials on my computer. Whenever you want to update your user’s credentials, you can either type AWS configure on the command prompt and enter the user’s access key ID and secret access key or you can come directly to this file and change it here then save the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fMeGe-KGdhIdBTce.png" /></figure><p>This is how you configure your user’s credentials on your computer and we will use this user’s credentials to authenticate with our AWS account programatically.</p><h3>18. Create a Repository in Amazon ECR with AWS CLI</h3><p><strong>Amazon ECR to store the Docker image</strong></p><p>Now that we’ve installed AWS CLI on our computer and created a user with programmatic access, we will use the AWS CLI command to create a repository in amazon ECR. This is the repository that we will use to store the docker image we built earlier.</p><p>You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub and use the commands.txt file.</p><p>Paste this command in your notepad because we will modify it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*H2Ryl4_mGYPAetCe.png" /></figure><p>After updating our repository name and region where we want to create our repository in, our notepad should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*ED6wlLjozD4CqZVS.png" /></figure><p>This is the AWS CLI command that we will use to create a repository in amazon ECR. Select all the command and copy it. Open your project folder. Right click on any file in your rentzone project folder then select open in integrated terminal.</p><p>Paste the CLI command here then press enter. If you get this output, it means that you have successfully created the repository in ECR. Let’ go to our AWS account to verify if the rentzone repository we created is there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*r5l7G07KoneQWA8L.png" /></figure><p>There you have it, in the Amazon ECR dashboard under repositories, we have the rentzone repository we just created. Open it.</p><p>Up next, we will push the image we built previously into this repository.</p><h3>19. Pushing the Docker Image to the Amazon ECR Repository</h3><p>We will push our docker image to the amazon ECR repository that we created previously.</p><p>You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub and use the commands.txt file.</p><p>Paste this command in your notepad or text editor because we will modify it.</p><pre># retag docker image <br>docker tag &lt;image-tag&gt; &lt;repository-uri&gt;</pre><pre># login to ecr<br>aws ecr get-login-password | docker login --username AWS --password-stdin &lt;aws_account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com# push docker image to ecr repository <br>docker push &lt;repository-uri&gt;</pre><p># retag docker image</p><ul><li>Specify our <strong>image tag</strong> (you can run docker image on your project folder under Dockerfile to see the tag image).</li><li>You can get the URI of your rentzone repository in your AWS account</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*GCTK4ueU7FeGHodf.png" /></figure><p>Our first command should look like this. Open your terminal again under Dockerfile and run this command.</p><pre># retag docker image <br>docker tag rentzone ******.dkr.ecr.us-east-1.amazonaws.com/rentzone</pre><p>We have successfully retagged our image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*0WlShsjGBRGJMRvR.png" /></figure><p>If you run docker image ls again, you will see the image we just retagged. This is the image that we will push to our Amazon ECR repository.</p><p># login to ecr</p><p>To push this image to Amazon ECR, we will log back in to our Amazon ECR. Update your &lt;aws_account_id&gt; and the &lt;region&gt; where your repository is in. The second command should look like this.</p><pre>aws ecr get-login-password | docker login --username AWS --password-stdin *****.dkr.ecr.us-east-1.amazonaws.com</pre><p>Run this command in your project folder. If you get a <strong>Login Succeeded</strong> output that means we have successfully logged in to ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7D-yxDVDvj6UF9PT.png" /></figure><p>push the docker image to ecr repository</p><p>Now that we have successfully logged in to Amazon ECR, we’re going to run the third command to push the docker image to ECR repository.</p><p>Modify the repository URI and the full command should look like this.</p><pre># push docker image to ecr repository <br>docker push ******.dkr.ecr.us-east-1.amazonaws.com/rentzone</pre><p>Run this command in your project folder. We are now pushing the Docker image that we created to the Amazon ECR repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*iVAOIp5saVXx-PwP.png" /></figure><p>We’ve successfully pushed our Docker image into the Amazon ECR repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*iakjO17EnWfjYRBB.png" /></figure><p>Now let’s go to our Amazon ECR repository to verify if the Docker image is there.</p><p>There you have it, in the rentzone repository you can see the image we just pushed to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*swENBGhWJMtNmed4.png" /></figure><p>This is how we push a Docker image that we built locally on our computer into Amazon ECR repository. Up next, the ECS Fargate service will use this image to run our containers.</p><h3>20. Migrate Database file (Rentzone MySQL)</h3><p>For details on how to migrate your database file, from <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%208%3A%20Launch%20the%20Setup%20Server"><strong>here</strong></a> all the way to <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%2010%3A%20Use%20Flyway%20to%20migrate%20database%20into%20the%20RDS%20Instance"><strong>here</strong></a><strong>. </strong>Where I fully explained how to migrate your database via Flyway.</p><h3>21. Registering for an SSL Certificate in Amazon Certificate Manager</h3><p>We will register for a free SSL certificate from the AWS certificate manager. We will use this to encrypt the communications between the web browser and our web servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*FaMOvjlHTBDruZqr.png" /></figure><p>For our website above, the communication between the web browser and our website is not secure. We will use this SSL certificate to secure all communications between the web browser and our website — also referred to as encryption in transit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*79MzKVIXtvR5GwuM.png" /></figure><p>Go to <strong>AWS Certificate Manager</strong> and <strong>Request a certificate</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*QxdO6KrGcpI5_k8p.png" /></figure><p>Choose <strong>Request a public certificate</strong> under <strong>Certificate type</strong></p><p>Enter your <strong>domain name</strong> and click <strong>Add another name to this certificate</strong></p><p>In the second certificate box, we are going to add a wildcard. Type <strong>*.</strong> followed by your domain name. We will leave the rest to their default settings then click <strong>Request</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*4HRyUC3yemuxOR5i.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*0T55xmjcVa6TfScG.png" /></figure><p>Let’s <strong>View certificate</strong> after creating the request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*gBvMM2on0-o-m0t1.png" /></figure><p>If your status says <strong>Pending validation </strong>this means you need to create a record set in Route 53 to validate that this domain name belongs to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*AjKRFvTF6g9uUIn2.png" /></figure><p>You will see that the <strong>Status </strong>of the <strong>Certificate</strong> is <strong>Issued. </strong>For the 2 domain names we requested the certificate for is now showing <strong>Success.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*L8VhZ5sKy67bqpgE.png" /></figure><p>Good work! This is how you request a free certificate from <strong>AWS Certificate Manager.</strong></p><h3>22. Create a Secrets in Secret Manager</h3><h4>Adding Environment Variables as secrets to Secret Manager</h4><p>We will add the values for our Environment Variables as secrets in Secret Manager — the application running in the eks cluster will be able to make use of the secrets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pt5AmNwqh6MK5JUMuJLpyQ.png" /></figure><p>Let’s go to our AWS console. Go to AWS Secrets Manager and select <strong>Store a new secret</strong> and enter the following information:</p><p><strong>Step 1</strong></p><p>Secret type: Other type of secret</p><p>The Keys and you must provide your own values:</p><ol><li>PERSONAL_ACCESS_TOKEN</li><li>GITHUB_USERNAME</li><li>REPOSITORY_NAME</li><li>WEB_FILE_ZIP</li><li>WEB_FILE_UNZIP</li><li>DOMAIN_NAME</li><li>RDS_ENDPOINT</li><li>RDS_DB_NAME</li><li>RDS_MASTER_USERNAME</li><li>RDS_DB_PASSWORD</li></ol><p><strong>Step 1:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/0*28NdKIHHz67xyTru.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qn_CmLGJEhLfA8O0Z-tGgw.png" /></figure><p><strong>Step 2:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ay9Kp32Z_eMp14QhdyBzjw.png" /></figure><p>Provide your Secret name following the format above —<strong> rentzone-secret</strong></p><p><strong>Step 3:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/0*a6D2qZeI3LpDjHBQ.png" /></figure><p>Leave them to their default settings</p><p><strong>Step 4:</strong></p><p>Review the summary of settings then click <strong>Store</strong>.</p><p>We have successfully stored the secret <strong>rentzone-secrets.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgdQnKYq63Z6QrBScuQ2WA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WA4Z-iNSz9TbVX-6Ovij1Q.png" /></figure><p>When you go to your Secret name and click Retrieve secret value you will see the Secrets you currently have.</p><h4>Create Secret Manager Access Policy</h4><p>For eks to access the secrets in the secrets manager we are going to create a secret access policy. This IAM policy will allow the eks cluster to have access to the secrets and use it for the application running in the cluster.</p><p>Let’s go to our AWS console. Go to AWS IAM and select policies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JhMbuM1g6-jDtljQuo8Wuw.png" /></figure><p>Click on <strong>Create policy </strong>and in the service, type in and select <strong>secret manager.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P5TGJG98lZRYAU5NCsv4rw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qCTfEThpoGHsNvCKqdiDtg.png" /></figure><p>In the <strong>Policy Editor, </strong>go to<strong> action allowed</strong> and in the <strong>access level</strong> expand the<strong> Read. </strong>Tick<strong> DescribeSecret </strong>and<strong> GetSecretValue.</strong></p><p>This access level will allow allow the application running in the eks cluster have access to the secrets.</p><p>Next go to the <strong>resource section</strong> and add the <strong>arn </strong>of the <strong>rentzone-secret</strong> we created in secrets manager.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZftkx74kZHpTZT-cFUpsQ.png" /></figure><p>Copy the <strong>Secret ARN,</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SdsI7Yd3fpEoeGliPISPHQ.png" /></figure><p>Paste the ARN to the arn pop-up, its automatically pulls the <strong>resource region</strong> and <strong>resource ARN. </strong>Click <strong>add ARNs</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-vDs5ftNQAND3nblYz5qzw.png" /></figure><p>Click Next to move to the next page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kF3vpA1pwdo0uomWQNhGwg.png" /></figure><p>In Next page give the <strong>policy name</strong> and <strong>description, rentzone-secret-access-policy </strong>and save. It should see something similar to this screenshot below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3BOLWg0lmnEZfRzNCSR7Ag.png" /></figure><h3>23. Install kubectl, eksctl, and Helm</h3><p>To install <strong>kubectl</strong>, <strong>eksctl</strong>, and <strong>Helm</strong>, follow these step-by-step instructions:</p><h4>Install kubectl</h4><p><strong>kubectl</strong> is the Kubernetes command-line tool. It allows you to manage Kubernetes clusters.</p><h4>On Linux:</h4><pre>curl -LO &quot;https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl&quot;<br>chmod +x kubectl<br>sudo mv kubectl /usr/local/bin/<br>kubectl version --client</pre><h4>On macOS:</h4><pre>brew install kubectl<br>kubectl version --client</pre><h4>On Windows:</h4><p>Using Chocolatey:</p><pre>choco install kubernetes-cli<br>kubectl version --client</pre><h4>Install eksctl</h4><p><strong>eksctl</strong> is a CLI for Amazon EKS that simplifies cluster creation and management.</p><h4>On Linux:</h4><pre>curl -s --location &quot;https://github.com/weaveworks/eksctl/releases/download/$(curl -s https://api.github.com/repos/weaveworks/eksctl/releases/latest | grep tag_name | cut -d &#39;&quot;&#39; -f 4)/eksctl_$(uname -s)_amd64.tar.gz&quot; | tar xz -C /tmp<br>sudo mv /tmp/eksctl /usr/local/bin<br>eksctl version</pre><h4>On macOS:</h4><pre>brew tap weaveworks/tap<br>brew install weaveworks/tap/eksctl<br>eksctl version</pre><h4>On Windows:</h4><p>Using Chocolatey:</p><pre>choco install eksctl<br>eksctl version</pre><h4>Install Helm</h4><p><strong>Helm</strong> is a Kubernetes package manager that simplifies the deployment of applications.</p><h4>On Linux:</h4><pre>curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash<br>helm version</pre><h4>On macOS:</h4><pre>brew install helm<br>helm version</pre><h4>On Windows:</h4><p>Using Chocolatey:</p><pre>choco install kubernetes-helm<br>helm version</pre><h4>Verification Steps</h4><p>After installation, verify each tool by running:</p><pre>kubectl version --client<br>eksctl version<br>helm version</pre><p>This confirms all tools are correctly installed and operational. Let me know if you need help setting up or configuring any of them!</p><h3>24. EKS Cluster IAM Role Creation</h3><p>Let’s go to our AWS console. Go to AWS IAM and select Roles.</p><p>Included is the documentation page for the <a href="https://docs.aws.amazon.com/eks/latest/userguide/cluster-iam-role.html#create-service-role"><strong>Amazon EKS cluster IAM rol</strong></a><strong>e</strong></p><p><strong>Create a New Role</strong>:</p><ul><li>Select <strong>Roles</strong> &gt; <strong>Create Role</strong>.</li><li>Choose <strong>AWS Service</strong> as the trusted entity type.</li><li>Under “Use case,” select <strong>EKS</strong> &gt; <strong>EKS — Cluster</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*95uqMJsosavFoxOMft8B-A.png" /></figure><p><strong>Attach a Policy</strong>:</p><ul><li>AWS provides a managed policy for EKS clusters: <strong>AmazonEKSClusterPolicy</strong>.</li><li>Attach this policy to the role.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0WRph6HHo3hfPKKJxqzqQ.png" /></figure><p><strong>Set a Role Name</strong>:</p><ul><li>Assign a descriptive name, e.g.,rentzone-eks-cluster-role.</li></ul><p><strong>Create the Role</strong>:</p><ul><li>Review the configuration and create the role.</li></ul><h3>25. EKS Cluster Setup</h3><p>In AWS management console, type into the search console and go to AWS EKS.</p><h4>Configure the Cluster</h4><p><strong>Cluster Name:</strong></p><ul><li>Enter a unique name for your cluster, e.g., rentzone-cluster.</li></ul><p><strong>Kubernetes Version:</strong></p><ul><li>Choose the Kubernetes version for the cluster (e.g., 1.30).</li><li>Select the latest version for the newest features unless a specific version is required.</li></ul><p><strong>Cluster Service Role:</strong></p><ul><li>Select an existing IAM role we created rentzone-eks-cluster-rolewith the <strong>AmazonEKSClusterPolicy</strong> attached.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l9ZjrVJO7bft4wXAjBCY3w.png" /></figure><p><strong>Cluster Access:</strong></p><ul><li>In the Bootstrap Cluster Admin Access, select Allow Cluster Admin Access</li><li>In the Cluster authentication mode, select EKS API and Configmap</li></ul><p>For other setting on the page, leave it as default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmQzPx2RQdn0GAbgJi82vA.png" /></figure><p><strong>Networking:</strong></p><ul><li>VPC Configuration: Choose an existing VPC we created previously</li><li>Subnets: Select private app subnets we created previously in different availability zones for fault tolerance.</li><li>Security Groups: EKS will automatically create the need security group for the cluster</li></ul><p><strong>Cluster IP address family:</strong></p><ul><li>Select IPV4</li></ul><p><em>You configure the range from which cluster services will recieve IP addresses but i will leave it as default.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JQUanFWCUCxw8QpC73px0g.png" /></figure><p><strong>Cluster Endpoint Access:</strong></p><ul><li>Select Public and Private</li><li>In the advance settings add the source of public access endpoint and limit it to your own ip address.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wl6xv9yfSqROqx_vPwjPbQ.png" /></figure><p><strong>Configure Observability:</strong></p><p>Enable logging for monitoring purposes:</p><ul><li>Select all options <strong>api</strong>, <strong>audit</strong>, <strong>authenticator</strong>, <strong>controller manager</strong> and <strong>scheduler</strong> logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mm30T1MkJgnsgMJVfVOKog.png" /></figure><p><strong>Add-ons:</strong></p><p>Configure Kubernetes add-ons:</p><p>Leave the default selection and make sure you select the latest versions.</p><ol><li><strong>CoreDNS</strong>: Provides DNS-based service discovery within the cluster.</li><li><strong>kube-proxy</strong>: Manages network routing between pods and nodes.</li><li><strong>VPC CNI</strong>: Handles networking for pods in the cluster.</li><li><strong>Amazon EKS Pod Identity Agent</strong>: Use EKS Pod identity to grant AWS IAM permission to pods through kubernetes service account.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QcdxxM2c2e4_QkbwMgSgXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ni7i7Y3g0ExwaoLs76So5w.png" /></figure><p><strong>Review and Create:</strong></p><ol><li>Review the configuration settings.</li><li>Click <strong>Create</strong></li></ol><p><strong>Wait for Cluster Creation:</strong></p><ul><li>The cluster will take several minutes to create.</li><li>The status changes from <strong>Creating</strong> to <strong>Active</strong> once it’s ready.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sdEn2t1FxXUBIej0y3ugyA.png" /></figure><h3>26. Modify RDS Security Group</h3><p>Navigate to the security group to modify the Database Security Group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*msfGuWVAKBVo_D6-Cuy7Jg.png" /></figure><p>We are going to allow the <strong>EKS-Cluster-SG-Rentzone</strong> in the <strong>Database-SG. </strong>Click the <strong>Database-SG </strong>and edit the inbound rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BmnmgJ2SRzxiPYiPMw55Xg.png" /></figure><p>Select <strong>MYSQL/AURORA</strong> for the type and set the source to be from the <strong>EKS-Cluster-SG-Rentzone.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IAQD0DPG5x0PCVX37-PdBg.png" /></figure><p>Save the <strong>Rules.</strong></p><h3>27. Worker Node IAM Role Creation</h3><p>Let’s go back to AWS console. Go to AWS IAM and select Roles.</p><p>Included is the documentation page for the <a href="https://docs.aws.amazon.com/eks/latest/userguide/create-node-role.html#create-worker-node-role">Amazon EKS node IAM role</a></p><p><strong>Create a New Role</strong>:</p><ul><li>Select <strong>Roles</strong> &gt; <strong>Create Role</strong>.</li><li>Choose <strong>AWS Service</strong> as the trusted entity type.</li><li>Under “Use case,” select <strong>EC2</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nGqKXa-Wn3Zxoccq68zObA.png" /></figure><p><strong>Attach a Policy</strong>:</p><p>On the <strong>Add permissions</strong> page, attach a custom policy or do the following:</p><ul><li>In the <strong>Filter policies, </strong>search and select these policies</li></ul><p><strong>AmazonEKSWorkerNodePolicy</strong></p><p><strong>AmazonEC2ContainerRegistryPullOnly</strong></p><p><strong>AmazonEKS_CNI_Policy</strong></p><ul><li>Attach these policiecs to the role.</li></ul><p><strong>Set a Role Name</strong>:</p><ul><li>Assign a descriptive name, e.g.,rentzone-worker-node-role.</li></ul><p><strong>Create the Role</strong>:</p><ul><li>Review the configuration and create the role.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a94WB4YNfBQb9yvR2YrdKA.png" /></figure><h3>28. Worker Node Group Setup</h3><h4>Setup for Managed Node Groups</h4><p>In AWS management console, type into the search console and go to AWS EKS.</p><p>Navigate to the <strong>Amazon EKS Dashboard, </strong>Select your cluster and click <strong>Compute Tab</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AVZRONhBdRu2wjG_kMYdog.png" /></figure><p>In the Node group section, click on <strong>add node group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L6vXX268oNzfZ_Ir4nj5fQ.png" /></figure><p>Give the node group a name rentzone-worker-node, Select the existing worker node role we created rentzone-worker-node-role</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BrgmesFZV4NcsZonzoMpPg.png" /></figure><p>Leave the other section to default and move to the next page.</p><p><strong>AMI Type</strong>:</p><ul><li>Choose the Amazon Linux 2 AMI.</li></ul><p>Capacity Type:</p><ul><li>Choose the On-demand.</li></ul><p><strong>Instance Types</strong>:</p><ul><li>Choose the EC2 instance type, e.g., t3.medium</li></ul><p><strong>Disk Size:</strong></p><ul><li>Choose the default 20GiB.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wdaY0JU3iMdmB11fhsKNOw.png" /></figure><p><strong>Scaling Configuration</strong>:</p><ul><li>Specify the desired size — 1, minimum size — 1, and maximum number of nodes — 2.</li></ul><p><strong>Node Group Update Scaling Configuration</strong>:</p><ul><li>Choose the Number and add one to the value.</li></ul><p><strong>Networking</strong>:</p><ul><li>The subnets will be selected automatically since it recognizes the subnet where the EKS Cluster is created.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*24L-kn3yrx5RlVRsBHfKEQ.png" /></figure><p><strong>Launch the Node Group</strong></p><ul><li>Click <strong>Create</strong> to provision the managed node group.</li><li>AWS will automatically provision and manage the nodes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZLsjs_4k_j6LjZHKsfjGSQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mw9x7mjIRlmxvYbCn_nRdw.png" /></figure><h3>29. Creating Kubernetes Manifests File</h3><p>A Kubernetes manifest file is a YAML (or JSON) file that defines the desired state for Kubernetes objects, such as Pods, Deployments, Services, ConfigMaps, Secrets, and more. These files serve as the input to the Kubernetes API and specify how resources should be configured and managed.</p><p>For this project we are use 3 kubernetes manifest files.</p><p><strong>SecretProviderClass File</strong></p><p><strong>Deployments File</strong></p><p><strong>Service File</strong></p><ul><li><strong>SecretProviderClass File</strong></li></ul><p>The SecretProviderClass is a custom resource in Kubernetes used by the Secrets Store CSI (Container Storage Interface) Driver to integrate external secrets stores with Kubernetes pods. It defines the configuration for accessing secrets from external providers and specifies how these secrets should be presented within pods.</p><p>You can find the SecretProviderClass <a href="https://github.com/werkmanne/rentzone-kubernetes-deployment/blob/main/secret-provider-class.yaml">here</a>.</p><ul><li><strong>Deployments File</strong></li></ul><p>A Kubernetes Deployment tells Kubernetes how to create or modify instances of the pods that hold a containerized application. Deployments can help to efficiently scale the number of replica pods, enable the rollout of updated code in a controlled manner, or roll back to an earlier deployment version if necessary.</p><p>You can find the deployment file <a href="https://github.com/werkmanne/rentzone-kubernetes-deployment/blob/main/deployment.yaml">here</a>.</p><ul><li><strong>Service File</strong></li></ul><p>A Kubernetes service file is a YAML file that defines how a service should be configured in a Kubernetes cluster. The service is used to expose the application to other pods in the cluster or to external clients.</p><p>You can find the Service file <a href="https://github.com/werkmanne/rentzone-kubernetes-deployment/blob/main/service.yaml">here</a>.</p><h3>30. Kubernetes Manifests File Deployment</h3><p><strong>Step 1: </strong>Configuring kubectl for EKS</p><pre>REGION=&quot;**********&quot;<br>CLUSTER_NAME=&quot;rentzone-cluster&quot;<br>AWS_ACCOUNT_ID=&quot;***************&quot;</pre><p>Make sure you edit the above env to your AWS account details and paste into you terminal before running the following commands.</p><pre><br>aws eks --region $REGION update-kubeconfig --name $CLUSTER_NAME</pre><p>This command updates the kubeconfig file with the configuration necessary to connect to an AWS EKS cluster. After running this command, your kubectl will be configured to interact with the specified cluster in the region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O2dqsmdzFFbwTNgu_7Eh3Q.png" /></figure><pre>kubectl config get-contexts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jve4-gyMW5cD6FXdEkxLnQ.png" /></figure><p>This kubectl command lists all the contexts available in your kubeconfig file. A context in Kubernetes is essentially a combination of a cluster, a user, and a namespace. This command helps you see all the configured clusters you can connect to, including their associated users and namespaces.</p><pre>kubectl config use-context &quot;arn:aws:eks:$REGION:$AWS_ACCOUNT_ID:cluster/$CLUSTER_NAME&quot;</pre><p>This command sets the current context for kubectl to a specific EKS cluster. After running this command, all subsequent kubectl commands will be executed against the specified cluster in the region under the specified AWS account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iGiZVsK96229zMyKXMhS4Q.png" /></figure><p><strong>Step 2: </strong>Namespace Creation</p><pre>NAMESPACE=&quot;rentzone&quot;</pre><p>Paste into you terminal before running the following commands</p><p>Create a namespace.</p><pre>kubectl create namespace $NAMESPACE</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8PUXWy-8u9T-IxDXd47HXg.png" /></figure><p>Permanently save the namespace for all subsequent kubectl commands.</p><pre>kubectl config set-context - current - namespace=$NAMESPACE</pre><p>Verify the namespace.</p><pre>kubectl config view - minify | grep namespace:</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*37wjnnBv6Zcm1xyAoYmDEg.png" /></figure><p><strong>Step 3: </strong>Secrets Store CSI Driver Installation</p><pre>helm repo add secrets-store-csi-driver https://kubernetes-sigs.github.io/secrets-store-csi-driver/charts</pre><p>This command adds the ‘secrets-store-csi-driver’ Helm repository to your local Helm configuration. By adding this repository, you gain access to the charts it contains, including the Secrets Store CSI Driver.</p><pre>helm repo update</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2H9P8eT8dQAzUNJ-3u4kNQ.png" /></figure><p>This command updates the local list of charts from all the Helm chart repositories that have been added. When you add a repository to Helm (using ‘helm repo add’), Helm tracks the charts available in that repository. Running ‘<strong><em>helm repo update</em></strong>’ ensures that you have the latest information about charts available from each added repository. This is particularly important to do before installing or upgrading charts to ensure you are getting the latest versions.</p><pre>helm install csi-secrets-store secrets-store-csi-driver/secrets-store-csi-driver - namespace kube-system</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U0J81Akr5_A1CZfPVnGxKA.png" /></figure><p>This command uses Helm to install the Secrets Store CSI Driver into your Kubernetes cluster, specifically in the ‘kube-system’ namespace. The CSI (Container Storage Interface) Driver allows Kubernetes to interface with external secrets stores like AWS Secrets Manager, Azure Key Vault, etc. ‘<strong><em>csi-secrets-store</em></strong>’ is the name of the Helm release — a unique identifier for this particular deployment of the chart.</p><pre>kubectl --namespace=kube-system get pods -l &quot;app=secrets-store-csi-driver&quot;</pre><p>Verify that Secrets Store CSI Driver has started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*59BvhUYVLzanryvjJlPhXg.png" /></figure><pre>kubectl apply -f https://raw.githubusercontent.com/aws/secrets-store-csi-driver-provider-aws/main/deployment/aws-provider-installer.yaml</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xYEYXKzLYPzhxAhpMH9M-A.png" /></figure><p>This command applies a Kubernetes manifest file directly from a URL using ‘kubectl’. The manifest contains the necessary Kubernetes objects for setting up the AWS provider for the Secrets Store CSI Driver. This allows the CSI driver to interface with AWS Secrets Manager, enabling pods in your cluster to use secrets stored in AWS.</p><blockquote>Note: If you have an error applying <strong><em>aws-provider-installer.yaml, </em></strong><em>dowload the yaml file and apply from the local directory</em><strong><em>.</em></strong></blockquote><p><strong>Step 4: </strong>IAM OIDC Identity Provider Association</p><pre>REGION=&quot;*****&quot;<br>CLUSTER_NAME=&quot;rentzone-cluster&quot;</pre><p>Edit and paste into you terminal before running the following commands</p><pre>eksctl utils associate-iam-oidc-provider - region=$REGION - cluster=$CLUSTER_NAME - approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-E-Xl4tcHUeDUJQ4nYplg.png" /></figure><p>This command is used to associate an <strong>IAM OIDC (OpenID Connect)</strong> identity provider with an AWS EKS cluster using eksctl, a command-line tool for EKS. <strong>IAM OIDC identity providers</strong> allow for fine-grained IAM role-based access control for applications running in EKS, using Kubernetes service accounts. Run only once on the cluster.</p><p><strong>Step 5: </strong>Creating AWS IAM Service Account</p><pre>SERVICE_ACCOUNT_NAME=&quot;rentzone-service-account&quot;<br>NAMESPACE=&quot;rentzone&quot;<br>REGION=&quot;******&quot;<br>CLUSTER_NAME=&quot;rentzone-cluster&quot;<br>AWS_ACCOUNT_ID=&quot;********&quot;<br>SECRET_MANAGER_ACCESS_POLICY_NAME=&quot;&lt;name of the secret policy we created previously&gt;&quot;</pre><p>Edit and paste into you terminal before running the following commands</p><pre>eksctl create iamserviceaccount \<br>    --name $SERVICE_ACCOUNT_NAME \<br>    --namespace $NAMESPACE \<br>    --region $REGION \<br>    --cluster $CLUSTER_NAME \<br>    --attach-policy-arn &quot;arn:aws:iam::$AWS_ACCOUNT_ID:policy/$SECRET_MANAGER_ACCESS_POLICY_NAME&quot; \<br>    --approve \<br>    --override-existing-serviceaccounts</pre><p>This command creates a new IAM service account in AWS, specifically for use with an EKS (Elastic Kubernetes Service) cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eZRPdJliu0xDiMcWD0S9dA.png" /></figure><p><strong>Step 6: </strong>Applying SecretProviderClass in EKS</p><pre>apiVersion: secrets-store.csi.x-k8s.io/v1<br>kind: SecretProviderClass<br>metadata:<br>  name: rentzone-secret<br>  namespace: rentzone<br>spec:<br>  provider: aws<br>  parameters:<br>    objects: |<br>        - objectName: &quot;arn:aws:secretsmanager:&lt;region&gt;:&lt;account-id&gt;:secret:rentzone-secret-&lt;random-key&gt;&quot;<br>          objectAlias: &quot;app-secret&quot;</pre><p>Add your <strong>region</strong>, <strong>account-id</strong> and <strong>random-key</strong>.</p><pre>SECRET_PROVIDER_CLASS_FILE_NAME=&quot;secret-provider-class.yaml&quot;</pre><p>This command apply the secret-provider-class configuration to a Kubernetes cluster.</p><pre>kubectl apply -f $SECRET_PROVIDER_CLASS_FILE_NAME</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kkFZCSuPZmoN5KG3nPFJ_w.png" /></figure><p><strong>Step 7: </strong>Applying Deployment file in EKS</p><pre>DEPLOYMENT_FILE_NAME=&quot;deployment.yaml&quot;</pre><p>This command apply the ‘deployment.yaml’ file to create or update resources in your Kubernetes cluster.</p><pre>kubectl apply -f $DEPLOYMENT_FILE_NAME</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-g6FHSdN2n-tTOjMUsRYbA.png" /></figure><p><strong>Step 8: </strong>Applying Service file in EKS</p><pre>SERVICE_FILE_NAME=&quot;service.yaml&quot;</pre><p>This command apply the <strong>‘service.yaml’</strong> file to expose the application running in your Kubernetes cluster. The <strong>‘service.yaml’</strong> creates a network load balancer in the AWS Management console.</p><pre>kubectl apply -f $SERVICE_FILE_NAME</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXgSlIHmFEuKUn3OeBw9YQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G1PZr4zS2fY554iRBCIegw.png" /></figure><h3>31. Adding TLS Listener for the Network Load Balancer</h3><p>We’re going to create an TLS listener for our NLB to secure our website. Let’s go to the <strong>EC2 dashboard</strong> and head over to <strong>Load balancer</strong></p><p>Ensure that your load balancer name is selected then click the <strong>Listener</strong> tab then Click <strong>Add listener</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5mldsTkocpzesGsus2UfDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mmXXw2toOWgCGlU_pTK0fQ.png" /></figure><p>Switch the protocol to <strong>TLS </strong>this is always on port <strong>443, </strong>Select <strong>Forward </strong>under <strong>Default actions </strong>and<strong> Target group</strong> will be <strong>K8s-rentzone-rentzone</strong></p><p>Select your <strong>Default SSL/TLS certificate</strong> and click <strong>Add </strong>at the bottom right part of your screen.</p><p>The HTTPS listener is added. Let’s delete the HTTP listener</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gIcgFDaaX5jVe5JPPpKFTA.png" /></figure><p>We have successfully deleted our HTTP listener to direct traffic to TLS.</p><h3>32. Create a Record Set in Route 53</h3><p>We will create a record set in Route 53 to access our website using our domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*COIP4eR2PiC1Jq47.png" /></figure><p>To create a record set in Route 53, go to the <strong>Route 53</strong> dashboard. Select <strong>Hosted zones </strong>and click your <strong>Domain</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*RyOOTuybFMFswpUh.png" /></figure><p>Click <strong>Create record</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7JEenP3mueYQcSwi.png" /></figure><p>Enter the information below then hit <strong>Create records</strong></p><p>Record name: www</p><p>Route traffic to:</p><ul><li>Alias to Network Load Balancer</li><li>Select the region</li><li>Select the NLB</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R1RGOnrEe22obz6vrEJSBw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*3BMaWupERrF3sCRU.png" /></figure><p>We have successfully created a record set.</p><p>Select the <strong>Record name</strong> and copy the <strong>Record name</strong> to your right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*OPiYKAttlhbcD61k.png" /></figure><p>Open a browser and paste the record name here.</p><p>There you have it! We can now access the application we deployed on ECS fargate containers and the communication between the end users and our application is also secured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aQTMNJSBrwDip4g4eSoK-Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8aP8AJaqM3-bG-aCuS2oFA.png" /></figure><h3>33. Cleaning Up Your EKS Project</h3><p>We have successfully deployed our application on AWS using docker, amazon ECR, ECK and various core AWS services. On my next project, we will deploy the same application on AWS using terraform.</p><p>Let’s start destroying the resources we created in this project to avoid further usage costs.</p><p><strong>Worker Node Group</strong></p><p>Select the rentzone-cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LLA3YWHofZCeZKvh8GNjKQ.png" /></figure><p>Under compute, select the node group and select delete node.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-NLW97XrWUoY3XukXxFFw.png" /></figure><p>We’ve successfully deleted the node group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sOLK28zR3vojSTw6u4mM4Q.png" /></figure><p><strong>EKS Cluster</strong></p><p>Select the rentzone-cluster and delete cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8pGUEoyIqrjHxHLsXRnE6g.png" /></figure><p>Enter the phrase to confirm deletion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cQ_Z2EfWFET2iZT7NYxG7g.png" /></figure><p>We’ve successfully deleted the rentzone-cluster.</p><p>Delete the following<strong>:</strong></p><p><strong>Network Load Balancer</strong></p><p><strong>Target groups</strong></p><p><strong>EICE</strong></p><p><strong>CloudFormation</strong> — Delete the Service account created by CF</p><p><strong>Secrets Manager</strong></p><p><strong>RDS Instance</strong></p><p>After selecting DB Instances, select your RDS instance.</p><p>You might need to disable the deletion protection found in the configuration tab. Click actions and click delete. We will create a final snapshot of our database so its crucial that you<strong> tick create final snapshot</strong>. Provide your snapshot name then hit the delete button.</p><p><strong>Record Set</strong></p><p>We are deleting the A record which has the www followed by your domain name.</p><p><strong>Security Groups</strong></p><p>Let’s delete the security groups in this order</p><ol><li>Database</li><li>Container Security Group</li><li>Bastion Host Security Group — you must terminate the Bastion Host first</li><li>ALB Security Group</li></ol><p><strong>NAT Gateways</strong></p><p>Let’s delete the NAT gateways in this order.</p><p>NAT Gateway AZ1</p><p>NAT Gateway AZ2</p><p><strong>Elastic IP Addresses</strong></p><p><strong>Amazon RDS Subnet Groups</strong></p><p>Going back to amazon RDS, select your database subnet group and click delete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*5RfXHt2e_my6xT6X.png" /></figure><p><strong>VPC</strong></p><p>Select the custom VPC that we created for this project.</p><p>These are all the resources that will be deleted, click delete.</p><p><strong>Congratulations</strong> and thank you for following along. I hope you find this valuable in your journey. Let me know if you have any questions and I look forward to see you on my next project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*ZjIm60E56FBGTdtj" /></figure><p>Build real-world projects with me <a href="https://www.youtube.com/@belloafeez_">here</a>! Show your employers that you are the right person for the job and stand out from the crowd!</p><p>Connect with me on <a href="https://www.linkedin.com/in/bello-afeez/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=071ec7f1b164" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Configuring Terraform for AWS Organizations with SSO Integration]]></title>
            <link>https://medium.com/@werkjober/configuring-terraform-for-aws-organizations-with-sso-integration-63935b334c4d?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/63935b334c4d</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 17:06:47 GMT</pubDate>
            <atom:updated>2024-10-05T18:01:10.077Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Terraform for AWS Organizations with SSO" src="https://cdn-images-1.medium.com/max/900/1*nqeVo49G7BlGC5Q_YAPHuw.png" /></figure><p>In today’s cloud-driven environment, managing infrastructure at scale requires automation and structure. AWS Organizations helps manage multiple AWS accounts under a single organization, while AWS SSO simplifies access management for teams. Combining Terraform, an Infrastructure as Code (IaC) tool, with AWS Organizations and SSO can help automate and standardize how you manage accounts and access. In this guide, I’ll walk through setting up Terraform with AWS Organizations with AWS SSO, to manage and deploy your infrastructure in a secure and easy way.</p><h3>Prerequisites</h3><p>Before we begin, ensure the following are in place:</p><ul><li><strong>Active AWS Account with SSO</strong>: I’ll assume you already have an active AWS account and have enabled <strong>AWS Single Sign-On (SSO)</strong>.</li></ul><p>You can follow along with the steps below to install the necessary tools:</p><ul><li><strong>Terraform</strong>: Install <strong>Terraform</strong> (version 0.13 or higher is recommended).</li><li><strong>AWS CLI (Version 2)</strong>: Install <strong>AWS Command Line Interface (CLI) V2</strong>.</li></ul><p>For a smoother development experience, using an IDE like <strong>VS Code</strong> is optional but recommended.</p><h3>Step 1: Download Terraform</h3><p>You can either download Terraform manually or use a package manager. I will go with the easy way to do so.</p><p>To get started, visit the official Terraform <a href="https://developer.hashicorp.com/terraform/install">downloads page</a> and locate the latest release for Linux. Since this tutorial is based on Ubuntu, I’ll be downloading the Linux binary. Make sure to select the AMD64 version for the most recent release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kLPtg34zjh1PFImVGIRK5A.png" /></figure><p>Alternatively, you can use wget or curl to download the latest version. For example:</p><pre>wget https://releases.hashicorp.com/terraform/1.5.0/terraform_1.5.0_linux_amd64.zip</pre><p>After downloading the zip file, you need to unzip it.</p><pre>sudo apt install unzip  # If unzip is not installed <br>unzip terraform_1.5.0_linux_amd64.zip</pre><p><strong>Move the Binary to </strong><strong>/usr/bin</strong></p><p>After unzipping the Terraform binary, move it to /usr/bin/ to make it globally accessible.</p><pre>sudo mv terraform /usr/bin/</pre><p>Again, verify that Terraform is correctly installed by running:</p><pre>terraform -version</pre><p>You should see the version of Terraform you just installed.</p><h3>Step 2: Download AWS CLI Version 2</h3><p>To install AWS CLI version 2, first uninstall version 1 if it’s already installed. Version 2 introduces several enhancements, including improved installation processes, new configuration options like AWS IAM Identity Center (the successor to AWS SSO), and a range of interactive features that are not available in version 1. Follow the steps below to install AWS CLI version 2.</p><p>Download the AWS CLI v2 installation package:</p><pre>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;</pre><p>Unzip the package and Run the install script:</p><pre>unzip awscliv2.zip<br>sudo ./aws/install</pre><p>After the installation completes, check if AWS CLI version 2 is successfully installed by running:</p><pre>aws --version</pre><p>You should see output similar to:</p><pre>aws-cli/2.x.x Python/3.9.x Linux/4.x botocore/2.x.x</pre><h3>Step 3: <strong>Setting Up Terraform</strong></h3><p>After setting up your Terraform code ready for deployment in VSCode — log into your AWS CLI with your SSO user. Open VSCode terminal</p><pre>aws configure sso</pre><p><strong>Step 1: Provide a session name</strong><br>Enter the name you’d like to assign to this session. Next, provide your SSO start URL, which can be found in the root AWS Organization account. Press <strong>Enter</strong> to accept the default values for any prompts you wish to skip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OVXOd7pu2DBWZ7JiVgWnqA.png" /></figure><p><strong>Step 2: Authenticate via browser</strong><br>You’ll now be redirected to a browser page to log in using your SSO credentials. Complete the login process there, then return to your CLI to finalize the session setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKg9NfK3rQkFQrbm8kahIA.png" /></figure><p><strong>Step 3: Providing the Right Credentials to Terraform</strong><br>Simply logging into your AWS CLI is not enough — Terraform also requires access to your AWS credentials, specifically the Access Key and Secret Access Key for your SSO user.</p><p>However, <strong>hardcoding credentials</strong> directly into your Terraform configuration is considered a bad practice for security reasons, and it’s something you should avoid. Instead, you can configure Terraform to securely access credentials stored locally on your system.</p><p>To allow Terraform to use your AWS credentials securely, follow these steps:</p><p><strong>1. Navigate to the </strong><strong>.aws Directory</strong><br>On your local machine, navigate to the .aws directory. This directory stores your AWS configuration files. Depending on your operating system, the path might be:</p><p><strong>2. Check the </strong><strong>config and </strong><strong>credentials Files</strong><br>Inside the .aws directory, you will find two key files:</p><ul><li><strong>config</strong>: This file contains configuration information, such as region and SSO start URLs.</li><li><strong>credentials</strong>: This file stores the actual access keys and tokens.</li></ul><p><strong>3. Edit the </strong><strong>credentials File</strong><br>Open the credentials file and locate the section where your SSO user information should be stored. If it’s not already there, you need to manually add the credentials generated from your AWS SSO login.</p><p>To do this:</p><ul><li>Log in to your AWS SSO account using the <strong>SSO start URL</strong> you received in your AWS Organization.</li><li>Once you’ve logged in, copy the credentials (Access Key, Secret Access Key, and session tokens) from the <strong>SSO user</strong> page.</li><li>Paste these credentials into the credentials file under the appropriate profile name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZwiDTgS0Mk0BKKrdh7o5A.png" /></figure><p>Example format for the credentials file:</p><pre>[your-profile-name]<br>aws_access_key_id = YOUR_ACCESS_KEY_ID<br>aws_secret_access_key = YOUR_SECRET_ACCESS_KEY<br>aws_session_token = YOUR_SESSION_TOKEN</pre><p><strong>4. Reference the Credentials in Terraform</strong><br>Now, Terraform can use these credentials without hardcoding them. You can:</p><ul><li><strong>Set Environment Variables</strong>: Terraform automatically picks up AWS credentials stored in the ~/.aws/credentials file.</li></ul><blockquote>Make sure to match the profile name of your pasted credentials with that mentioned in Terraform <strong>main.tf </strong>file</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fTI3hJOXnKJ-_JWk-y4hEg.png" /></figure><pre>provider &quot;aws&quot; {<br>  region = var.aws_region<br>  shared_config_files      = [&quot;/home/bello/.aws/config&quot;]<br>  shared_credentials_files = [&quot;/home/bello/.aws/credentials&quot;]<br>  profile                  = &quot;*******&quot;<br>}</pre><p>And that’s it! You’re all set to deploy your terraform code with</p><p>&gt;&gt;<strong>terraform init</strong><br>&gt;&gt; <strong>terraform apply</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AGl-5q6mtPs-qmiDLzUpSw.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63935b334c4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Backup and Restore ETCD Snapshot on Kubernetes Cluster]]></title>
            <link>https://medium.com/@werkjober/how-to-backup-and-restore-etcd-snapshot-on-kubernetes-cluster-c612ce5b6147?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/c612ce5b6147</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Thu, 14 Dec 2023 12:46:53 GMT</pubDate>
            <atom:updated>2023-12-14T12:46:53.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nFJG6G8QuYIhbxKjW1T1yw.png" /></figure><p>In this kubernetes tutorial, you will learn how to backup etcd and restore on Kubernetes cluster with an etcd snapshot.</p><p>In Kubernetes architecture, Etcd is a distributed key-value store that is used as the primary datastore in Kubernetes. It plays a crucial role in maintaining the state of the entire cluster by storing configuration data, state information, and metadata</p><p>Few things you should know about etcd from a Kubernetes perspective.</p><ol><li>It is a consistent, distributed, and secure key-value store.</li><li>Supports highly available architecture with stacked etcd.</li><li>It stores kubernetes cluster configurations, all API objects, object states, and service discovery details.</li><li>Etcd serves as the authoritative source of truth for the cluster. All nodes in the Kubernetes cluster read and write to etcd to maintain a consistent and up-to-date view of the cluster state.</li><li>It uses <a href="https://raft.github.io/">raft protocol.</a></li><li>Kubernetes components, including controllers and the API server, use the watch mechanism to monitor changes in etcd. This allows them to react to changes in the cluster and take appropriate actions.</li></ol><p>ETCD has a built-in snapshot mechanism and etcdctl is the command line utility that interacts with etcd for snapshots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*-7td9m38fDoqck0_9gstAw.png" /></figure><h3>1 - Lets Backup etcd in K8s Cluster Using etcdctl.</h3><p><strong>Step 1:</strong> Log in to the control plane.</p><p><strong>Step 2:</strong> If you don’t have etcdctl in your cluster control plane, install it using the following command.</p><pre>sudo apt install etcd-client</pre><p><strong>Step 3:</strong> We need to pass the following three pieces of information to etcdctl to take an etcd snapshot.</p><ol><li>etcd endpoint (–endpoints)</li><li>ca certificate (–cacert)</li><li>server certificate (–cert)</li><li>server key (–key)</li></ol><p>You can get the above details in two ways.</p><p>From the etcd static pod manifest file located at /etc/kubernetes/manifests/etcd.yaml the location.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/0*n_6wFac9WnI-PpDG.png" /></figure><p>You can also get the above details by <strong>describing the etcd pod running</strong> in the kube-system namespace. While describing the pod, replace etcd-master-node with your etcd pod name.</p><pre>kubectl get po -n kube-system<br>kubectl describe pod etcd-master-node -n kube-system</pre><p><strong>Step 4: </strong>Take an etcd snapshot backup using the following command.</p><pre>ETCDCTL_API=3 etcdctl \<br>  --endpoints=https://127.0.0.1:2379 \<br>  --cacert=&lt;ca-file&gt; \<br>  --cert=&lt;cert-file&gt; \<br>  --key=&lt;key-file&gt; \<br>  snapshot save &lt;backup-file-location&gt;</pre><p>The command looks like the following when you add the actual location and parameters. Execute the command to perform a backup. You can replace /opt/backup/etcd.db with the location and name of your choice.</p><pre>ETCDCTL_API=3 etcdctl \<br>  --endpoints=https://127.0.0.1:2379 \<br>  --cacert=/etc/kubernetes/pki/etcd/ca.crt \<br>  --cert=/etc/kubernetes/pki/etcd/server.crt \<br>  --key=/etc/kubernetes/pki/etcd/server.key \<br>  snapshot save /opt/backup/etcd.db</pre><p>On a successful execution you will get a “Snapshot saved at /opt/backup/etcd.db”, message as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/0*xcRqxWO77Hb-2tUx.png" /></figure><p>We have successfully created a snapshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*5-D29uL6klkueRUFi-jB4A.png" /></figure><h3>2 - Lets Restore the backup using the snapshot we created earlier</h3><p>Now we have the backup in the /opt/backup/etcd.db location. We will use the snapshot backup to restore etcd.</p><p>Here is the <strong>command to restore etcd.</strong></p><pre>ETCDCTL_API=3 etcdctl snapshot restore &lt;backup-file-location&gt;</pre><p>Let’s execute the etcd restore command. In my case /opt/backup/etcd.db is the backup file.</p><pre>ETCDCTL_API=3 etcdctl snapshot restore /opt/backup/etcd.db</pre><p>If you want to use a specific data directory for the restore, you can add the location using the --data-dir flag as shown below.</p><pre>ETCDCTL_API=3 etcdctl --data-dir /opt/etcd snapshot restore /opt/backup/etcd.db</pre><p>Make sure you edit the ETCD yaml file to use the new directory as the source of the data source.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*TF7FE_hZxd71RNf1" /></figure><p><strong>Congratulations</strong> and thank you for following along. I hope you find this valuable in your journey. Let me know if you have any questions.</p><p>Build real-world projects with me <a href="https://www.aosnote.com/a/2147524876/WLBooyWz">here</a>! Show your employers that you are the right person for the job and stand out from the crowd!</p><p>Connect with me on <a href="https://www.linkedin.com/in/bello-afeez/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c612ce5b6147" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA["kubectl apply": A Deep Dive into Kubernetes Most Versatile Command]]></title>
            <link>https://medium.com/@werkjober/kubectl-apply-a-deep-dive-into-kubernetes-most-versatile-command-b2b441bbc2b1?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2b441bbc2b1</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubectl]]></category>
            <category><![CDATA[cloud-services]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Wed, 22 Nov 2023 08:44:22 GMT</pubDate>
            <atom:updated>2023-11-22T09:14:43.642Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wA63qbJmor8dHpeWHwUDtg.gif" /></figure><p>In the world of Kubernetes, one command that consistently stands out for its versatility and power is kubectl apply. This command is fundamental to the way we manage and interact with Kubernetes clusters. To truly appreciate its capabilities, it’s essential to understand how it operates under the hood.</p><p>Kubectl apply command is used for creating, updating or deleting an object in a declarative way.</p><ul><li>The “kubectl apply” command is intelligent to be able to create an object if it doesn’t already exist.</li><li>It will look at the existing configuration and figure out what changes need to be made to the existing objects or applications.</li></ul><p>When modifications are required in our application, such as updating the image version, we simply adjust the object configuration file and execute “kubectl apply -f object-definition.yaml”. In this instance, the apply command recognizes the existing object and updates it with the new changes.</p><p><strong><em>So how does the kubectl apply command exactly works?</em></strong></p><p>The kubectl apply takes <strong><em>the local configuration file, a live object definition on Kubernetes and the last applied configuration</em></strong> into consideration before making a decision on what changes are to be made.</p><p><strong><em>nginx.yaml</em></strong></p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>   name: myapp-pod<br>   labels:<br>      app: myapp<br>      type : front-end-service<br>spec:<br>   containers:<br>   - name: nginx-conatiner<br>     image: nginx:1.18<br></pre><p>So when you run the command</p><pre>kubectl apply -f nginx.yaml</pre><p>if the object does not already exist, the object is created.</p><p>When the Object is created, a “<strong>live object configuration</strong>” similar to what we created locally is also created but with additional fields to store the status of the object.</p><p><strong><em>live-nginx-configuration:</em></strong></p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>   name: myapp-pod<br>   labels:<br>      app: myapp<br>      type : front-end-service<br>spec:<br>   containers:<br>   - name: nginx-conatiner<br>     image: nginx:1.18<br>status:<br>  conditions:<br>  - lastProbeTime: null<br>    status: &quot;True&quot;<br>    type: Initialized</pre><p>This is the method by which Kubernetes retains information about an object, regardless of the method employed (whether through “kubectl create” or “kubectl apply”) to generate the object.</p><p>However, when employing the “kubectl apply” command for object creation, it introduces an additional step. The YAML representation of the “local object configuration” file undergoes conversion to JSON format, subsequently serving as the “last applied configuration” for storage.</p><p><strong><em>last applied configuration</em></strong></p><pre>{<br>  &quot;apiVersion&quot;: &quot;v1&quot;,<br>  &quot;kind&quot;: &quot;Pod&quot;,<br>  &quot;metadata&quot;: {<br>    &quot;name&quot;: &quot;myapp-pod&quot;,<br>    &quot;labels&quot;: {<br>      &quot;app&quot;: &quot;myapp&quot;,<br>      &quot;type&quot;: &quot;front-end-service&quot;<br>    }<br>  },<br>  &quot;spec&quot;: {<br>    &quot;containers&quot;: [<br>      {<br>        &quot;name&quot;: &quot;nginx-conatiner&quot;,<br>        &quot;image&quot;: &quot;nginx:1.18&quot;<br>      }<br>    ]<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cLo5LVGJbPaAKwx0O3A09g.png" /></figure><p><em>Moving forward, any updates to the object involve a comparison among the three configurations: the local object configuration, the last applied configuration, and the live object configuration, in order to determine the necessary adjustments for the live object in the Kubernetes cluster.</em></p><p>For instance, suppose the Nginx image is upgraded to version 1.19 in our local file. Upon executing the “kubectl apply” command, this updated value is compared to the corresponding value in the live configuration. If disparities exist, the live configuration is modified to reflect the new value.</p><p>Subsequently, following any alteration, the last applied JSON format is consistently updated to ensure it remains current at all times.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jxyc-7BVhcWEsOfvDNIK0A.png" /></figure><blockquote><strong>So why do we really need the last applied configuration?</strong></blockquote><p>Let’s say a field was deleted, say for example, the type label was deleted, and now when we run the “kubectl apply” command, we see the last applied configuration had a label, but it’s not present in the local configuration.</p><p>This means that the field needs to be removed from the live configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yzp_3xO43CMKQEAIH2HD-g.png" /></figure><p>If a field is present in the live configuration but absent in both the local and last applied configurations, it remains unchanged.</p><p>However, if a field is missing in the local configuration but is present in the last applied configuration, it implies that this field existed in a previous configuration but has now been removed. In such cases, the last applied configuration serves as a valuable reference, helping identify the fields that have been removed from the local file. Consequently, the corresponding field is then removed from the live configuration to maintain consistency with the updated specifications.</p><p>As we seen have in above diagram, and we know that the local file is stored in our local system. The live object configuration is stored in the Kubernetes memory, but where is the JSON file that has the last applied configuration stored?</p><p>The JSON file containing the last applied configuration is stored within the live object configuration on the Kubernetes cluster itself. It is stored as an annotation with the specific name “last applied configuration.” This annotation serves as a reference point for tracking the most recent configuration applied to the object. By keeping this information within the live object configuration on the Kubernetes cluster, the system can efficiently compare and update configurations as needed, ensuring consistency and accuracy in managing object states.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_-TXUPlzwqf2qg2cSUZg9Q.png" /></figure><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>   name: myapp-pod<br>   annotations:<br>   kubectl.kubernetes.io/last-applied-configuration:<br>   {&quot;apiVersion&quot;: &quot;v1&quot;,&quot;kind&quot;: &quot;Pod&quot;,&quot;metadata&quot;: {&quot;name&quot;: &quot;myapp-pod&quot;, &quot;labels&quot;: {&quot;app&quot;: &quot;my-app&quot;,&quot;type&quot;: &quot;front-end-service&quot;}},&quot;spec&quot;: {&quot;containers&quot;: [{&quot;name&quot;: &quot;nginx-container&quot;,&quot;image&quot;: &quot;nginx:1.18&quot;<br>}]}}<br>labels:<br>      app: myapp<br>      type : front-end-service<br>spec:<br>   containers:<br>   - name: nginx-container<br>     image: nginx:1.18<br>status:<br>  conditions:<br>  - lastProbeTime: null<br>    status: &quot;True&quot;<br>    type: Initialized</pre><p>The mechanism of storing the last applied configuration as an annotation is specific to the kubectl apply command. When you use kubectl apply, it not only creates or updates the live object configuration but also stores a record of the last applied configuration as an annotation. This annotation aids in tracking changes and facilitating the comparison process for subsequent updates.</p><p>On the other hand, the kubectl create or kubectl replace commands do not incorporate this feature. They focus on creating or replacing the object directly without preserving the last applied configuration in the form of an annotation. Therefore, if you rely on kubectl apply for managing your objects, you benefit from the additional functionality of tracking and storing the last applied configuration for future reference.</p><p>As we’ve seen, kubectl apply is a command that embodies the essence of Kubernetes: simplicity, efficiency, and power. Whether you’re a novice or an expert, understanding this command is key to mastering Kubernetes.</p><p><strong>Congratulations</strong> and thank you for following along. I hope you find this valuable in your journey. Let me know if you have any questions and I look forward to see you on my next project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2b441bbc2b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host A Dynamic Web App on AWS with Docker, ECR, and ECS]]></title>
            <link>https://medium.com/@werkjober/host-a-dynamic-web-app-on-aws-with-docker-ecr-and-ecs-3d1a4fab96d6?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/3d1a4fab96d6</guid>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[aws-fargate]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Mon, 16 Oct 2023 16:29:14 GMT</pubDate>
            <atom:updated>2023-10-16T16:37:39.365Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Fk3dsLuxCagbPccwYFwHA.png" /></figure><p>Greetings! Welcome back 😃. In the upcoming project, we’ll be focusing on delivering comprehensive tutorial for hosting a dynamic web application on AWS using Docker, Amazon ECR, and Amazon ECS. Throughout this course, we’ll cover various essential steps, starting with setting up your local environment. This includes tasks like creating a free GitHub account, generating Key Pairs, installing Git and Visual Studio Code, and establishing a Docker Hub account.</p><p>Our chosen technology stack for this project is LAMP, which stands for Linux (the operating system), Apache (the web server software), MySQL (the database engine), and PHP (the programming language). This combination of open-source software components enables us to create a dynamic web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*3xQY-BHq15LXBLle.png" /></figure><p>We will also learn how to build the AWS infrastructure for your containerized web app by building a Three-Tier VPC, creating NAT Gateways, setting up Security Groups, and creating an RDS instance. We will learn how to build Docker image for our containerized web app by creating a repository to store your application codes, creating a docker file, and adding build arguments and environment variables. Then we will learn how to push the docker image to AWS for deployment.</p><p>Lastly, we will cover how to input data with Flyway and creating an ECS service for the containerized web app. Including creating an Application Load Balancer, registering an SSL certificate, and creating a Record Set in Route 53. By the end of our project, we will have a fully functional web app that is hosted on AWS using containerized technologies.</p><p>Let’s dive into the world of containerized web applications.</p><h3>What is Container Deployment?</h3><p>Container deployment is a method for quickly building and releasing complex applications. Docker container deployment is a popular technology that gives developers the ability to construct application environments with speed at scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*76q9s_HAL_RDPOcH" /></figure><h3>Benefits</h3><ol><li>Less overhead</li><li>Increased portability</li><li>More consistent operation</li><li>Greater efficiency</li><li>Better application development</li></ol><h3>Objectives</h3><ol><li>Introduction</li><li>Sign up for a Free GitHub Account</li><li>Create Key Pairs</li><li>Add the Public SSH Key to GitHub</li><li>Install Git on your Computer</li><li>Installing Visual Studio Code on your Computer</li><li>Create a Docker Hub Account</li><li>Enable Virtualization on your Computer</li><li>Download and Install Docker on your Computer</li><li>Building a Three-Tier AWS Network VPC from Scratch</li><li>Create NAT Gateways</li><li>Create Security Groups in AWS</li><li>Set up MySQL RDS Instance in AWS</li><li>Create EC2 Instance Connect Endpoint</li><li>Registering a New Domain Name in Route 53</li><li>Create Repository to Store the Application Codes</li><li>Adding the Application Code to the GitHub Repository</li><li>Creating a Repository to Store the Dockerfile</li><li>Creating a Personal Access Token</li><li>Adding Build Arguments and Environment Variables to a Dockerfile</li><li>Creating a Script to Build the Docker Image</li><li>Making Script Executable</li><li>Building the Docker Image</li><li>Installing the AWS Command Line CLI</li><li>Creating an IAM User with Programmatic Access</li><li>Running the AWS Configure Command</li><li>Creating a Repository in Amazon ECR with AWS CLI</li><li>Pushing the Docker Image to the Amazon ECR Repository</li><li>Migrate Database file (Rentzone MySQL)</li><li>Creating an Application Load Balancer</li><li>Registering for an SSL Certificate in Amazon Certificate Manager</li><li>Creating an HTTPS Listener for the Application Load Balancer</li><li>Adding Environment Variables to a File</li><li>Creating an S3 Bucket to Store the Environment File</li><li>Creating an IAM Role for the ECS Task Definition</li><li>Creating an ECS Cluster</li><li>Creating a Task Definition</li><li>Creating an ECS Service</li><li>Creating a Record Set in Route 53</li><li>Cleaning Up Your ECS Project</li></ol><h3>Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*Jjg96I9zB6K86TxZD2ViAA.png" /></figure><p><strong>Docker </strong>to build the container image</p><ol><li><strong>Git </strong>to track changes to secure code and files</li><li><strong>GitHub </strong>to manage the Dockerfile and application codes in Git repositories</li><li><strong>AWS CLI</strong> to interact with AWS services from the command line</li><li><strong>Flyway </strong>to migrate SQL data into the RDS database</li><li><strong>VS Code </strong>to write and edit scripts</li><li><strong>Amazon ECR</strong> to store the Docker Image</li><li><strong>Amazon ECS</strong> to containerize the web application on the AWS cloud</li><li><strong>3 tier VPC</strong> with public and private subnets in 2 availability zones</li><li><strong>Internet Gateway</strong> to allow communication between resources in VPC and the internet</li><li><strong>NAT Gateways</strong> to allow resources in the private subnets access to the internet</li><li><strong>Amazon MySQL RDS</strong> for relational database</li><li><strong>ECS Fargate</strong> to run the containerized application</li><li><strong>Application Load Balancer</strong> to distribute web traffic to the ECS Fargate tasks</li><li><strong>Auto Scaling Group</strong> to dynamically create new ECS tasks</li><li><strong>Route 53</strong> to register domain name and create record set</li><li><strong>AWS S3</strong> to store files containing environment variables for the container</li><li><strong>IAM Role</strong> to grant permission for ECS to execute tasks</li><li><strong>Security Group</strong> to control inbound and outbound traffic to resoources</li><li><strong>Certificate Manager</strong> to encrypt data in transit</li></ol><h3>2. GitHub to Manage the Dockerfile and Application Codes</h3><p>We will create a GitHub account to store all the code’s file project. For details on how to set up a GitHub account, you can check this GitHub documentation <a href="https://docs.github.com/en/get-started/signing-up-for-github/signing-up-for-a-new-github-account"><strong>here</strong></a><strong> </strong>where it explained thoroughly.</p><h3>3. Create Key Pairs</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/0*u772EOSP1aGRQaOZ.png" /><figcaption>Reference Architecture</figcaption></figure><p>Create key pairs on your computer</p><p>We will create key pair on our computer so we can use it to clone our private GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*lTWWPqmFfeyVMM67.png" /></figure><p>Open your <strong>PowerShell</strong>. To create keypair on your computer type ssh-keygen -t rsa -b 2048 press <strong>enter</strong>.</p><p><em>-t means type. The type is </em><em>rsa . The </em><em>-b is byte and the byte is </em><em>2048</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*MYXP7cF1owqq35xH.png" /></figure><p>The next question is asking you where you want to save your keypair to. The directory above is the default directory where your keypair will be saved and for best practice, it is always best to leave it here. Press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*mjztKBEuxmXvXpVn.png" /></figure><p>Press enter because we are not going to add any passphrase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/0*StMLMipPU-G155mJ.png" /></figure><p>Press enter again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*VGPh8SzLxMYAxrq9.png" /></figure><p>We have successfully created the keypair. Our keypair is saved in <strong>C:\Users\Admin/.ssh/id_rsa</strong> so let’s go and check this path.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Esl162Ps4IoKpLBV.png" /></figure><p>There you go, in the .<strong>ssh folder</strong>, you can see the keypairs in there.</p><h3>4. Add the Public SSH Key to GitHub</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/0*ExxaZ_7bn6B1k-y_.png" /><figcaption>Reference Architecture</figcaption></figure><p>Add the public SSH key to GitHub to connect to GitHub without supplying your username and personal access token at each visit.</p><p>We will upload our keypair into GitHub. Previously, we created a keypair the next thing that we need to do is to upload the public key of that keypair into GitHub. Afterwards, we’ll be able to clone our GitHub repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*LWTqWIR1qnwKwL4P.png" /></figure><p>Open <strong>file explorer</strong> and go to the location where you saved your keypair. We need to upload the public key and it has the <strong>P icon</strong>. Right click and select <strong>Open with notepad.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*WGNruJk40yEaYTD0.png" /></figure><p>Copy everything. Do not make any changes because it’s an encryption key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhVnsq4-einjiLjMOXQ9Xg.png" /></figure><p>Log in to your <strong>GitHub account.</strong> Click your <strong>profile icon</strong> and select <strong>settings.</strong> Go to <strong>SSH and GPG keys (left menu) </strong>and<strong> </strong>Select<strong> New SSH Key.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2X-G9lK84dA_wTSU_1m3kg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YFb1k4a_6vWcKHRs9UYQMg.png" /></figure><p>Give a <strong>title</strong>, paste your public your public key in the big box, and click <strong>Add SSH key.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WMTuSV55CBKm9nYSo3dflA.png" /></figure><p>We have successfully uploaded our public SSH key into GitHub. We can now clone our GitHub repository to our computer.</p><h3>5. Install Git to track changes to secure code and files</h3><p>We will clone our repository to our local computer. Cloning means that you are creating an identical copy of your GitHub repository on your local computer. So when you clone a GitHub repository, all the files in the repository are downloaded to your computer to allow you to work with those files easily.</p><h4>Install Git</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/0*DsMr8oQK4czucUPG.png" /><figcaption>Reference Architecture</figcaption></figure><p>Install Git on your computer for source code management.</p><p>Go to <strong>git-scm.com</strong> and click download for windows. Follow the installation prompt. Once downloaded, we need to verify that Git was successfully installed on our computer. One way to verify is to type <strong>git </strong>in the <strong>search box</strong> of your start menu. Click the Git <strong>Bash app</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*2ThikPdOVLn-tD8U_HOrYg.png" /></figure><p>There you go, we have successfully installed Git on our computer.</p><pre>git config --global user.name &quot;Your Name&quot;</pre><pre>git config --global user.email &quot;youremail&quot;</pre><p>Open the <strong>command prompt.</strong> We need to run these commands in the terminal to configure your <strong>Git username and email.</strong> Make sure to <strong>update your first and last name and your email address</strong> before you run the command.</p><p>There you have it. That’s all we need to do to configure our Git username and email.</p><h3>6. Install Visual Studio Code on Your Computer</h3><p>Visual Studio Code is a text editor and we will install it on your computer. For details on how to install it, visit <a href="https://code.visualstudio.com/download"><strong>here </strong></a>to download it.</p><h3>7. Create a Docker Hub Account</h3><p>To sign up for a docker hub account, visit <a href="https://hub.docker.com/signup"><strong>here</strong></a><strong> </strong>to sign up for your free account.</p><h3>8. Enable Virtualization on your Computer</h3><p>The virtualization is always enabled on your computer by default. To check if this is enabled on your computer watch this <a href="https://www.youtube.com/watch?v=MOuTxfzCvMY"><strong>video</strong></a> by Triple-A Tech Solution.</p><p><strong><em>Before you can install docker on your windows computer, you must enable virtualization on your computer.</em></strong></p><p>If you’ve verified the <strong>Virtualization Enabled In Firmware: Yes</strong>. This means that virtualization is enabled on your computer and you can stop here and proceed to the next step. Otherwise, finish watching the video and complete the steps in enabling virtualization in windows 10, this requires rebooting your computer.</p><h3>9. Download and Install Docker on Your Computer</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*VCFUwUKr2yb0AM6Q.png" /><figcaption>Reference Architecture</figcaption></figure><p><strong>Download and install docker on your computer.</strong></p><p>Go <a href="https://docs.docker.com/get-docker/"><strong>here</strong></a> to download and install docker on your computer. Click <strong>Docker Desktop for Windows. </strong>Run and install the executable file.</p><p>Reboot your computer to complete the installation.</p><blockquote>The first time you open docker, you need to review and accept the service agreement. When you see the WSL 2 Installation is Incomplete window, click the link underneath and click the link below Step 4 to download the latest linux kernel package.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Im5nbhnP3XuFckxl.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*_0e_0OdbidQKUsz6.png" /></figure><p>Run the <strong>executable file and the Setup Wizard.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*-2ABSFAaswp7w_8B.png" /></figure><p>After updating the package, proceed to Step 5 and follow the instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*qVMK1aKKvBiehdiK.png" /></figure><p>The operation completed successfully and that is all that we need to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*_7H6SRTSontxr6Vb.png" /></figure><p>Restart docker and sign in. Lastly, verify if docker is installed on your computer. Open Windows PowerShell and run docker -v If you get an output like this, it meaning that its successfully installed in your computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/0*ohKxusv3jwJKkgkn.png" /></figure><p>This is all we need to do to install docker on our computer.</p><h3>10. Build a Three-Tier AWS Network VPC from Scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*dn-viSRkUFrmIXPM.png" /></figure><ol><li><strong>VPC</strong> with public and private subnets in 2 availability zones</li><li>An <strong>internet gateway</strong> is used to allow communication between instances in VPC and the internet</li><li>We are using <strong>2 availability zones</strong> for high availability and fault tolerance</li><li>Resources such as NAT gateway, bastion host, and application load balancer use <strong>public subnets.</strong></li><li>We will put the web servers and database servers in the <strong>private subnets</strong> to protect them</li><li>The <strong>public route table</strong> is associated with the public subnets and routes traffic to the internet through the internet gateway</li><li>The <strong>main route table</strong> is associated with the private subnets</li></ol><p>For details on how to build a three-tier AWS network VPC from scratch, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%201%3A%20Build%20a%20Three%2DTier%20AWS%20Network%20VPC%20from%20Scratch"><strong>here</strong></a><strong> </strong>where I explained it thoroughly.</p><h3>11. Create Nat-gateway</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Z3883Zc_D8U8RJEi.jpeg" /></figure><ol><li>The <strong>NAT Gateway</strong> allows the instances in the private app subnets and private data subnets to access the internet</li><li>The <strong>Private Route Table</strong> is associated with the private subnets and routes traffic to the internet through the NAT gateway.</li></ol><p>For details on how to create NAT Gateways, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%202%3A%20Create%20NAT%20Gateways"><strong>here</strong></a> where I explained it thoroughly.</p><h3>12. Create Security Groups in AWS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*dwsvJZmECfG-fn3rVvuKbg.png" /></figure><p>We will create 4 security groups for this project.</p><p><strong>ALB Security Group</strong></p><ul><li>Types are HTTP and HTTPS</li><li>Opens port 80 and 443 with source 0.0.0/0</li><li>This is the security group that we will add to the application load balancer</li></ul><p><strong>SSH Security Group — EICE</strong></p><ul><li>This is the security group that we will use to EICE to ssh into our EC2 instance in the private subnet</li><li>Port: Open outbound on 22 with Source: <strong>VPC cidr </strong>(10.0.0.0/16)</li></ul><p><strong>Container Security Group</strong></p><ul><li>Types are HTTP and HTTPS</li><li>Allows internet traffic on port 80 and 443 but only if the traffic is coming from the Application Load Balancer.</li><li>It will be attached to the Amazon ECS tasks.</li></ul><p><strong>Database Security Group</strong></p><ul><li>It will be attached to the RDS instance.</li><li>Ports are 3306</li><li>Type is MySQL/Aurora with source container security group.</li><li>Type is custom TCP with source bastion host security group.</li></ul><p>For details on how to create <strong>Security Groups</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%203%3A%20Create%20Security%20Groups"><strong>here</strong></a> where I explained it thoroughly.</p><h3>13. Set up MySQL RDS Instance in AWS</h3><p>We will create our database for this project in the private database subnet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*pvsVmNcdoFDpD9mf.jpeg" /></figure><p>For details on how to create <strong>RDS Instance</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%204%3A%20Create%20the%20RDS%20Instance"><strong>here</strong></a> where I explained it thoroughly.</p><h3>14: Create EC2 Instance Connect Endpoint</h3><p>For details on how to create <strong>EC2 Instance Connect Endpoint</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%205%3A%20Create%20EC2%20Instance%20Connect%20Endpoint"><strong>here</strong></a> where I explained it thoroughly.</p><h3>15. Register a New Domain Name in Route 53</h3><p>For details on how to create <strong>New Domain Name in Route 53</strong>, visit my previous project <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%2013%3A%20Register%20a%20New%20Domain%20Name%20in%20Route%2053"><strong>here</strong> </a>where I explained it thoroughly.</p><h3>16. Create Repository to Store the Application Codes</h3><p>We will create a repository to store our application code. We will then clone our repository on our computer.</p><h4>Create a GitHub Repository</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/0*g-0C3bZQdnbCOBbu.png" /><figcaption>Reference Architecture</figcaption></figure><p>Create a GitHub repository to store your codes. Go to <strong>GitHub Homepage</strong> and <strong>select New.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yeEWFlHy96XlXSKjPcjLGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjLv42U4sHiitO6p7oEtGg.png" /></figure><p>After creating the repository, go to SSH tab and click the copy icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1gJWFx0abemcN3ARhAn1ig.png" /></figure><p>Open your terminal in my case it’s Windows PowerShell.</p><blockquote>PowerShell always opens to your home directory. If you want to clone your repository in a different directory, first you need to change to that directory.</blockquote><p>To clone the repository we just created in this directory, run git clone &quot;url of the repository&quot; You can verify this by going to your file explorer and follow the path PS C:/Users/Dell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qeD5gnoPg9NlhBgQ1BVQ-Q.png" /></figure><h3>17. Adding the Application Code to the GitHub Repository.</h3><p>We have created the repository where we will use to store our application code and we cloned that repository on our computer.</p><p>We will add our application code into that repository and we will push the changes back to GitHub. Take note of the 2 folder names because we will need them when we build our docker image.</p><p>We have a zip folder called rentzone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*nHzZ_jjPmXpEl53qskku_g.png" /></figure><p>In the folder, we have the unzipped version which is also called rentzone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4NGarOQGSUkj-KU8ylu1Q.png" /></figure><p>Let’s go back to the zip folder and copy it. Go to the directory where we cloned our repository. Paste the application code here.</p><p>Let’s open that repository in visual studio code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*isQYycc1JFESy58nibwWng.png" /></figure><p>Push this zip file into the repository in GitHub. We now have the rentzone.zip file in the application-codes repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RFP3vo5ljrG1CeyBiHKEg.png" /></figure><h3>18. Creating a Repository to Store the Dockerfile</h3><p>We will create another repository that we will use to store our Docker file. Afterwards, we will clone that repository on our computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*ZaJ4JFIJgD85S2M_2ISPnw.png" /></figure><p>Similar to the steps we did previously, create a new repository using your preferred repository name. In my case, docker-projects.</p><p>We’ve successfully created our repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M05gjAzQf-q5ztyiFnDsdw.png" /></figure><p>Up next, follow the steps that we did previously to clone the repository on our computer.</p><h3>19. Creating a Personal Access Token</h3><p>We will create a personal access token and docker will use this to clone the application code repository where we’ll build our docker image.</p><p>In your GitHub account, go to profile, select settings then go to developer settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VFJsWB34JdX0DM60FKpAXA.png" /></figure><p>Click on personal access tokens and select tokens (classic).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pm7Bj7DC0tQrARG9DAJNtg.png" /></figure><p>Click on generate new token then generate new token (classic). You may be asked to confirm access.</p><p>Provide your token name. Select an expiration date, select repo and click generate token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*avsBcZPGD5tOGBtzpbXR1g.png" /></figure><p>We’ve successfully created a personal access token that docker will use to clone the application code’s repository.</p><p>Leave the page by clicking tokens (classic). You can view the personal access token we just created including its expiration date.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LhTDnK2t64Id6SkFFs-PKA.png" /></figure><h3>20. Adding Build Arguments and Environment Variables to a Dockerfile</h3><p>We will learn how to properly pass secrets to our dockerfile. To start, create a Dockerfile in the rentzone folder. You can access the reference file I created and paste it here. You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Afterwards, save all your file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XKjAxPy8NkLtjp3Jvne6OA.png" /></figure><p>This is the dockerfile that we will use to build our image. I added some build arguments (line 53 to 63). I also added some environment variables (line 65 to 75). Please don’t edit it yet.</p><h4><strong>Build Arguments</strong></h4><p>The build arguments allow us to build our image locally so that we can push it to amazon ECR. We created build arguments for all the values we don’t want to hard code in this Dockerfile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*DFfEGd-SR4yMPjBHQSaryQ.png" /></figure><p><strong>Environment Variables</strong></p><p>We set each build argument to an environment variable.</p><p>Here’s an example:</p><p>This build argument ARG PERSONAL_ACCESS_TOKEN is equivalent to this environment variable ENV PERSONAL_ACCESS_TOKEN=$PERSONAL_ACCESS_TOKEN</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*a0Vv2dbAQREEATUsnSR-GA.png" /></figure><p>After we set each build argument to the environment variable, we can now use the environment variable in our Dockerfile instructions.</p><p>Here’s an example:</p><p>Note the instruction on line 78.</p><ol><li>Instead of hardcoding/entering our personal access token directly, we are now using the environment variable, personal access token.</li><li>Instead of hardcoding/entering our GitHub username directly, we are now using the environment variable, GitHub username.</li><li>Instead of hardcoding/entering our repository name directly, we are now using the environment variable, repository name.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*7WZFEH6o5mIM5lRNrAS1Ig.png" /></figure><p>We pretty much did the same thing for all value we don’t want to hardcode on the Dockerfile.</p><p>This is how you can use build arguments and environment variables to pass secrets to a Dockerfile.</p><p>Let me explain about build arguments further.</p><p>Going back to line 78, before we can push our image to amazon ECR we need to build the image locally and when we do, docker still needs the information for our personal access token, GitHub username, and repository name to clone our repository.</p><p>If we don’t include these information when we build our image locally, the build is going to fail. So while you are building your image locally, the build argument allows you to specify the value of your personal access token, GitHub username, repository name, and all the other build arguments you have specified on the Dockerfile.</p><p><strong>Line 66</strong> — we set our build argument to the environment variable. So if I reference the build argument on line 78, that means it denotes environment variable.</p><p>Moreover, the values that we’ve specified for our build arguments while building our image locally, will be only be available to the Dockerfile during the build process and they will be not included in the final image that we built.</p><p>Let’s use the personal access token for example. When we specify the value of our personal access token while building our docker image locally, the value of the personal access token and other build arguments will only be available to help us build our image. Once we have built our image you will no longer see these values on the image we built. On the other hand, the environment variables will be available to the ECS containers we ran from the built image. When we create our task definition in ECS later on, the environment variables that we have set here, we will set the same environment variable in ECS and we’ll be able to add the actual values that we want.</p><p>This is how you use build arguments and environment variables to pass secrets to your Dockerfile. Please do not edit this file yet.</p><h3>21. Creating a Script to Build the Docker Image and creating a Git</h3><p>Now that we’ve created our Dockerfile, we’re going to write a simple script that we’ll use to build our docker image.</p><p>You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Use the build_image.ps1 if your using windows computer and use build_image.sh if you are using Mac.</p><p>In the rentzone folder, create a new file build_image.ps1. This is the name of our script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OEY1kOqWwC2b0JOiffm18A.png" /></figure><p>In the build_image.ps1 reference file on GitHub, copy all the parameters and paste them here.</p><p>This is the PowerShell script that we will use to build our image and we only have one command — docker build. followed by our build arguments. For every build arguments we’ve listed in our Dockerfile, we need to enter the values here.</p><p><strong>Line 3</strong> — after the = add a ’ then provide your personal access token.</p><p><strong>Line 4 </strong>— after the = add a ’ then provide your GitHub username.</p><p><strong>Line 5</strong> — after the = add a ’ then provide your repository name, Application-Codes.</p><p><strong>Line 6 </strong>— the name of the zip folder that contains our application code, rentzone.zip. After the = add a ’ then enter rentzone.zip.</p><p><strong>Line 7</strong> — this is our web file unzip, after the = add a ’ then enter rentzone.</p><p><strong>Line 8</strong> — we registered a domain name earlier so after the = add a ’ then enter your domain name.</p><p><strong>Line 9 </strong>— after the = add a ’ then provide the RDS endpoint of your database instance. You can find this under the connectivity &amp; security tab of your RDS instance in your AWS account.</p><p><strong>Line 10 </strong>— after the = add a ’ then provide the RDS DB Name. You can find this under the configuration tab of your RDS instance in your AWS account.</p><p><strong>Line 11 </strong>— after the = add a ’ then provide your RDS master username. You can find this under the configuration tab of your RDS instance in your AWS account.</p><p><strong>Line 12 </strong>— after the = add a ’ then provide your RDS DB password.</p><p><strong>Line 13</strong> — this is the tag name that we want to give to our image. Since this application is called rentzone, I will tag this image rentzone. Replace the value &lt;image-tag&gt; with rentzone</p><p>This is all that we need to to create the script that we will use to build the docker image.</p><p>This is how our build_image.ps1 should look like. Go ahead and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CUNmjKw6Xj4sl2_D3NW4Hw.png" /></figure><p>Please remember that our script contains sensitive information such as our personal access token. We don’t want to commit this script to our GitHub repository so we need to add this to our <strong>.gitignore</strong> file.</p><p>To create a Gitignore file, right click on any open space below and type .gitignore you should see the Git logo beside it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*hOYurx0RK36t2wJtRxCBNw.png" /></figure><p>Next, we will add these script to our .gitignore file. Right click on the buil_image.ps1 script and select rename so we can copy it.</p><p>Paste it in the .gitignore file</p><p>Let’s save it all again. Notice that our script is no longer tracked.</p><p>Go ahead and push our changes to our GitHub repository.</p><h3>22. Making Script Executable</h3><p>We will make the shell script file that we created previously (to build our docker image) executable. You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Use the commands.txt file.</p><p>If you are using a windows computer, you will run this command Set-ExecutionPolicy -ExecutionPolicy unrestricted in PowerShell as an administrator. If you are using a Mac computer, you will run this command chmod +x build_image.sh in the same directory your shell script file is located in.</p><p>To make the shell script file executable on your windows computer, run Set-ExecutionPolicy -ExecutionPolicy unrestricted in Power Shell. Enter Y after the confirmation message and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*9og1IEJP2nfNOxnk.png" /></figure><p>Run PowerShell as an administrator</p><p>This is how you make a shell script file executable on a windows computer.</p><h3>23. Building the Docker Image</h3><p>Now that we have made the shell script file executable, we will run the shell script file to build our docker image. Right click on the shell script file (build_image.ps1) and select open in integrated terminal.</p><blockquote>When you right click on the shell script file and select open in integrated terminal, it is going to open the terminal in the same directory as the shell script file because in order to run the shell script file we need to be in the same directory.</blockquote><p>To run the shell script file to build our image run .\build_image.ps1 We are running the shell script file and it is now building the docker image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GxsZfm0Ktgv6JRl58gTCNA.png" /></figure><p>We have successfully built the docker image. The blue output corresponds to each instructions on our Dockerfile. It also indicates that each instruction ran successfully when we built the docker image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uw6t75-HdvHdijsOYa6uTw.png" /></figure><p>To see the image run docker image ls and you will see the image that we just built. The tag we gave that image is rentzone. It has the image ID and created few minutes ago.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_OmfBQnZQZAFBgJgad6gWw.png" /></figure><p>This is how you use a shell script file to build a docker image. Up next, we will push the image we just built to Amazon ECR.</p><h3>24. Installing the AWS Command Line CLI</h3><p>We will install the AWS command line on our computer.</p><blockquote>For details on how to install the AWS command line on your windows computer, visit AWS documentation <a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html"><strong>here</strong></a>.</blockquote><h3>25. Creating an IAM User with Programmatic Access</h3><p>The next thing we will do is push the container image we created to the elastic container registry in our AWS account. The ECR in AWS is similar to docker hub. It is a service that allows you to store your container images in AWS. To push the images that we created to ECR, we will create an IAM user with programmatic access then we will use the AWS CLI, user’s access keys, and secret access keys to authenticate with AWS in order to push the container images to ECR.</p><h4>Create IAM User</h4><p>We are going to create an IAM user with programmatic access. Docker will use this IAM user’s credentials to push the images to AWS ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gn_KdVPKCr6vQdhh82ZJkQ.png" /></figure><p>On the <strong>IAM dashboard</strong>, go to <strong>users then add users.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9DzNRG8rIUXCS6mIhNhogA.png" /></figure><p>Provide a <strong>name </strong>for your user and put a <strong>check </strong>beside <strong>Provide user access to the AWS Management Console.</strong></p><p>Let’s leave the rest of the settings on this page to <strong>default </strong>and click <strong>next</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*TgtSCeImxBncdLgA.png" /></figure><p>Select <strong>Attach policies directly.</strong> Search and select administrator access in permissions policies and hit next. You can review the S<strong>ummary </strong>before <strong>Creating user.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*qKbNLvNbGHgbNPw_8zN5uQ.png" /></figure><p>After you created your user, Goto to User you created, click on it and toggle <strong>Security Credentials</strong> to create and download the <strong>csv file containing the access key and password.</strong> This is the only time that your credentials can be viewed or downloaded. You cannot recover it later. <strong>Please keep them private and in a safe place</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qKbNLvNbGHgbNPw_8zN5uQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*SH2Riuhq8_Ph3wND.png" /></figure><p><strong>Create access key</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*3Z_MSn6SSSS_4_7F.png" /></figure><p>Select <strong>Third-party service,</strong> check <strong>I understand the above recommendation and want to proceed to create an access key and click next.</strong></p><h3>26. Running the AWS Configure Command</h3><p>We will configure the access key ID and secret access key on our computer. Configuring the user’s credentials on our computer will allow us to authenticate with our AWS account programmatically.</p><p>Open the command prompt and run aws configure Enter your AWS access key ID followed by secret access key ID and default region name, us-east-1. Press enter after default output format.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/0*F2ySsPV6Al1kBuvJ.png" /></figure><p>I’ve included the location of the user’s credentials on my computer. Whenever you want to update your user’s credentials, you can either type AWS configure on the command prompt and enter the user’s access key ID and secret access key or you can come directly to this file and change it here then save the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jKvGpAbwCNMSOjr0V6yYvQ.png" /></figure><p>This is how you configure your user’s credentials on your computer and we will use this user’s credentials to authenticate with our AWS account programmatically.</p><h3>27. Create a Repository in Amazon ECR with AWS CLI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*I6kxeE5nxxwnwwha9cf_yw.png" /></figure><p><strong>Amazon ECR to store the Docker image</strong></p><p>Now that we’ve installed AWS CLI on our computer and created a user with programmatic access, we will use the AWS CLI command to create a repository in amazon ECR. This is the repository that we will use to store the docker image we built earlier.</p><p>You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub and use the commands.txt file.</p><p>Paste this command in your notepad because we will modify it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*Ei1wuttFLRXhQ1mW.png" /></figure><p>After updating our repository name and region where we want to create our repository in, our notepad should look like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*29r-X1l7l3-85eLw.png" /></figure><p>This is the AWS CLI command that we will use to create a repository in amazon ECR. Select all the command and copy it. Open your project folder. Right click on any file in your rentzone project folder then select open in integrated terminal.</p><p>Paste the CLI command here then press enter. If you get this output, it means that you have successfully created the repository in ECR. Let’ go to our AWS account to verify if the rentzone repository we created is there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*cpbfOL2WeVi89Tao.png" /></figure><p>There you have it, in the Amazon ECR dashboard under repositories, we have the rentzone repository we just created. Open it.</p><p>Up next, we will push the image we built previously into this repository.</p><h3>28. Pushing the Docker Image to the Amazon ECR Repository</h3><p>We will push our docker image to the amazon ECR repository that we created previously.</p><p>You can find my reference file in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub and use the commands.txt file.</p><p>Paste this command in your notepad or text editor because we will modify it.</p><pre># retag docker image <br>docker tag &lt;image-tag&gt; &lt;repository-uri&gt;</pre><pre># login to ecr<br>aws ecr get-login-password | docker login --username AWS --password-stdin &lt;aws_account_id&gt;.dkr.ecr.&lt;region&gt;.amazonaws.com</pre><pre># push docker image to ecr repository <br>docker push &lt;repository-uri&gt;</pre><p># retag docker image</p><ul><li>Specify our <strong>image tag</strong> (you can run docker image on your project folder under Dockerfile to see the tag image).</li><li>You can get the URI of your rentzone repository in your AWS account</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*FIaBVbZBmT-YbZkD.png" /></figure><p>Our first command should look like this. Open your terminal again under Dockerfile and run this command.</p><pre># retag docker image <br>docker tag rentzone 914269993146.dkr.ecr.us-east-1.amazonaws.com/rentzone</pre><p>We have successfully retagged our image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*pzc9HPorimq95wjp.png" /></figure><p>If you run docker image ls again, you will see the image we just retagged. This is the image that we will push to our Amazon ECR repository.</p><p># login to ecr</p><p>To push this image to Amazon ECR, we will log back in to our Amazon ECR. Update your &lt;aws_account_id&gt; and the &lt;region&gt; where your repository is in. The second command should look like this.</p><pre>aws ecr get-login-password | docker login --username AWS --password-stdin 614990794914.dkr.ecr.us-east-1.amazonaws.com</pre><p>Run this command in your project folder. If you get a <strong>Login Succeeded</strong> output that means we have successfully logged in to ECR.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*1hv-GV-VJ84fyGDF.png" /></figure><p>push the docker image to ecr repository</p><p>Now that we have successfully logged in to Amazon ECR, we’re going to run the third command to push the docker image to ECR repository.</p><p>Modify the repository URI and the full command should look like this.</p><pre># push docker image to ecr repository <br>docker push 614990794914.dkr.ecr.us-east-1.amazonaws.com/rentzone</pre><p>Run this command in your project folder. We are now pushing the Docker image that we created to the Amazon ECR repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*GcHsaiIL7xH0HuFh.png" /></figure><p>We’ve successfully pushed our Docker image into the Amazon ECR repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*yXIaURx5OFinMMi-.png" /></figure><p>Now let’s go to our Amazon ECR repository to verify if the Docker image is there.</p><p>There you have it, in the rentzone repository you can see the image we just pushed to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*BsUqOb-UfqBFmWXh.png" /></figure><p>This is how we push a Docker image that we built locally on our computer into Amazon ECR repository. Up next, the ECS Fargate service will use this image to run our containers.</p><h3>29. Migrate Database file (Rentzone MySQL)</h3><p>For details on how to migrate your database file, from <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%208%3A%20Launch%20the%20Setup%20Server"><strong>here</strong></a> all the way to <a href="https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372#:~:text=Part%2010%3A%20Use%20Flyway%20to%20migrate%20database%20into%20the%20RDS%20Instance"><strong>here</strong></a><strong>. </strong>Where I fully explained how to migrate your database via Flyway.</p><h3>30. Creating an Application Load Balancer</h3><p><strong>Application Load Balancer to distribute web traffic to the ECS Fargate tasks.</strong></p><p>Before creating the ALB we need to create the target group and when the ECS service creates our task, it will add those task to the target group then the ALB can route traffic to the task in the target group.</p><p>To create the target group, go to your EC2 dashboard and select target groups. Click create target group and refer to the settings below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvdSnZyQyVyXVZ4igJcriw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*zst7tAAV2J3CODmImhEBWQ.png" /></figure><p>We haven’t created the ECS service that’s why we don’t have any task to add to the target group. When we create our ECS service, it will automatically add those task to this target group.</p><p>Click create target group.</p><p>Now we can create the application load balancer. Select load balancer just right above target group then create load balancer. Please refer to the summary of settings below then click create load balancer. You can click view load balancer and wait until the state turns from provisioning to active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*HIN3pUFNclCzoOJ9.png" /></figure><p>This is all we need to do to create the application load balancer and the target group.</p><h3>31. Registering for an SSL Certificate in Amazon Certificate Manager</h3><p>We will register for a free SSL certificate from the AWS certificate manager. We will use this to encrypt the communications between the web browser and our web servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*UgOf7pdnb25ByxDb.png" /></figure><p>For our website above, the communication between the web browser and our website is not secure. We will use this SSL certificate to secure all communications between the web browser and our website — also referred to as encryption in transit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*f8WSVbsugZeHalZE.png" /></figure><p>Go to <strong>AWS Certificate Manager</strong> and <strong>Request a certificate</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*n2N8lHCf5n0LPvLS.png" /></figure><p>Choose <strong>Request a public certificate</strong> under <strong>Certificate type</strong></p><p>Enter your <strong>domain name</strong> and click <strong>Add another name to this certificate</strong></p><p>In the second certificate box, we are going to add a wildcard. Type <strong>*.</strong> followed by your domain name. We will leave the rest to their default settings then click <strong>Request</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*v7LeGNF1KQ9u-96E.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*iRw9d7R32OovOU-i.png" /></figure><p>Let’s <strong>View certificate</strong> after creating the request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*73pJ7pRyuTbX_qmr.png" /></figure><p>If your status says <strong>Pending validation </strong>this means you need to create a record set in Route 53 to validate that this domain name belongs to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*Ysc0sgd6hoscSGv5.png" /></figure><p>You will see that the <strong>Status </strong>of the <strong>Certificate</strong> is <strong>Issued. </strong>For the 2 domain names we requested the certificate for is now showing <strong>Success.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*vmVmOf78h_u5lFbU.png" /></figure><p>Good work! This is how you request a free certificate from <strong>AWS Certificate Manager.</strong></p><h3>32. Create an HTTPS Listener for the Application Load Balancer</h3><p>We’re going to create an HTTPS listener for our ALB to secure our website. Let’s go to the <strong>EC2 dashboard</strong> and head over to <strong>Load balancer</strong></p><p>Ensure that your load balancer name is selected then click the <strong>Listener</strong> tab then Click <strong>Add listener</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*-pF1zey3XNJHkUc6.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/0*QNY-3ZZ9aCYY_j1V.png" /></figure><p>Switch the protocol to <strong>HTTPS </strong>this is always on port <strong>443, </strong>Select <strong>Forward </strong>under <strong>Default actions </strong>and<strong> Target group</strong> will be <strong>Demo-TG</strong></p><p>Select your <strong>Default SSL/TLS certificate</strong> and click <strong>Add </strong>at the bottom right part of your screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/0*I_vMzXNM3NMKj_UH.png" /></figure><p>The HTTPS listener is added. Let’s edit the HTTP listener to redirect HTTP traffic to HTTPS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*sSEk2sw0_g7hE0kv.png" /></figure><p>Select the <strong>HTTP </strong>listener and <strong>Edit, Remove </strong>the <strong>Default actions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/0*kfEnbnsLlwi9-wXr.png" /></figure><p>Select <strong>Redirect </strong>under <strong>Default actions</strong></p><p>We are going to redirect it to <strong>HTTPS </strong>and enter <strong>Port 443. Save changes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*4_76KMlPDWMxHaG0.png" /></figure><p>We have successfully edited our HTTP listener to redirect traffic to HTTPS.</p><h3>33. Adding Environment Variables to a File</h3><p>We will create an environment file to store the environment variables we defined in our Dockerfile. When we created the Dockerfile, these are the environment variables we defined in it.</p><p>You can find the environment variables (rentzone.env file) that we will use in this lesson in my <a href="https://github.com/werkmanne/medium-post-files/tree/main/docker-rentzone">medium-post-files</a> repository on GitHub. Copy all the environment variables.</p><p>Let’s go to our docker project folder in visual studio code. Right click on your rentzone folder then select new file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*hPCTihCvG6z0muWilmCBzQ.png" /></figure><p>You can name your file any way you want just make sure it has the .env extension. Press enter after naming the file. There you have it, we’ve created the environment file that we will use to store the values for the environment variables we defined in our Dockerfile.</p><p>Paste the environment variables in rentzone.env.</p><p>Go ahead and add the values for this environment variables. To do this, we will use the build script file. Open both rentzone.env and build script files. You can split your screen into 2 (rentzone.env at your left and build script to your right).</p><p>All you have to do is copy each values of your build argument and paste it in their corresponding environment variable. Do not include the single quote. The personal token for example, select the value from your build script file do not include the single quote. Come back to your environment file and paste it beside personal access token. Please repeat the same process for the other environment variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3EZCPvCh1xTXBffpc8aYw.png" /></figure><p>This is all we need to do to create the environment file that contains the values for our environment variables.</p><p>Before we save this file, you will notice that Git is tracking this file, hence we don’t want Git to track this file. Just like what we did to the build script, this file also contains sensitive information that we don’t want to commit into our GitHub repository. The next thing that we need to do is add the rentzone.env file to the .gitignore file so Git can stop tracking it. Right click on the file name, select rename, and copy all of it. Click out of it. Select your .gitignore file, press enter, and paste the name of the file here.</p><p>After entering the file name in .gitignore, when we save this file you will notice that Git will stop tracking it. Go ahead and save all your work. Notice that Git has stopped tracking this file as it’s greyed out.</p><p>Let’s go ahead and push our updates to our GitHub repository. Select source control, select commit and enter your commit message — create env file Click commit, and sync changes.</p><p>That’s all we got to do in this lesson. We created an environment file that contains the values for our environment variables.</p><h3>34. Creating an S3 Bucket to Store the Environment File</h3><p><strong>AWS S3 to store files containing environment variables for the container.</strong></p><p>We will create an amazon S3 bucket. We’ll upload the environment file we created in the last tutorial into that S3 bucket and when we create the ECS task, it will retrieve the environment variables from the file in the S3 bucket.</p><p>To create the S3 bucket, search S3 in your AWS console and select it. Click create bucket. Give your bucket a unique name and we will create this bucket in US east region. Click create bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*G1D_9XOdCDdVIlb3.png" /></figure><p>We have successfully created an S3 bucket. Select this bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*Q5kFHpcayvF0-pK0.png" /></figure><p>Upload the rentzone.env file. Browse the location on your computer where you saved this file and click upload.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*pWXn9ygz9hmBRGHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*hBTFCOzng0NU8TU-.png" /></figure><p>We’ve successfully uploaded the file into the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*LZAdG1ak6dvYvGsh.png" /></figure><h3>Almost there! Stay positive!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*jo-AxtcbEu4lNW2p" /></figure><h3>35. Creating an IAM Role for the ECS Task Definition</h3><p><strong>IAM Role to grant permission for ECS to execute tasks.</strong></p><p>We will create an IAM role that the ECS service will use to access the environment file we uploaded into the S3 bucket previously.</p><p>In your AWS console or recently visited, search for IAM and select it then select create role. Please refer to the settings below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*trbiwx7Xq6_hN4-n.png" /></figure><p>Under use case, search elastic container service. Select elastic container service task. Click next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*9wc7B0yG9SDzQPCV.png" /></figure><p>In the search field search for and type it this way AmazonECSTaskexecutionrole and press enter. Select the search result by putting a check mark. Click next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*bmyJGHMetLJAiv-B.png" /></figure><p>Provide your role name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*JlQMilFT-m2R9mwB.png" /></figure><p>Under permissions and summary ensure that you have the AmazonECSTaskExecutionRolePolicy listed. Scroll down and click create role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*SKBPRYuROp1L3Tsu.png" /></figure><p>We’ve successfully created the role. Select it to open the role.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*kgKqcP43NBU2_Xqa.png" /></figure><p>We will add an inline policy to this role. This will allow the ECS service to access the environment file we uploaded into the S3 bucket previously.</p><p>Click add permissions then select create inline policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*A6dsyKQwrBcVzw2_.png" /></figure><p>Under select a service, type S3 then select S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*IVXsx5IKxJ9Xj8DH.png" /></figure><p>In the read option, click the drop down arrow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*BYE6EWwdMekj3yb3.png" /></figure><p>and select GetObject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*NtedJRx35-dDTqLG.png" /></figure><p>Click the drop down arrow beside resources. Click add arn. We will enter the bucket and object name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7y5YDXI_1KTQEv0h.png" /></figure><p>Go back to your Amazon S3 and locate the S3 bucket and object name that we uploaded earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*M0tnwJwGbd2wC7aX.png" /></figure><p>Enter the S3 bucket and object name then select add ARNs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*tAb7j_CKu4hAi_SH.png" /></figure><p>Click add more permisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*R3Kg9cMP4sGlr-nR.png" /></figure><p>Search S3 again and select it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7RW2mhPMXINwXZ6G.png" /></figure><p>In the read option, click the drop down arrow and search for GetBucketLocation, click to check it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*h3t5gSxiK1iJl0Eg.png" /></figure><p>Click the drop down arrow beside resources and select add ARN. Enter your S3 bucket name again then click add ARNs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*U-Dd722nGIyIzmHY.png" /></figure><p>These are the 2 inline policies we need to add to this role. Scroll up and select the JSON tab, this is what the policy looks like. Ensure that your policy looks similar to mine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*LTtpRJOU5pw1xv8N.png" /></figure><p>After reviewing the policy and you’re happy with it, click next. Provide your policy name then select create policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*sG-UVV7MNIvIAS6L.png" /></figure><p>We’ve successfully created an IAM role. Ensure that you have these 2 policies attached.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*4jpr69-9br9lt4aj.png" /></figure><p>If we click the + beside S3-Get-Object, it shows the policy where all we needed is to update the ARN (resource).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*8JoLXkr-zxOb8X5m.png" /></figure><h3>36. Creating an ECS Cluster</h3><p><strong>Amazon ECS to containerize the web application on the AWS cloud</strong></p><p>Now that we’ve set up everything we need for this project, we are ready to run the ECS task (ECS container).</p><p>To create the ECS task, first we need to create the ECS cluster. In your AWS console, search for elastic container service. Select create cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*dwXWT8BuLQWZrNCY.png" /></figure><p>Provide your cluster name and refer to the settings below. Ensure that you select our custom VPC including 2 private subnets (private app subnet in AZ1 and AZ2)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*8V59u-OFkQSz6FKP.png" /></figure><p>We will leave the rest to their default settings then hit create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*MKbr1kpxV_im5cJj.png" /></figure><p>We’ve successfully created the ECS cluster and this completes our steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*ZlV0I-K4iJ9vQIa5.png" /></figure><h3>37. Creating a Task Definition</h3><p>Up next, we need to create the task definition. It is the blue print that contains various parameters and settings for a container. For example, in a task definition we would specify things such as the image that we want to use, the CPU and memory we want to allocate to the container, and the commands we want to run when the container is launched.</p><p>To start, in the ECS dashboard select task definition at the left menu. Click create new task definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*NM6vziAsCTei01u0.png" /></figure><p>Provide your task definition family name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*IHtCf_solK3lb3Xt.png" /></figure><p>Provide your container name. We will also enter the URI of the image that we will use to launch this container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*whABHY14VFaOZLQ0.png" /></figure><p>If you recall, we stored our rentzone image in a repository in amazon ECR. Just select repositories at the left menu to go to that repository. You can either click the copy icon beside copy URI or select the image tag name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*OnSjHteaydyo0YzG.png" /></figure><p>and copy the URI from here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*A4C0pTaoyjDn2rg5.png" /></figure><p>Under environment variables, this is where we will list our environment variables for this project and remember that we stored our environment variables in a file in the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*xBuyw5Dq7zK9uGPo.png" /></figure><p>To reference it, click add environment file. In the location field, we will enter the ARN of our environment file in the S3 bucket. Go to your buckets in your Amazon S3. Select the name of the bucket to open it (this contains your environment file). Look for the ARN and copy it. Paste it in the location field and click next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/0*9FvGvEVj4brLWsNI.png" /></figure><p>In the app environment, we’re leaving it to AWS fargate (serverless). In the operating system architecture, if you’re using windows select Linux/X86_64. If you build your image on a MAC computer use Linux/ARM64. Let’s leave the CPU and memoryto default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*Hv5qlJdfcg8H_HA5.png" /></figure><p>In the task execution role, select the Rentzone-ECS-Task-Execution-Role we created earlier. This role contains the inline policy that we will use to access our environment file in the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*uMGwMqh789ZDYu_a.png" /></figure><p>We will leave the use log collection to its default settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*t0F9N1n4FsSPELCk.png" /></figure><p>Review the summary of settings and if everything is correct, click create.</p><p>We have successfully created the task definition. This shows the name of the task definition and the current revision is 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*-kKr0Hc4UZhUjJ13.png" /></figure><p>By clicking task definition you can see the list of all your task definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*zQ4OxZZCBguXOmv2.png" /></figure><p>This is all we need to do for this part.</p><h3>38. Creating an ECS Service</h3><p><strong>ECS Fargate to run the containerized application.</strong></p><p>Now that we’ve created the ECS task definition, we will create the ECS service that will create the fargate containers.</p><p>On the amazon elastic container service console, select clusters at the left menu. Select the rentzone-cluster. Under services tab, click create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*SefF4P4Zp0Q-cvTK.png" /></figure><p>Under compute options in the environment page, select capacity provider storage. Under capacity provider strategy ensure that use custom is selected. We will leave the other options to their default settings. Scroll down.</p><p>Here in deployment configuration under application type, select service. Choose the task definition we created earlier under family. Ensure that its latest version is selected. Currently, we only have one version of our task definition.</p><p>Provide your service name. We’ll leave the service type to its default settings.</p><p>Under desired tasks, based on our reference architecture we want 2 containers running, hence we will select 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/0*ZMW70UpBkI3-0Iji.png" /></figure><p>We will leave the deployment option and deployment failure detection to their default settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*ebKf_hjGWMIh3r9j.png" /></figure><p>In the networking section, select our custom Dev-VPC. Include the private app subnet in AZ1 and AZ2. We will only use the container security group. Its crucial to disable the public IP because our container is going to be in the private subnet, hence it shouldn’t have a public IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/0*DItwkQRQjrVlZZ-E.png" /></figure><p>Let’s go now to the load balancing section. Under load balancer type, select application load balancer. We will use an existing load balancer, hence our Dev-ALB. Leave choose container to load balance to default settings. We will also use an existing listener, hence select port 80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/797/0*VGvcn-Lfi4PJ4jOr.png" /></figure><p>We will use our existing target group, hence Dev-TG</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/0*AhoImp9lm0mTPw3Q.png" /></figure><p>This is how we’re going to add an auto scaling group to our ECS service. Check use service auto scaling. We want our minimum number of tasks/containers running 2 and maximum of 4.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7a2wyVbZk7JpFcL3.png" /></figure><p>Our policy name is rentzone-policy. The target value is going to be the average CPU utilization that ASG will use to decide whether to scale down or up our ECS tasks/containers. We will leave the rest to their default settings. Click create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*wY8Cjq1LnPRsMsFh.png" /></figure><p>We’ve successfully created the ECS service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*TIPvXaOYMpKOmaM0.png" /></figure><p>You should see the rentzone ECS service we just created under services tab. Select to open it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*Ib3xY7uBGub34QI0.png" /></figure><p>The health and metrics tab shows the status of our rentzone service. We have 2 healthy tasks/containers running. Select the target group link to open it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*vvqQ9-4Lg05Tph4V.png" /></figure><p>The Dev-TG shows 2 healthy targets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*py3gKfjMb-Vk7eIc.png" /></figure><p>You can also see the targets here if you scroll down. These are the 2 ECS fargate containers we just launched.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*kmznaNnQzFlFpBJ5.png" /></figure><p>Going back to the ECS window, click logs. When the ECS service starts running the containers, this window will show any errors it encounters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*LPMt1owGLoYq2qrL.png" /></figure><p>The configuration tab further shows the information of the rentzone-service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*pI5ANDCKO7tuF-ks.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*xBNn_YiEHPw32azT.png" /></figure><p>The deployments tab shows the information about deployment as well as the events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*pHMAT8oe1vapZZFp.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*hJKe8N6gU0ACVwor.png" /></figure><p>The networking tab shows our VPC, subnets, security groups, IAM role, and load balancer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*GSOjIyw4QwqwbZsQ.png" /></figure><p>Going back to our rentzone-cluster, we have 1 service</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*w7_fZ3fZTdnylGv6.png" /></figure><p>and we have 2 healthy tasks/containers running. These are the tasks that was created by our service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*V69_LWL5Cdq0-8VH.png" /></figure><p>In order for us to see the application we’ve deployed on the fargate containers, in the next tutorial we will create a record set in the route 53 hosted zone. This way the end users will be able to use our domain name to access the application.</p><h3>39. Create a Record Set in Route 53</h3><p>We will create a record set in Route 53 to access our website using our domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7FdRuDg2uzww4z1b.png" /></figure><p>To create a record set in Route 53, go to the <strong>Route 53</strong> dashboard. Select <strong>Hosted zones </strong>and click your <strong>Domain</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*eonNQtedk5PI9eMe.png" /></figure><p>Click <strong>Create record</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*kexqRZ7UsFv9MOPv.png" /></figure><p>Enter the information below then hit <strong>Create records</strong></p><p>Record name: www</p><p>Route traffic to:</p><ul><li>Alias to Application and Classic Load Balancer</li><li>US East (N. Virginia) [us-east-1]</li><li>Demo ALB</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*cPjszE89mtb5ZJlP.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*THx8F_KDwA4YZfvG.png" /></figure><p>We have successfully created a record set.</p><p>Select the <strong>Record name</strong> and copy the <strong>Record name</strong> to your right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*wZw2qLVCma5WlXF4.png" /></figure><p>Open a browser and paste the record name here.</p><p>There you have it! We can now access the application we deployed on ECS fargate containers and the communication between the end users and our application is also secured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*IfnyQ4KXzsDh9EZj6KdpTA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*sUrgM0_SCMjSq_H0A_Kykg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*ZmHMLG6b40ekvV-zEJjVUw.png" /></figure><h3>40. Cleaning Up Your ECS Project</h3><p>We have successfully deployed our application on AWS using docker, amazon ECR, ECS and various core AWS services. On my next project, we will deploy the same application on AWS using terraform.</p><p>Let’s start destroying the resources we created in this project to avoid further usage costs.</p><p><strong>Elastic Container Service</strong></p><p><strong>Task/Container</strong></p><p>Select the rentzone-cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*veJKMN3wGi_NnEW9.png" /></figure><p>Under services, select the rentzone-service and select delete service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*paRPgh2Cp0CKVvfF.png" /></figure><p>Check force delete service, type delete in the box then click delete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/743/0*GJRmGYUJ_yubtC1b.png" /></figure><p>We’ve successfully deleted the task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*7VOdwD9brGFexCm8.png" /></figure><p><strong>ECS Cluster</strong></p><p>Select the rentzone-cluster and delete cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*LIy8QEBegkWsfqQt.png" /></figure><p>Enter the phrase to confirm deletion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/0*jmZfRhiROG_2KDL7.png" /></figure><p>We’ve successfully deleted the rentzone-cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*XU_aLhKkGS6nPZ47.png" /></figure><p><strong>Task Definition</strong></p><p>Select the rentzone task definition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*MhmG4fHhCnndQwbG.png" /></figure><p>Click actions then deregister.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*uvCNfKcbm0ruWZBW.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/0*JbgcTkOGdBsE-2ZO.png" /></figure><p><strong>Application Load Balancer</strong></p><p><strong>Target Group</strong></p><p><strong>RDS Instance</strong></p><p>After selecting DB Instances, select your RDS instance.</p><p>You might need to disable the deletion protection found in the configuration tab. Click actions and click delete. We will create a final snapshot of our database so its crucial that you<strong> tick create final snapshot</strong>. Provide your snapshot name then hit the delete button.</p><p><strong>CloudWatch</strong></p><p>Select the log group that the ECS has created the select actions, and click delete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*F_aOmBCRpwJGRgcN.png" /></figure><p><strong>Record Set</strong></p><p>We are deleting the A record which has the www followed by your domain name.</p><p><strong>Security Groups</strong></p><p>Let’s delete the security groups in this order</p><ol><li>Database</li><li>Container Security Group</li><li>Bastion Host Security Group — you must terminate the Bastion Host first</li><li>ALB Security Group</li></ol><p><strong>NAT Gateways</strong></p><p>Let’s delete the NAT gateways in this order.</p><p>NAT Gateway AZ1</p><p>NAT Gateway AZ2</p><p><strong>Elastic IP Addresses</strong></p><p><strong>Amazon RDS Subnet Groups</strong></p><p>Going back to amazon RDS, select your database subnet group and click delete.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*NRbfjIlBPGUvbouk.png" /></figure><p><strong>VPC</strong></p><p>Select the custom VPC that we created for this project.</p><p>These are all the resources that will be deleted, click delete.</p><p><strong>Congratulations</strong> and thank you for following along. I hope you find this valuable in your journey. Let me know if you have any questions and I look forward to see you on my next project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*kRbuJrpvsEeTXadE" /></figure><p>Build real-world projects with me <a href="https://www.aosnote.com/a/2147524876/WLBooyWz">here</a>! Show your employers that you are the right person for the job and stand out from the crowd!</p><p>Connect with me on <a href="https://www.linkedin.com/in/bello-afeez/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3d1a4fab96d6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Host a Dynamic Web Application on AWS (Nestapp)]]></title>
            <link>https://medium.com/@werkjober/host-a-dynamic-web-application-on-aws-nestapp-dbca29a55372?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbca29a55372</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[vpc]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Thu, 05 Oct 2023 14:38:34 GMT</pubDate>
            <atom:updated>2023-10-05T14:38:34.991Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ll guide you through the process of setting up a highly available and fault tolerant <strong>Dynamic Web-app</strong> on AWS using the management console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*us1Yzt4Djxi848jP1RzQFw.png" /></figure><h3>Introduction</h3><p>I’m excited to have you here again as we embark on our next real-world project. In this journey, we’ll delve into the deployment of a dynamic web-app on AWS. Throughout this endeavor, we’ll explore the utilization of my reference architecture to host the website, leveraging a variety of AWS services and understanding how they seamlessly collaborate.</p><ul><li>VPC with public and private subnets</li><li>Security groups</li><li>EC2 instances</li><li>NAT gateways</li><li>EC2 Instance Endpoint Connection — EICE</li><li>RDS</li><li>Application load balancer</li><li>Route 53</li><li>Auto scaling group</li><li>Certificate manager</li></ul><h3>Objective</h3><ol><li>Build a three-tier AWS network VPC from scratch</li><li>Create NAT gateways</li><li>Create the security groups</li><li>Launch a MySQL RDS instance</li><li>Create S3 bucket and upload file</li><li>Create an IAM role with S3 policy</li><li>Launch the setup server</li><li>SSH into an instance in the private subnet</li><li>Use Flyway to migrate the SQL database to RDS Instance</li><li>Install a dynamic website on an EC2 instance <strong>LAMP Stack</strong></li><li>Create an application load balancer</li><li>Register a new domain name in route 53</li><li>Create a record set in route 53</li><li>Register for an SSL certificate in AWS certificate manager</li><li>Secure the website with ACM SSL certificate</li><li>Create AMI</li><li>Create auto scaling group</li><li>Clean up</li></ol><h3>VPC Reference Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MsCerkcnKzdw5lxB6LoLTQ.jpeg" /></figure><ol><li><strong>VPC</strong> with public and private subnets in 2 availability zones</li><li>An <strong>internet gateway</strong> is used to allow communication between instances in VPC and the internet</li><li>We are using <strong>2 availability zones</strong> for high availability and fault tolerance</li><li>Resources such as NAT gateway and application load balancer use <strong>public subnets.</strong></li><li>We will put the web servers, eice and database servers in the <strong>private subnets</strong> to protect them</li><li>The <strong>public route table</strong> is associated with the public subnets and routes traffic to the internet through the internet gateway</li><li>The <strong>main route table</strong> is associated with the private subnets</li></ol><p>We will commence by establishing a custom <strong>3-tier VPC</strong> using the architecture mentioned above. In this 3-tier architectural model, our infrastructure is categorized into three distinct tiers.</p><p>Firstly, in <strong>Tier 1</strong>, we will establish the public subnet, where resources like the NAT gateway, load balancer will be located.</p><p>Secondly, in <strong>Tier 2</strong>, we will set up the private subnet, where our web servers (EC2 instances), EICE will reside.</p><p>Lastly, in <strong>Tier 3</strong>, we will create another private subnet designated for our database.</p><p>To enhance high availability and fault tolerance, we will replicate these subnets across multiple availability zones.</p><p>As a final step, we will establish an internet gateway and configure a route table to enable internet access for the resources within our VPC.</p><p>Let’s get started!</p><h3>Part 1: Build a Three-Tier AWS Network VPC from Scratch</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCQzHA1USgwKLryIvGTEgw.png" /></figure><h3>VPC</h3><p>In the management console, select the region where we want to create our VPC. According to our reference architecture we need to create this VPC in the N. Virginia region.</p><p>Either select VPC from the console or type VPC in the search bar above.</p><p>In your VPC dashboard select VPCs or the Create VPC orange box</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Kg1VOZNcZ6dTX-A1.jpeg" /></figure><p>Let’s give our VPC a name. Let’s select VPC only and call it Demo VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/0*l1i5ldC6mM7fyAw_.png" /></figure><p>According to our reference architecture, we will assign the IPv4 CIDR block of 10.0.0.0/16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/0*_kVeNggJcMYuARm8.png" /></figure><p>We will keep the IPv6 CIDR block and Tenancy settings at their default values. Now, let’s proceed by clicking the “Create VPC” button located at the bottom right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/0*dnFZGfaKNgEdfY7A.png" /></figure><p>It will give us a <strong>successfully created</strong> message and You can view all the VPCs that have been created by clicking the drop-down arrow in the “Select a VPC” box. Please select the VPC we just created from the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RC_FkqGaMFyaeTUd.png" /></figure><p>Let’s enable the DNS host name in our VPC by selecting <strong>Actions </strong>and <strong>Edit VPC settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/0*FrJ8cODOTwTPBotI.png" /></figure><p>Under Edit <strong>VPC settings </strong>make sure that <strong>Enable DNS hostnames </strong>is checked then click <strong>Save</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*R5vOVtUQtnCaF_yz.png" /></figure><h3>Internet Gateway</h3><p>The next thing we are going to do is to create an <strong>Internet gateway </strong>for our VPC. You can find and select <strong>Internet gateway </strong>at the left side menu of <strong>Your VPC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*atVhc_m40zi1GLjW.png" /></figure><p>Let’s select <strong>Create Internet gateway, </strong>give it a name — <strong>Demo Internet Gateway </strong>and click <strong>Create internet gateway</strong></p><p>Now, we need to attach the internet gateway to the VPC we created earlier. This will allow the VPC to communicate with the internet.</p><p>Just simply click <strong>Attach to a VPC</strong> in the green banner above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/0*vVYBCpleqWdRODKR.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2zJnyy1LimRWZfGV.png" /></figure><p>Select the Demo VPC that we created and click <strong>Attach internet gateway. </strong>This is the only VPC that will show in your account this doesn’t have any internet gateway attached to it. We can only attach one internet gateway to one VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*uJhqZSJLSOC6IoKl.png" /></figure><p>We successfully attached the internet gateway to our VPC. The Details show the <strong>State </strong>and the <strong>VPC ID</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7dm84K78Yv2QK6QL.png" /></figure><h3>Public Subnets</h3><p>Let’s create our public subnets in the first and second availability zones. Ensure that its still filtered to our <strong>Demo VPC</strong> then click <strong>Subnets </strong>at the left side.</p><p>Once you are in the subnet page, click <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*3vPyOs51mM00rQI_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/0*AHOTwog6vLa6XWsQ.png" /></figure><p>Let’s select the VPC where we want to create our subnet in — let’s choose Demo VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*uHfMYx4KzI30OX48.png" /></figure><p>Let’s give our subnet a name. Based on our reference architecture, we will call it <strong>Public Subnet AZ1 </strong>and put this in the <strong>us-east-1a Availability Zone</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*ZIAeLeCmVHSTrwfD.png" /></figure><p>The <strong>CIDR block</strong> should be <strong>10.0.0.0/24 </strong>and click <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/0*6wL_Uije8v21xa8a.png" /></figure><p>We have successfully created our first public subnet in the us-east-1a Availability Zone.</p><p>Let’s create our second subnet in the us-east-1b Availability Zone and click the <strong>Create subnet</strong> button at the top right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*pC-WnQh1_mIJxGXk.png" /></figure><p>Select the same VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*WcCYghlZIVwIo63u.png" /></figure><p>Select and enter 10.0.1.0/24 in <strong>IPv4 CIDR block. </strong>Afterwards we can <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*S1aNgUTGsOW57LKp.png" /></figure><p>Select and enter 10.0.1.0/24 in <strong>IPv4 CIDR block. </strong>Afterwards we can <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*MvhkU53NCOlHHZ_3.png" /></figure><p>Great job! We have successfully created our second public subnet in the us-east-1b Availability Zone. If you select “Clear filters,” it will display the two subnets that we created in this region. Please make sure to filter it to your Demo VPC in order to view and populate these subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vmgiWrsI_J1C5PbJ.png" /></figure><p>Remember to check the following:</p><p>Public Subnet AZ1 is in us-east-1a AZ</p><p>Public Subnet AZ2 is in us-east-1b AZ</p><p>Moving forward let’s enable the <strong>Auto assign IP settings</strong> for these 2 public subnets. This means that anytime you launch EC2 instance in these public subnets, those EC2 instances will be assigned a public IPv4 address.</p><p>Let’s select <strong>Public Subnet AZ1</strong> click <strong>Actions </strong>and click <strong>Edit subnet settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*S2hMVfKzapsv9cQS.png" /></figure><p>Under <strong>Edit subnet settings and Auto-assign IP settings </strong>check the <strong>Enable auto-assign public IPv4 address</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*4ZNgF6TgjSIufEst.png" /></figure><p>Scroll all the way down and hit <strong>Save. </strong>We are going to repeat the same procedure for Public Subnet AZ2.</p><p>Next is we need to create a public route table. Based on our reference architecture, we will call this <strong>Public Route Table.</strong></p><p>Let’s click <strong>Route tables</strong> on the left side. The route table that we see was set up when we created the VPC. This is the main route table and its private by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nIT_Ls1IhI8Trz5q.png" /></figure><p>Click <strong>Create route table. </strong>We will call it <strong>Public Route Table. </strong>Make sure to select <strong>Demo VPC</strong> under <strong>VPC </strong>before clicking <strong>Create route table</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4_pqGn_vIWm78vSE.png" /></figure><p>We have successfully created our Public Route Table.</p><p>Let’s add internet gateway to the public route table. This will allow the route table to route traffic to the internet. First, let’s make sure that we are on the <strong>Routes </strong>tab then click <strong>Edit routes.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/0*2AMj7DRdy0mwAbYR.png" /></figure><p>Click <strong>Add route </strong>and to add a route that routes traffic to the internet to this route table, we will add <strong>0.0.0.0/0 </strong>under <strong>Destination </strong>and the Target should be the <strong>Internet Gateway</strong> we created. When this is all filled in we can click <strong>Save changes.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*0yUN7TJs7Q0bBy_A.png" /></figure><p>We successfully added a route to the internet to our public route table. You can see it under the <strong>Routes tab.</strong></p><p>Let’s associate the 2 public subnets we created earlier with this route table. Let’s ensure that we are still under <strong>Public Route Table.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qrauRKypnDk63a-T.png" /></figure><p>Click <strong>Subnet associations</strong> and click <strong>Edit subnet associations. </strong>On this page, we can see the 2 subnets that we created previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*GFS4EAECoRygIYn4.png" /></figure><p>Under <strong>Edit subnet associations </strong>select both Subnets and <strong>Save association.</strong></p><p>Good job! We have associated the 2 subnets that we created to the Public Route Table. These will now show under <strong>Subnet associations</strong> tab.</p><p>To finish creating our VPC we need to create 4 private subnets. So let’s click <strong>Subnets </strong>at the left side and <strong>Create subnet.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*EZlX9okIBWGVzUlW.png" /></figure><p>We will still stick to our <strong>Demo VPC</strong> under <strong>VPC ID</strong> and based on our reference architecture let’s name it <strong>Private App Subnet AZ1 </strong>and choose <strong>us-east-1a Availability Zone.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*K81cF0jzN3ccRDzt.png" /></figure><p>Our CIDR block should be <strong>10.0.2.0/24 </strong>and we are now ready to <strong>Create subnet.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/0*wTIhnTTstIxlC3iG.png" /></figure><p>There you go! We created our 1st private subnet in the us-east-1a Availability Zone. Doing the same procedures above let’s create the next 3 private subnets using the settings below and referring to our reference architecture:</p><p><strong>2nd Subnet</strong></p><p>VPC ID: Demo VPC</p><p>Subnet name: Private App Subnet AZ2</p><p>Availability Zone: us-east-1b</p><p>IPv4 CIDR block: 10.0.3.0/24</p><p><strong>3rd Subnet</strong></p><p>VPC ID: Demo VPC</p><p>Subnet name: Private Data Subnet AZ1</p><p>Availability Zone: us-east-1a</p><p>IPv4 CIDR block: 10.0.4.0/24</p><p><strong>4th Subnet</strong></p><p>VPC ID: Demo VPC</p><p>Subnet name: Private Data Subnet AZ2</p><p>Availability Zone: us-east-1b</p><p>IPv4 CIDR block: 10.0.5.0/24</p><p>We have successfully created all 4 subnets. To see these let’s click <strong>Clear filters </strong>and filter it by <strong>Demo VPC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i-vSFylraikSz9ly.png" /></figure><p>Before we proceed to Part 2 of our project, let’s review and confirm that we have correctly placed each subnet in the respective availability zones.</p><p>Additionally, it’s important to understand the distinction between public and private subnets. When we create a route table and configure it with a route to direct traffic to the internet, any subnet associated with that route table becomes a public subnet. In contrast, subnets without such routes remain private, typically used for resources that should not have direct internet access.</p><p>This differentiation is crucial for controlling network traffic and ensuring the appropriate level of security and access for your resources within the VPC.</p><p><em>To show you why these 2 subnets are public:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*PVUH7XYSD2AlZqqA.png" /></figure><p><em>and these subnets are private</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*8aRdxIRntEqAgt2T.png" /></figure><p>let’s look at the VPC we just created. To verify these, click on <strong>Route Tables and filter it by our VPC — Demo VPC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*71pfx_me6FZBg30x.png" /></figure><p>Let’s select <strong>Public Route Table </strong>and <strong>Routes </strong>tab, this route table is routing traffic to the internet. So any subnet we associate with this route table becomes public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*H_TBJw0L7YGEPI-C.png" /></figure><p>The <strong>Subnet associations</strong> tab shows that we associated both <strong>Public Subnet AZ1 and AZ2 </strong>to this route table. That is what makes these 2 subnets public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*YfJ0FZKwvu8tocV9.png" /></figure><p>On the other hand, let’s select the main Route Table. Uncheck the <strong>Public Route Table </strong>and select the main <strong>Route table — </strong>this was created when we created the VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rHH21kilPfkCGe3a.png" /></figure><p>The main Route table is private by default it is only routing traffic locally in the VPC and it doesn’t have a route to the internet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*4yes4j-VMOY3b3Rp.png" /></figure><p>Further, we created 4 private Subnets we did not associate them with any route tables. By default, they will be associated with the main Route table which is private. Going back to the main <strong>Route table </strong>under <strong>Subnet associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*2-hAoEnjVZtTf1Gw.png" /></figure><p>Let’s scroll down to <strong>Subnets without explicit associations. </strong>It says <strong><em>The following subnets have not been explicitly associated with any route tables and are therefore associated with the main route table.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*6nuuohoC2GFHPMcR.png" /></figure><p>On the next part of our project, we will create a NAT Gateway and private Route tables. We will explicitly associate our private subnet with our private Route tables but for now we will let the Private subnet be associated with the main Route table which is private by default.</p><h3>Part 2: Create NAT Gateways</h3><p>Certainly, before creating the NAT Gateway, it’s important to ensure that we are in the correct AWS region, which is N. Virginia (us-east-1), as this is the region where we previously created the VPC.</p><p>Once you have confirmed that you are in the correct region, we can proceed with the creation of the NAT Gateway in the first and second availability zones according to the reference architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mqSTah6ialedDDrG.jpeg" /></figure><p>To proceed with creating the NAT Gateway, please click on “VPC” in the AWS Management Console. You can select “NAT Gateways” from the list of options within the VPC dashboard to begin the process of creating NAT Gateways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*A79TpjTFEUGlVCWi.png" /></figure><p>We will create the first <strong>NAT gateway</strong> in the <strong>Public Subnet AZ1. </strong>We will call it <strong>NAT Gateway AZ1 </strong>and we will put this in the Public Subnet AZ1. We also need to click the <strong>Allocate Elastic IP button</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wOblTlQBZJ1IrIbW.png" /></figure><p>Now we are ready to click <strong>Create NAT gateway. </strong>It should bring us to the NAT gateway created successfully page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aUx94_WDkv5aNr4v.png" /></figure><p>Then we will follow the same step to create our <strong>NAT gateway AZ2 </strong>in the <strong>Public Subnet AZ2.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kymiOd4QtpsuRLau.png" /></figure><p>Next is we need to create a route table. We will call it <strong>Private Route Table AZ1. </strong>Select <strong>Route tables</strong> at the left side and hit <strong>Create route table.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/0*NEeJRdJTBjSWEX-a.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ZZ-g3vKTjEOJzobD.png" /></figure><p>We will call this <strong>Private Route Table AZ1</strong> in <strong>Demo VPC </strong>then hit <strong>Create route table</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zYjUzvEMQpIAPBXf.png" /></figure><p>The next page should say <strong>Route table was created successfully.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*fXgSu42baWobioh0.png" /></figure><p>Let’s add a route to the <strong>Private Route Table AZ1 </strong>to route traffic to the internet through the <strong>NAT gateway</strong> in the <strong>Public Subnet AZ1</strong></p><p>Under <strong>Routes </strong>tab click <strong>Edit routes </strong>then <strong>Add route</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*0Zr2VXagRKKeqsMX.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ZFBO5Ixn6iJSCacg.png" /></figure><p>Internet traffic is always <strong>0.0.0.0/0</strong> so we will select that as our <strong>Destination</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*mpDIfYe-G46D363m.png" /></figure><p>Our target will be <strong>NAT gateway</strong> and we need to select <strong>NAT gateway AZ1. </strong>We’re ready to click <strong>Save changes </strong>the next page shows <strong>Updated routes for Private Route Table AZ1 successfully</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Sj-eHb4Ou3LCdci3.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*C9ROhPtdV7Gju-S_.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*8Ifhw-a9b5BVyQbq.png" /></figure><p>Next we will associate <strong>Private Route Table AZ1</strong> with <strong>Private App Subnet AZ1</strong> and <strong>Private Data Subnet AZ1.</strong></p><p>Let’s click the <strong>Subnet associations</strong> tab and <strong>Edit subnet associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BOwGccldePbIYk-c.png" /></figure><p>From the list of available subnets below we need to select <strong>Private App Subnet AZ1</strong> and <strong>Private Data Subnet AZ1</strong> then click <strong>Save associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*bjG4Tzd4816aqh6W.png" /></figure><p>We have successfully associated <strong>Private App Subnet AZ1</strong> and <strong>Private Data Subnet AZ1 </strong>to the <strong>Private Route Table AZ1</strong> as shown under <strong>Explicit subnet associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cekNsjXoBzH-t930.png" /></figure><p>and Explicit subnet associations under <strong>Subnet associations</strong> tab</p><p>Now we will follow the same steps to create<strong> Private Route Table AZ2 </strong>and then add our <strong>NAT gateway AZ2 </strong>to route traffic for the <strong>Private App Subnet AZ2</strong> and <strong>Private Data Subnet AZ2.</strong></p><p>Good work! This is how we create NAT gateways to allow resources in the private subnet to have access to the internet.</p><h3>Part 3: Create Security Groups</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*r3e4s2bYA51prhsFPi-fVg.png" /></figure><h3>Security Group Reference Architecture</h3><p>These are the security groups that we need for this project.</p><p><strong>ALB Security Group</strong></p><ul><li>This is the security group that we will add to the application load balancer</li><li>Port: 80 and 443 with Source: 0.0.0.0/0</li></ul><p><strong>SSH Security Group — EICE</strong></p><ul><li>This is the security group that we will use to EICE to ssh into our EC2 instance in the private subnet</li><li>Port: Open outbound on 22 with Source: <strong>VPC cidr </strong>(10.0.0.0/16)</li></ul><p><strong>Webserver Security Group</strong></p><ul><li>This is the security group that we will add to the web servers in the private app subnets</li><li>Port: 80 and 443 with Source: ALB Security Group</li><li>Port: 22 with Source: SSH Security Group <strong>— EICE</strong></li></ul><p><strong>Database Security Group</strong></p><ul><li>This is the security group that we will add to the RDS instance in the private data subnet</li><li>Port: 3306 Source: Webserver Security Group</li></ul><p>Let’s head over to the console and create the security groups. We will use the information from the reference architecture above.</p><p>In the console home search and click VPC. At the left hand side click security groups</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*1XieI-pgjieIimjW.png" /></figure><p>Click create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*c1HjYrTPpcSKrB7k.png" /></figure><p>Enter the following settings</p><p><strong>Basic details</strong></p><p>Security group name: ALB Security Group</p><p>Description: ALB Security Group</p><p>VPC: Demo VPC</p><p><strong>Inbound rules — we will add 2 rules</strong></p><p><strong>1st rule</strong></p><p>Type: HTTP</p><p>Protocol: TCP</p><p>Port range: 80</p><p>Source: 0.0.0.0/0</p><p><strong>2nd rule</strong></p><p>Type: HTTPS</p><p>Protocol: TCP</p><p>Port range: 443</p><p>Source: 0.0.0.0/0</p><p>Once we opened the ports let’s click Create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ckkaeo2Pcc-1Ca4L.png" /></figure><p>We successfully created the ALB security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*PORylS_MIbGUxGev.png" /></figure><p>Let’s create the SSH security group. Click security groups to go back one directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*gzRKcehdYSnLGwOT.png" /></figure><p>Click create security group and enter the following settings</p><p><strong>Basic details</strong></p><p>Security group name: SSH Security Group — <strong>EICE</strong></p><p>Description: SSH Security Group</p><p>VPC: Demo VPC</p><p><strong>Outbound rules</strong></p><p>Type: SSH</p><p>Protocol: TCP</p><p>Port range: 22</p><p>Source: <strong>VPC CIDR</strong></p><p>This is the only rule that we need to add to our SSH security group let’s click create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ieqlZsnk63uPajja.png" /></figure><p>We successfully created the SSH security group -EICE</p><p>The next security group that we will create is web server security group. Click security groups to go back one directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/0*IA7VoDMdxTLT_Q9Y.png" /></figure><p>Click create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*sw2PqJSgLpl-ys0d.png" /></figure><p>Click create security group and enter the following settings</p><p><strong>Basic details</strong></p><p>Security group name: Webserver Security Group</p><p>Description: Webserver Security Group</p><p>VPC: Demo VPC</p><p><strong>Inbound rules</strong></p><p><strong>1st rule</strong></p><p>Type: HTTP</p><p>Protocol: TCP</p><p>Port range: 80</p><p>Source: ALB Security Group — this is how we limit a traffic to a particular security group</p><p><strong>2nd rule</strong></p><p>Type: HTTPS</p><p>Protocol: TCP</p><p>Port range: 443 — this is an internet traffic that is encrypted</p><p>Source: ALB Security Group</p><p><strong>3rd rule</strong></p><p>Type: SSH</p><p>Protocol: TCP</p><p>Port range: 22</p><p>Source: SSH Security Group -<strong>EICE</strong></p><p>This completes the rules that we need for our webserver security group. Click create security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*YGDnK481Vk4ePtBe.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*qrImNhnGtAhSW2Gj.png" /></figure><p>We have successfully created the web server security group. We also opened port 80 and 443 and limited the source to the application load balancer security group</p><p>Next is database security group. Enter the following information below then click <strong>Create security group</strong></p><p><strong>Basic details</strong></p><p>Security group name: Database Security Group</p><p>Description: Database Security Group</p><p>VPC: Demo VPC</p><p><strong>Inbound rules</strong></p><p>Type: MYSQL/Aurora</p><p>Protocol: TCP</p><p>Port range: 3306</p><p>Source: Webserver Security Group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*e-BBgBQ-8CyD7XRu.png" /></figure><p>You can review your security groups by going to security groups page and filter it to your Demo VPC. These are all the security groups that we need for this project.</p><h3>Part 4: Create the RDS Instance</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XizXoNPRnBtK2Ux-.jpeg" /></figure><p>We will create the RDS instance in the private data subnets. Let’s head over to the console, search <strong>RDS</strong> or select RDS in the <strong>Recently visited</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*9OcIBl6MxcQPxjEb.png" /></figure><p>Before we create the RDS instance in the private data subnets, the first thing that we need to create are the subnet groups — this allows us to specify which subnets we want to create our RDS database in.</p><p>Select <strong>Subnet groups </strong>and <strong>Create DB subnet group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*zWdAzj9XKJgZagu4.png" /></figure><p>Enter the following information and hit <strong>Create</strong></p><p><strong>Subnet group details</strong></p><p>Name: Database subnets</p><p>Description: Database subnets</p><p>VPC: Demo VPC</p><p><strong>Add subnets</strong></p><p>Availability Zones: us-east-1a and us-east-1b</p><p>Subnets: subnet with CIDR block 10.0.5.0/24 and subnet with CIDR block 10.0.4.0/24</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BY3a35_z95PsPbxc.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/0*otSArdC-lylf4xxW.png" /></figure><p>Let’s create the database. Select <strong>Database </strong>and click <strong>Create database</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*5JJmqTbNMyIl6FRX.png" /></figure><p>Enter the information below</p><p>Database creation method: Standard create</p><p>Engine options: MySQL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*6U5DAOwwQYx73npV.png" /></figure><p>Engine Version: MySQL 5.7.37 or latest</p><p>Templates: Dev/Test</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tvsRWLVAS-bLZ5Sk.png" /></figure><p>Availability and durability : Single DB instance</p><ul><li>According to our reference architecture, we can create a standby database in the other AZ. If you want to create a standby database in another AZ, you can select the <strong>Multi-AZ DB instance. </strong>For this project, so it won’t cost us money we won’t create a standby database</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*7PZEUmCbqwAgtVrL.png" /></figure><p><strong>Settings</strong></p><p>DB instance identifier: type a name for your DB instance</p><p>Credentials Settings: Provide your master username, password, and confirm password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*P1S9r00H5yCb1d9D.png" /></figure><p><strong>Instance configuration</strong></p><p>DB instance class: Burstable classes (includes t classes)</p><ul><li>select db.t2.micro</li></ul><p>Include previous generation classes: enabled</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*nVKbVkP0VLZdieIW.png" /></figure><p><strong>Connectivity</strong></p><p>Virtual private cloud (VPC): Demo VPC</p><p>DB subnet group: ensure that the 2 subnet group we created earlier are selected</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/0*TI6sKQYkSgmwDovY.png" /></figure><p>VPC security group (firewall): Choose existing</p><p>Existing VPC security groups: Databse Security Group</p><p>Availability Zone: us-east-1b</p><ul><li>This is where you choose the AZ you want to create the master database in</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*U9ZzNo6bMcHReZhV.png" /></figure><p>Database authentication: checked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*R2Lq5UW1SegtbGU3.png" /></figure><p><strong>Additional configuration</strong></p><p>Specify your <strong>Initial database name</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*lo8bmP72EFsKkEDt.png" /></figure><p>Scroll all the way down and click <strong>Create database. </strong>It will take a few minutes to create our RDS instance. Wait until the <strong>Status</strong> says Available</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*MfpZgy2Re-jjbaiT.png" /></figure><p>Once you’ve created your RDS instance, you won’t be able to see the password for the RDS instance in the management console. That is why it is important to save your credentials. You can click <strong>View credentials</strong> details above to view your credentials the last time.</p><p>Let’s go to <strong>DB identifier</strong> name</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*CUawfNan0_NSjBzr.png" /></figure><p>Under the <strong>Connectivity &amp; security</strong> tab is where we will find the endpoint for our database. We will need this information when we connect our database to our EC2 instance. You will find more information about our database below the <strong>Configuration </strong>tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*OVkfo3wMKKcNMrr8.png" /></figure><p>Well done! This is how we create an RDS instance with MYSQL engine.</p><h3>Part 5: Create EC2 Instance Connect Endpoint</h3><ol><li>Open the Amazon VPC console</li><li>In the left navigation pane, choose Endpoints.</li><li>Click on <strong>Create endpoint</strong>, and then complete the settings in the dialog box, as follows:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IOyxMiKNvGYoIfVW.png" /></figure><ol><li>(Optional) For the <strong>Name</strong> tag, enter a name for the endpoint.</li><li>For <strong>Service</strong> category, choose <strong>EC2 Instance Connect Endpoint.</strong></li><li>For <strong>VPC</strong>, select the VPC in which to create the endpoint.</li><li><strong>For Security groups</strong>, select the security group to associate with the endpoint. If you don’t select a security group, the default security group for your VPC will be associated with the endpoint. For more information, see Security Groups for EC2 Instance Connect Endpoint.</li><li>For <strong>Subnet</strong>, select the subnet in which to create the endpoint.</li><li>(Optional) To add a tag, choose Add new tag and enter the tag key and the tag value.</li><li>Choose Create endpoint.</li><li>The initial status is Pending. Before you can connect to an instance using this endpoint, wait until the status is Available. This can take a few minutes.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vy_SruWIWI5dU-nz.png" /></figure><p>Keep up the good work! Our next step is creating S3 buckets</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*kpqoMfOZPSEAItDe" /></figure><h3>Part 6: Create S3 bucket and upload file</h3><ol><li>We will create an S3 bucket and upload our Nest-app application code, SQL Database and App Service Provider file.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z1zgPxoSyLtO-ZkKiZ3QUA.png" /></figure><p>This is the file containing the application code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*2JUuyjYmMngqdoRr.png" /></figure><p>From your <strong>management console &gt; Amazon S3 &gt; Create bucket</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w73L3ykMuu6dzSXYflFhoA.png" /></figure><p>Give your bucket a name. The first bucket we will create is where we will store the web files in. Make sure you have web files at the end so that you would know that this is the right bucket to store the web files in. Also, create a name different from mine. Ensure that you are in the right region. We will leave the rest of the settings to default<strong> &gt; Create bucket</strong></p><p>We’re going to see the bucket we just created here. Click on it <strong>&gt; Upload</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*df7Iw1AHQzdzi8akPPo1Rg.png" /></figure><p><strong>Locate the nest-app folder in your computer and drag or add it into the bucket &gt; Upload</strong></p><p>The web files are uploaded successfully into our bucket as shown in the <strong>Status</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qyWgSBrJHHgHblswL8sXPg.png" /></figure><p>In the S3 bucket, you can see the application code in there.</p><p>Repeat the same process to add the nest-app SQL database into s3 bucket.</p><h3>Part 7: Create an IAM Role with S3 Policy</h3><p>We are going to create an IAM role with S3 permissions policy and give it S3FullAccess policy.. This will allow our EC2 instance to download the web files from the S3 bucket we created previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*1oh_e9r10oe0SMdq.png" /></figure><p>Let’s go to the <strong>IAM dashboard &gt; Create role</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*M2yY8IQWSovZa3XI.png" /></figure><p>Choose <strong>AWS service &gt; EC2 &gt; Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*wED_sPnngnQ7SkRP.png" /></figure><p>Under Permissions policies, we will attach the S3 policy to this IAM role. Type <strong>AmazonS3FullAccess</strong> the same way I did <strong>&gt; Enter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*A4elBLsCdHZQlcJf.png" /></figure><p>Select <strong>AmazonS3FullAccess &gt; Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rQltt-T-B6Ka55fp.png" /></figure><p>Let’s provide a <strong>Role name &gt; Create role</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*2qez2pr0_4_reb3c.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*7OqTKkMJULj4l2Ug.png" /></figure><p>We have successfully created the IAM role and attached a permissions policy.</p><h3>Part 8: Launch the Setup Server</h3><p>In this part project, we will launch the EC2 instance in the private subnet AZ1. We will name this instance <strong>Setup Server</strong> and we will use this to accomplish 2 things:</p><ol><li>We will use the setup server to migrate the SQL database for our application into the RDS database using Flyway</li><li>We will use the setup server to install and configure our application</li></ol><p>To launch the EC2 instance, let’s go to the console. Either type EC2 in the search bar or select EC2 from your recently visited then select <strong>Launch instance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*D6dpYE6s3pNjeMRj.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eUYlZTjO_TQ0k19m.png" /></figure><p>On the <strong>Launch an instance page, </strong>enter the information below</p><p>Name: Setup Server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/0*fhQm0EbAh-zdcZM4.png" /></figure><p><strong>Application and OS Images (AMI)</strong></p><ul><li>click <strong>Quick Start</strong></li><li>select Amazon Linux 2 AMI Free tier</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*BOWB9pDFVcbO-z6D.png" /></figure><p>Instance type: t2.micro</p><p>Proceed without a key pair because we use the EICE we created to ssh into the setup server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*N6_1tMCuJ6g3eX64.png" /></figure><p><strong>Network settings</strong></p><ul><li>click <strong>Edit</strong></li><li>VPC: Demo VPC</li><li>Subnet: Private Subnet AZ1</li></ul><p><strong>Firewall (security groups)</strong></p><ul><li>Select <strong>existing security group</strong></li><li>We will use 3 security groups: <strong>SSH, ALB, and Webserver Security Group</strong></li><li>You can view them all by clicking the + icon</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/885/0*6UAsPfR537-zMJiZ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/0*AViNSK8N7n4rD8a7.png" /></figure><p>We will attach the S3 permission role we created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*TTPacJO-TF_FZf5B.png" /></figure><p>You can also view the summary of your instance at the right menu then let’s click <strong>Launch instance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/446/0*cwSJRWRmIIeur1mV.png" /></figure><p>We have successfully launched the EC2 instance. You can click the <strong>instance ID</strong> to view your instance. Wait until the <strong>Instance state</strong> says <strong>running</strong> and <strong>Status check</strong> shows <strong>Passed</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LN2xWC8OvEwxB9C5.png" /></figure><p>This is all that we need to launch the EC2 instance that we will use to install our dynamic web-app and migrate our database. Let’s head over to part 8.</p><h3>Part 9: SSH Into an EC2 Instance in the Private Subnet (Windows Users) with EICE</h3><p>To SSH into the setup server using EICE let’s select <strong>Setup Server</strong> from the <strong>Instances </strong>page and Copy the Instance Id</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yLJPknxFC7Z4lkZZ.png" /></figure><p>Open Powershell or CMD on your computer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lqEniKDOM_cxqb17.png" /></figure><p>Type this command: <strong>aws ec2-instance-connect ssh — instance-id &lt;</strong>*****&gt; and paste the instance id your copied earlier to replace *****.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JY_xyzCEhFKQvil3.png" /></figure><p>We are now ready ssh into our private instance<strong>. </strong>The first time you SSH into an EC2 instance you will see a prompt box, just <strong>type</strong> <strong>yes</strong> and <strong>press enter</strong> to continue</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wDACPa6V_BBd15cP.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2f8WBhpGVgcX72FM.png" /></figure><p>We have successfully SSH into our EC2 instance using EICE. Let’s head over to the next part of our project.</p><p>You know that we are in the private subnet by confirming the ec2-user ip displayed with the ip on the EC2 management console.</p><h3>Part 10: Use Flyway to migrate database into the RDS Instance</h3><p>After we successfully SSH into the Setup Server in the private subnet. We move to the root directory.</p><pre>sudo su</pre><p>We will download the flyway folder on our root directory paste this linux command.</p><pre>wget -qO- https://download.red-gate.com/maven/release/org/flywaydb/enterprise/flyway-commandline/9.22.2/flyway-commandline-9.22.2-linux-x64.tar.gz | tar -xvz &amp;&amp; sudo ln -s `pwd`/flyway-9.22.2/flyway /usr/local/bin </pre><p>After executing the Linux command we should check the flyway folder to be sure its downloaded on the machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/1*OD2Dw62LqTlpmUx07Kn-Dg.png" /></figure><p>We should see the latest version flyway downlead on the machine.</p><p>Next use the Linux command bellow to delete and create a new sql folder for the migration.</p><pre>cd flyway-9.22.2/<br>rm -rf sql/<br>mkdir sql</pre><p><strong><em>Note the flyway version will be the latest version when working on this tutorial.</em></strong></p><p>Go into the new SQL directory just you created and run this Linux command to download the nest-app SQL files from the S3 bucket.</p><pre>aws s3 sync s3://nest-app-database-file /home/ec2-user/flyway-9.22.2/sql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aYEISaayBVzDqPYaEGVhJg.png" /></figure><p>Move back to the Flyway directory to migrate the SQL file to the RDS instance. Note that all the parameter in the script are from the rds instance we created earlier.</p><pre><br>flyway -url=jdbc:mysql://applicationdb.clltdecxyfzo.us-east-1.rds.amazonaws.com:3306/demodb \<br> -user=bello \<br> -password=Icui4cyou \<br> -locations=filesystem:sql \<br> migrate</pre><p>Break down of the script.</p><p>RDS endpoint: applicationdb.clltdecxyfzo.us-east-1.rds.amazonaws.com:3306</p><p>DB Name: demodb</p><p>User: Master Username — bello</p><p>Password: Master Password</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwAjzKFJlHAZd3gwgCoMHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wOULmy7uRZMeyZpImD_UKw.png" /></figure><p>After running the command in Flyway directory you should database migration successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKjl1MGevW0uQ91Y953iuQ.png" /></figure><p>Good job we have successfully migrate our nest-app sql file the RDS Instance.</p><h3>Part 11: Install a dynamic website on an EC2 instance LAMP Stack</h3><p>We will use the setup server to install and configure our website. Make sure you are back to the home directory on our setup server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/0*81UbzGxC4zn4pp7Y.png" /></figure><p><strong>Type this command and press Enter.</strong> This will update the EC2 instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/0*C5nhKvBoDj40IQb0.png" /></figure><p>We’ve successfully updated the EC2 instance and the shell prompt is now available. Type clear to clear your screen</p><pre>sudo yum install httpd -y<br>sudo systemctl enable httpd <br>sudo systemctl start httpd</pre><p>The commands above install the apache server on the EC2 instance, press Enter after typing the command and wait to finish the installation. When you see this option <strong>sudo systemctl start httpd, </strong>press <strong>Enter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/0*JolOuxSq2c6YRyBo.png" /></figure><p>We have successfully installed apache on our EC2 instance. Clear the screen.</p><pre>sudo dnf install -y httpd wget php-fpm php-mysqli php-json php php-devel</pre><p>Type this command to install php 8.0 and its extensions</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-r1WWhLH0gT_kJRyemhiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oim04aJzemOw0hfPS5AP4g.png" /></figure><pre>sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm <br>sudo ls -lrt<br><br>sudo dnf install mysql80-community-release-el9-1.noarch.rpm<br>dnf repolist enabled | grep &quot;mysql.*-community.*&quot;<br>sudo dnf install mysql-community-server<br><br>sudo systemctl start mysqld<br>sudo mysql -V</pre><p>Let’s run this command to install mysql version 8.0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/1*bBLdnGCsEHkK4jU_2ChAPw.png" /></figure><p>Press Enter when you get this option and you should see the shell prompt. We have successfully installed mysql version 8.0</p><p><strong>Enable PHP_CURL Module</strong></p><pre>sudo sed -i &#39;s/;extension=curl/extension=curl/g&#39; /etc/php.ini</pre><p>Open your php configuration file php.ini and change the following settings.<br>i. memory_limit = 128M<br>ii. max_execution_time = 300</p><pre>sudo nano /etc/php.ini</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*L7lJM4fwieOSWg1KDcUHqw.png" /></figure><p>Enable Mod rewrite</p><pre>sudo sed -i &#39;/&lt;Directory &quot;\/var\/www\/html&quot;&gt;/,/&lt;\/Directory&gt;/ s/AllowOverride None/AllowOverride All/&#39; /etc/httpd/conf/httpd.conf</pre><p>Restart the apache server</p><pre><br>sudo systemctl restart httpd</pre><p>This command will download the application code from the S3 bucket. Make sure you update the name of your S3 bucket before you run this command.</p><pre>sudo aws s3 sync s3://nest-app-web-files /var/www/html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s4uYYhSQn1K2BCZm6K3uhQ.png" /></figure><p>Copy the bucket name and update the bucket name in the command then press <strong>Enter</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*I7a_3k0YHCD4wWnKrKFHIA.png" /></figure><p>We have successfully downloaded the webfiles from the S3 bucket into the HTML directory on our EC2 instance. Clear the screen.</p><pre>cd /var/www/html<br>sudo unzip nest-app.zip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*iS0Gy-ElduZZMURyNM5UtQ.png" /></figure><p>The next command will change the directory to the HTML directory and we are going to unzip the zip file that we copied from our S3 bucket into the HTML directory. Press <strong>Enter </strong>after typing the command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*datkDDQgImWfmRsuNgPDZA.png" /></figure><p>If you type ls, you can see that there are 2 folders in our HTML directory. The red folder was the zip folder that we downloaded from our S3 bucket. Then we unzipped that folder to create the blue folder.</p><p>Move all the files and folder from the Nest App directory to the html directory</p><pre>sudo mv nest-app/* /var/www/html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Up6YpLGcg31b3mFKw2gvKQ.png" /></figure><p>We have successfully moved all the files from the blue folder into the HTML directory. If you type ls, we now have all the files from this blue folder in the HTML directory.</p><p>We also need to move some hidden files from the blue folder to our HTML directory. Type the command above and press enter. Clear the screen if you didn’t get any errors.</p><pre>sudo mv nest-app/.editorconfig /var/www/html<br>sudo mv nest-app/.env /var/www/html<br>sudo mv nest-app/.env.example /var/www/html<br>sudo mv nest-app/.gitattributes /var/www/html<br>sudo mv nest-app/.gitignore /var/www/html<br>sudo mv nest-app/.htaccess /var/www/html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PGz44JV66Sz4wfnE97-RjQ.png" /></figure><p>Let’s list the files in our HTML directory again, type ls and press enter. Now that we have moved all of our application code into the HTML directory, we no longer need the zip folder (red folder) we downloaded from S3 and the one we unzipped anymore.</p><pre>sudo rm -rf nest-app nest-app.zip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*C33zwcrSFXchHtU1DUdZTA.png" /></figure><p>After running the command, if you type ls again, you can see that we no longer have the zip folder we downloaded from S3 and the folder that we unzipped in our HTML directory.</p><p>This command will enable mod_rewrite on ec2 linux.</p><pre>sudo chmod -R 777 /var/www/html<br>sudo chmod -R 777 storage/</pre><p>These 2 commands will set permissions in our HTML and storage directory. Clear the screen after running the command.</p><p>Now that we have installed all the software that our application needs to function as well as setting the permissions on our HTML directory. The next thing that we need to do is configure our website by connecting it to our database.</p><pre>sudo vi .env</pre><p>For this application we are working on, to connect it to our database, we need to edit the .env file. Hence we will use the vi editor. Type the command above and press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/873/1*Thc8W8M3Fuk2YRKuQ5oCHQ.png" /></figure><p>Its going to open the env file in the vi editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/163/0*mPTm_r4QvJBOiivO.png" /></figure><p>We need to edit our database information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/118/0*eP48XhswFtBScOVO.png" /></figure><p><strong>Press I to go to the INSERT mode. </strong>You will see this at the bottom of your PowerShell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/161/0*p_njENc8ejXIubF2.png" /></figure><p>Using your down arrow key, press it until you reach the DB_HOST. Use to right arrow key to reach the end and delete all the numbers. Make sure to leave the = sign.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*Q1-5JYlrKBgyvFA1tuE0gQ.png" /></figure><p>Copy the Endpoint of your RDS instance and paste it in the DB_HOST.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/261/1*rAwiWt54irt6p9Ql3ttZNw.png" /></figure><p>Go to the DB_DATABASE= using your down arrow key and enter your database name from the RDS instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*pCI8CgopVYGlYQRXUZTb0w.png" /></figure><p>Enter your database username and password then press the <strong>Escape </strong>key.</p><p><strong>Type :wq! and press Enter. </strong>This is all that we need to do to connect our database with the application.</p><p>The next file that we need to update on our webserver is the AppServiceProvider.php file which is also in the HTML directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/0*fFdq1TEtoIlux5h9.png" /></figure><p>Type ls and press enter. The app is the next file that we need to update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/0*EOqUHlvKK4INOJae.png" /></figure><p>Type cd app and press enter. We are now in the app directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*kfOuNe0ScuWygyOlSU-1zw.png" /></figure><p>Run the ls command again and you will see that the file is the Providers’ directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/0*mKcLRHGpfwdvDV2b.png" /></figure><p>Run cd Providers/ and we are able to change our directory to Providers directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*DFs3Mj9CvI5OXlz-.png" /></figure><p>If you run ls, this is the file we want to update.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/0*7LCFxv4z180KamgI.png" /></figure><p>Type sudo vi AppServiceProvider.php (if you press the tab key it will auto complete it for you) then press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/985/0*pnY7q_h63Eby8JV1.png" /></figure><p>This is the file that we want to edit. Press I to go to the INSERT mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/208/0*IVeRSRV05ZAmVjtC.png" /></figure><p>Using your arrow keys, go just below public and bring our cursor beside the bracket, press enter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/0*7nb6b6M6ZzJ_ugRZ.png" /></figure><p>It should bring your cursor here</p><pre>if (env(&#39;APP_ENV&#39;) === &#39;production&#39;) {\Illuminate\Support\Facades\URL::forceScheme(&#39;https&#39;);}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/0*ad9ubv9KMfkNRjWe.png" /></figure><p>Let’s run this line of code. Remember to paste this line of code in the public function boot in the bracket under it. This is all we need to do update this file. <strong>Let’s press escape. Type :wq! and press enter.</strong></p><h3>Part 12: Create an Application Load Balancer</h3><p>Let’s create a target group then we will put these instances in the target group to allow the ALB to route traffic to them.</p><p>Click Target group at the left hand side</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/0*DBjSgRR-kMDFsrbr.png" /></figure><p>Enter the information below and click <strong>Next</strong></p><p>Target type: Instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*nPwLXJJZLHm_l0qG.png" /></figure><p>Target group name: Demo-TG</p><p>Protocol: HTTP</p><p>VPC: Demo VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*BHbfzhFq1Crn-dck.png" /></figure><p><strong>Advanced health check settings</strong></p><p>Success codes: 200,301,302</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*G-ZB2k-cETOusuiL.png" /></figure><p>On this page, we will select the instances we want the ALB to route traffic to. Pick <strong>Setup Server </strong>then click <strong>Include as pending below. </strong>Click <strong>Create target group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CaPMUvbLo_Z-dXrY.png" /></figure><p>We have Successfully created target group. The next step is we will create the ALB. At the left side select <strong>Load Balancers</strong> then <strong>Create load balancer</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*SjJVXIXDagCaP3NP.png" /></figure><p>It’s going to be <strong>Application Load Balancer</strong> and hit <strong>Create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/0*PEowhNPLjpVpfyWL.png" /></figure><p>Let’s enter the information below</p><p>Load balancer name: Demo-ALB</p><p>Scheme: Internet-facing</p><p>IP address type: IPv4</p><p>VPC: Demo VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TEvZpWBl__kIORTX.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bXrCY2P4g9nMteG_.png" /></figure><p>Under <strong>Mappings</strong>, we have to select at least 1 public subnet in each AZ for the ALB. First, let’s choose <strong>us-east-1a </strong>and select <strong>Public Subnet AZ1. </strong>Second, let’s select us-east-1b and choose <strong>Public Subnet AZ2</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*s-Z2GsYO1tvJvPhs.png" /></figure><p>Under <strong>Security groups</strong>, remove the default and select the <strong>ALB Security Group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*sHgpaHEFXu62OLRl.png" /></figure><p>We will set up a listener of port 80. Under <strong>Listener</strong> and <strong>Default action</strong>, we will select <strong>Demo-TG (this is the target group we created earlier). </strong>We will set up an HTTPS listener later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JizspCqUvxRM89QH.png" /></figure><p>Let’s click <strong>Create load balancer </strong>and we should get a successful prompt. Click <strong>View load balancer</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yrewWlTvHZOZw8Lo.png" /></figure><p>We will wait for its <strong>State</strong> to be <strong>Active. </strong>Then we will<strong> </strong>use the <strong>DNS name</strong> of the <strong>ALB </strong>to access the setup server to complete the installation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u7PgapAIJcCRh3c1.png" /></figure><h3>Part 13: Register a New Domain Name in Route 53</h3><p>We will register a new domain name in Route 53. This will allow our end users to access our website using that domain name instead of the DNS name of our application load balancer. View Miguel (Colleague) tutorial <a href="https://medium.com/@e-miguel/egister-a-new-domain-name-in-route-53-f5f64b57bcb5">here</a>. Once you completed it we will go to the next part of this project</p><h3>Part 14: Create a Record Set in Route 53</h3><p>We will create a record set in Route 53 to access our website using our domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KtgY7y_4PfUiWmhm.png" /></figure><p>To create a record set in Route 53, go to the <strong>Route 53</strong> dashboard. Select <strong>Hosted zones </strong>and click your <strong>Domain</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qmK6zDYP2uXKYYTq.png" /></figure><p>Click <strong>Create record</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zFn5BOYB-gaDPUtg.png" /></figure><p>Enter the information below then hit <strong>Create records</strong></p><p>Record name: www</p><p>Route traffic to:</p><ul><li>Alias to Application and Classic Load Balancer</li><li>US East (N. Virginia) [us-east-1]</li><li>Demo ALB</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CIHBuZ3yqO_SacL9.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jQywZJlJrkW_LOtE.png" /></figure><p>We have successfully created a record set.</p><p>Select the <strong>Record name</strong> and copy the <strong>Record name</strong> to your right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EJi8px_9mDRGInLN.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*xIMSMCEcRU5u5nolBMyB9A.png" /></figure><p>Lets head back to our terminal and update the .env file again. Use sudo vi .env and add your new domain to the file. Make sure to restart the system after any update.</p><pre> sudo systemctl restart httpd</pre><p>Open a new tab and paste the record name in the address bar. We can now access our website using the domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMwEsG66-hCZqs9ayEmMvA.png" /></figure><h3>Part 15: Create an Amazon Machine Image (AMI)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XsCE_s2-CEiDp3CphS0wLw.png" /></figure><p>Once we have installed and configured our website, we will use the <strong>Setup Server</strong> EC2 instance we installed our website on to create an AMI. Then we can use the AMI to launch new EC2 instances with our website already configured on them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J9qLKTCKuW-Ju2HB.png" /></figure><p>On the <strong>EC2 Dashboard &gt; Instances (running)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i0OyZ0ENCkzFPooN.png" /></figure><p><strong>Setup Server &gt; Actions &gt; Image and templates &gt; Create image</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xAC5W8Beu8tgI4kHo4fUBA.png" /></figure><p>Provide the name and description</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K84T5wUIyHejqoDV5ZyiqQ.png" /></figure><p>Enable <strong>Tag image and snapshots together.</strong></p><p>Key: Name</p><p>Value: Nestapp AMI</p><p>Then click <strong>Create image</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4do0fi5wyS_Yn_gv6V583Q.png" /></figure><p>We have successfully created our AMI from the Setup Server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*axGy3xd5voXUdujHgDXgbQ.png" /></figure><p>You can see the AMI by clicking <strong>AMIs </strong>under <strong>Images</strong></p><p>When you create an AMI a snapshot is also created. Wait until the status is completed/available. Now we can use this AMI to launch new EC2 instances with our website already installed on it. This is how we use an EC2 instance to create an AMI.</p><p>After successfully creatin the AMI we will then terminate the Setup Server we created to do the installation.</p><p>Next we will create an <strong>Auto Scaling Group</strong> to <strong>dynamically create and scale the EC2 instance in the private app subnet.</strong></p><h3>Part 16: Create an Auto Scaling Group</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A3uqUN0H8D2wFaI2xqEaIg.png" /></figure><p>We will create an auto scaling group to dynamically create and scale the web servers in the private app subnet.</p><p>Next, we need to create our Launch templates — this contains the configuration of the EC2 instance that auto scaling group will use to launch new EC2 instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hfVsNCMWa-OdoJWO.png" /></figure><p>Go to <strong>Launch Templates &gt; Create launch template</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l6eKZ9IcnTJX536g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*svQm1-TjOPDo_xt2oTcs1g.png" /></figure><p>Provide the name and description. Select the AMI that we created earlier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*Q95JIVWGNb4mL0Wm.png" /></figure><p>Enter these information</p><p>Launch template name: Demo-Launch-Template</p><p>Template version description: Launch Template for ASG</p><p>Provide guidance to help me set up a template that I can use with EC2 Auto Scaling: Checked</p><p>Application and OS Images: My AMIs</p><p>Instance type: t2.micro</p><p>Keypair: don’t include in launch template</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*YB1fo92oR8oYUIwA.png" /></figure><p><strong>Select existing group</strong> and let’s choose <strong>Webserver Security Group. </strong>We will leave the rest of the settings to default &gt; <strong>Create launch template</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PFg6zT6-mh3Iz-pO.png" /></figure><p>We created the launch template. Let’s go ahead and create our auto scaling group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rH_qwtpc_LlhYb8e.png" /></figure><p>Let’s go to <strong>Create Auto Scaling group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rgigG6HjM3ZkwGh2.png" /></figure><p>Give your ASG a name and select the launch template we created previously then click <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5hdITotbdKp627d-.png" /></figure><p>VPC: Demo VPC</p><p><strong>Availability Zones and subnets:</strong> Private App Subnet AZ1 and Private App Subnet AZ2</p><p>Let’s make sure that we enter these information correctly before clicking <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*6lMQUx1-RW9sWonE.png" /></figure><p>Under <strong>Load balancing</strong>, we are going to attach our auto scaling group with the ALB we created previously</p><p>Select these information under <strong>Load balancing</strong></p><ul><li>Attach to an existing load balancer</li><li>Choose from your load balancer target groups</li></ul><p>Existing load balancer target groups: select your target group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/0*ruKoH2dNarJBZ_gA.png" /></figure><p><strong>Enable Turn on Elastic Load Balancing health checks</strong> and <strong>Enable group metrics collection within CloudWatch </strong>then click <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*-7TjN7yXi1tFCdTf.png" /></figure><p>We want our auto scaling group to maintain two EC2 instances and the ASG can scale down to a minimum 1 instance or a maximum of 4 instances, click <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/0*b9lYQoOBjPLH2fSi.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/0*jyOMr2CHqrfx_Pcn.png" /></figure><p>Select the CloudWatch topic we created earlier. If you don’t have it already you can click <strong>Create a topic. </strong>Leave all <strong>Event types</strong> checked and click <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/0*J52CGq9OXxlt-jvS.png" /></figure><p>Let’s add a tag. Provide <strong>Key </strong>and <strong>Value </strong>then click <strong>Next. </strong>Verify your settings and <strong>Create Auto Scaling group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KE6uN_GyXg-9EIrD.png" /></figure><p>We successfully created our auto scaling group with desired capacity of two.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SoBOAcnC9CMQ-o0G.png" /></figure><p>You should have 2 instances running. These were launched by the ASG. You can tell because these are the tag names we gave them (ASG-Webserver). Let’s wait until it pass the <strong>Status check</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h8iUeOSLaHpUDaW0.png" /></figure><p>Let’s also make sure that the <strong>Health status</strong> of the <strong>Registered targets</strong> are healthy. We do this by going to <strong>Target Groups</strong> under <strong>Load Balancing</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GvZdtWhG4IL9wA4DM1N5CA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rj87tnlKpxkztkEcSNhTsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KseRxwMfWYgkWtKkT0DWSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*izx56gv_bC-mYjbzkTMkYg.png" /></figure><p>Type your domain name and press enter. This is how you create an auto scaling group to dynamically create and scale the EC2 instances in the private app subnet.</p><h3>Part 17: Clean up</h3><p>We have built all the resources on our reference architecture and completed this project. Let’s clean up our AWS accounts so it won’t incur costs. These are the accounts/resources that you need to clean</p><p>Auto scaling group</p><p>Launch template</p><p>Application load balancer</p><p>Target group</p><p>RDS instance</p><p>This is important. Before deleting the RDS instance make sure that you create a final snapshot. We will use this final snapshot on our Terraform project</p><p>Security groups</p><p>NAT gateway</p><p>VPC</p><p>Elastic IP</p><p>Record se</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*htG3RBpOVEDPztWu" /></figure><p>Congratulations! Thank you for completing this project with me. Let me know if you have any questions and I look forward to see you on my next project.</p><p>Build real-world projects with me <a href="https://www.aosnote.com/a/2147524876/WLBooyWz">here</a>! Show your employers that you are the right person for the job and stand out from the crowd!</p><p>Connect with me on <a href="https://www.linkedin.com/in/bello-afeez/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbca29a55372" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Host A Static Website On AWS]]></title>
            <link>https://medium.com/@werkjober/how-to-host-a-static-website-on-aws-a0c2588b1765?source=rss-eab516814854------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0c2588b1765</guid>
            <category><![CDATA[ec2]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[web]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[vpc]]></category>
            <dc:creator><![CDATA[Bello Afeez]]></dc:creator>
            <pubDate>Fri, 22 Sep 2023 18:03:34 GMT</pubDate>
            <atom:updated>2023-09-22T18:03:34.228Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome back to my blog, In this tutorial I’ll guide you through the process of setting up a highly available and fault tolerant Static Website on AWS using the management console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rKh-Y5svj6rqrQPC_6ahnQ.png" /></figure><h3>Introduction</h3><p>I’m excited to have you here again as we embark on our next real-world project. In this journey, we’ll delve into the deployment of a static website on AWS. Throughout this endeavor, we’ll explore the utilization of my reference architecture to host the website, leveraging a variety of AWS services and understanding how they seamlessly collaborate.</p><ul><li>VPC with public and private subnets</li><li>Security groups</li><li>EC2 instances</li><li>NAT gateways</li><li>EC2 Instance Endpoint Connection — EICE</li><li>Application load balancer</li><li>Route 53</li><li>Auto scaling group</li><li>Certificate manager</li></ul><h3>Objective</h3><ol><li>Build a three-tier AWS network VPC from scratch</li><li>Create NAT gateways</li><li>Create the security groups</li><li>Launch the EC2 instances (<strong>Webserver</strong>) in the private subnet</li><li>Create an application load balancer</li><li>Register a new domain name in Route 53</li><li>Create a record set in route 53</li><li>Register for an SSL certificate in AWS certificate manager</li><li>Create an HTTPS listener for the application load balancer</li><li>Create an auto scaling group</li><li>We will store our web files in a <strong>GitHub </strong>repository</li><li>Clean up</li></ol><p><strong><em>Note: We create a three-tier VPC for this tutorial in order to learn how to create a high available infrastructure but we would only use the two subnets (Public Subnet and Private App Subnet). As reference in the VPC architecture below.</em></strong></p><h3>VPC Reference Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_bunG0wBvjWiVtNQ9JdzWA.jpeg" /></figure><ol><li><strong>VPC</strong> with public and private subnets in 2 availability zones</li><li>An <strong>internet gateway</strong> is used to allow communication between instances in VPC and the internet</li><li>We are using <strong>2 availability zones</strong> for high availability and fault tolerance</li><li>Resources such as NAT gateway and application load balancer use <strong>public subnets.</strong></li><li>We will put the web servers, eice and database servers in the <strong>private subnets</strong> to protect them</li><li>The <strong>public route table</strong> is associated with the public subnets and routes traffic to the internet through the internet gateway</li><li>The <strong>main route table</strong> is associated with the private subnets</li></ol><p>We will commence by establishing a custom <strong>3-tier VPC</strong> using the architecture mentioned above. In this 3-tier architectural model, our infrastructure is categorized into three distinct tiers.</p><p>Firstly, in <strong>Tier 1</strong>, we will establish the public subnet, where resources like the NAT gateway, load balancer will be located.</p><p>Secondly, in <strong>Tier 2</strong>, we will set up the private subnet, where our web servers (EC2 instances), EICE will reside.</p><p>Lastly, in <strong>Tier 3</strong>, we will create another private subnet designated for our database.</p><p>To enhance high availability and fault tolerance, we will replicate these subnets across multiple availability zones.</p><p>As a final step, we will establish an internet gateway and configure a route table to enable internet access for the resources within our VPC.</p><p>Let’s get started!</p><h3>Part 1: Build a Three-Tier AWS Network VPC from Scratch</h3><h3>VPC</h3><p>In the management console, select the region where we want to create our VPC. According to our reference architecture we need to create this VPC in the N. Virginia region.</p><p>Either select VPC from the console or type VPC in the search bar above.</p><p>In your VPC dashboard select VPCs or the Create VPC orange box</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*hotZ6Av3-mKeRo1G.jpeg" /></figure><p>Let’s give our VPC a name. Let’s select VPC only and call it Demo VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*BNrK6Y7CxaWz6DXK.png" /></figure><p>According to our reference architecture, we will assign the IPv4 CIDR block of 10.0.0.0/16.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/0*fuIARgSnTbhU1ASC.png" /></figure><p>We will keep the IPv6 CIDR block and Tenancy settings at their default values. Now, let’s proceed by clicking the “Create VPC” button located at the bottom right corner.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/0*yiaFlE4xwf9J1Upc.png" /></figure><p>It will give us a <strong>successfully created</strong> message and You can view all the VPCs that have been created by clicking the drop-down arrow in the “Select a VPC” box. Please select the VPC we just created from the list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tTpJ2w-hj8C-dpUC.png" /></figure><p>Let’s enable the DNS host name in our VPC by selecting <strong>Actions </strong>and <strong>Edit VPC settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/0*40LeqkKnA46SYtZ1.png" /></figure><p>Under Edit <strong>VPC settings </strong>make sure that <strong>Enable DNS hostnames </strong>is checked then click <strong>Save</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*lWmeidlu3HAqodnP.png" /></figure><h3>Internet Gateway</h3><p>The next thing we are going to do is to create an <strong>Internet gateway </strong>for our VPC. You can find and select <strong>Internet gateway </strong>at the left side menu of <strong>Your VPC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*OynLIXEsUCyyLgRO.png" /></figure><p>Let’s select <strong>Create Internet gateway, </strong>give it a name — <strong>Demo Internet Gateway </strong>and click <strong>Create internet gateway</strong></p><p>Now, we need to attach the internet gateway to the VPC we created earlier. This will allow the VPC to communicate with the internet.</p><p>Just simply click <strong>Attach to a VPC</strong> in the green banner above</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*E90lfMSXeDyVyaCq.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*A3gCa62ZKd16vA8x.png" /></figure><p>Select the Demo VPC that we created and click <strong>Attach internet gateway. </strong>This is the only VPC that will show in your account this doesn’t have any internet gateway attached to it. We can only attach one internet gateway to one VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Ma4QirGFYolnc_96.png" /></figure><p>We successfully attached the internet gateway to our VPC. The Details show the <strong>State </strong>and the <strong>VPC ID</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*3yP7XQaEhHMb18DQ.png" /></figure><h3>Public Subnets</h3><p>Let’s create our public subnets in the first and second availability zones. Ensure that its still filtered to our <strong>Demo VPC</strong> then click <strong>Subnets </strong>at the left side.</p><p>Once you are in the subnet page, click <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/585/0*9iXUPxSpv8ABaqc0.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*jksfO3DqwLWmNyAa.png" /></figure><p>Let’s select the VPC where we want to create our subnet in — let’s choose Demo VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*R_T9bD_F2faWlY61.png" /></figure><p>Let’s give our subnet a name. Based on our reference architecture, we will call it <strong>Public Subnet AZ1 </strong>and put this in the <strong>us-east-1a Availability Zone</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/0*_ahHS6fz0kK-rwm5.png" /></figure><p>The <strong>CIDR block</strong> should be <strong>10.0.0.0/24 </strong>and click <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/0*07vfnX4AdPWW4FkY.png" /></figure><p>We have successfully created our first public subnet in the us-east-1a Availability Zone.</p><p>Let’s create our second subnet in the us-east-1b Availability Zone and click the <strong>Create subnet</strong> button at the top right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*40FShuTUpKyWUScn.png" /></figure><p>Select the same VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*XpqwoKHyK-cSKLYw.png" /></figure><p>Select and enter 10.0.1.0/24 in <strong>IPv4 CIDR block. </strong>Afterwards we can <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/742/0*5ga1XpLN5x4ZHquf.png" /></figure><p>Select and enter 10.0.1.0/24 in <strong>IPv4 CIDR block. </strong>Afterwards we can <strong>Create subnet</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Ff12aKmQYoeUpFfx.png" /></figure><p>Great job! We have successfully created our second public subnet in the us-east-1b Availability Zone. If you select “Clear filters,” it will display the two subnets that we created in this region. Please make sure to filter it to your Demo VPC in order to view and populate these subnets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Zh4yA5fD6Ukxovy4.png" /></figure><p>Remember to check the following:</p><p>Public Subnet AZ1 is in us-east-1a AZ</p><p>Public Subnet AZ2 is in us-east-1b AZ</p><p>Moving forward let’s enable the <strong>Auto assign IP settings</strong> for these 2 public subnets. This means that anytime you launch EC2 instance in these public subnets, those EC2 instances will be assigned a public IPv4 address.</p><p>Let’s select <strong>Public Subnet AZ1</strong> click <strong>Actions </strong>and click <strong>Edit subnet settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*1wmCjUZYNPFlCJSt.png" /></figure><p>Under <strong>Edit subnet settings and Auto-assign IP settings </strong>check the <strong>Enable auto-assign public IPv4 address</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*i4UP8aaxZFoHwAKg.png" /></figure><p>Scroll all the way down and hit <strong>Save. </strong>We are going to repeat the same procedure for Public Subnet AZ2.</p><p>Next is we need to create a public route table. Based on our reference architecture, we will call this <strong>Public Route Table.</strong></p><p>Let’s click <strong>Route tables</strong> on the left side. The route table that we see was set up when we created the VPC. This is the main route table and its private by default.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*bpcc-bEpbJSIZD0O.png" /></figure><p>Click <strong>Create route table. </strong>We will call it <strong>Public Route Table. </strong>Make sure to select <strong>Demo VPC</strong> under <strong>VPC </strong>before clicking <strong>Create route table</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rzkEE8ZmY1uFpVbQ.png" /></figure><p>We have successfully created our Public Route Table.</p><p>Let’s add internet gateway to the public route table. This will allow the route table to route traffic to the internet. First, let’s make sure that we are on the <strong>Routes </strong>tab then click <strong>Edit routes.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/0*_oszxMbR2LJK4HXq.png" /></figure><p>Click <strong>Add route </strong>and to add a route that routes traffic to the internet to this route table, we will add <strong>0.0.0.0/0 </strong>under <strong>Destination </strong>and the Target should be the <strong>Internet Gateway</strong> we created. When this is all filled in we can click <strong>Save changes.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*El31XXJkPdxhJQze.png" /></figure><p>We successfully added a route to the internet to our public route table. You can see it under the <strong>Routes tab.</strong></p><p>Let’s associate the 2 public subnets we created earlier with this route table. Let’s ensure that we are still under <strong>Public Route Table.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*GghXkSt6ceEk7Rze.png" /></figure><p>Click <strong>Subnet associations</strong> and click <strong>Edit subnet associations. </strong>On this page, we can see the 2 subnets that we created previously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*sdPavvbVFTyXew7m.png" /></figure><p>Under <strong>Edit subnet associations </strong>select both Subnets and <strong>Save association.</strong></p><p>Good job! We have associated the 2 subnets that we created to the Public Route Table. These will now show under <strong>Subnet associations</strong> tab.</p><p>To finish creating our VPC we need to create 4 private subnets. So let’s click <strong>Subnets </strong>at the left side and <strong>Create subnet.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*XSvSYh9zbungcSTT.png" /></figure><p>We will still stick to our <strong>Demo VPC</strong> under <strong>VPC ID</strong> and based on our reference architecture let’s name it <strong>Private App Subnet AZ1 </strong>and choose <strong>us-east-1a Availability Zone.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*s4hSMomqCOJRjcER.png" /></figure><p>Our CIDR block should be <strong>10.0.2.0/24 </strong>and we are now ready to <strong>Create subnet.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/0*k2FpRO5Pns_wN1Lj.png" /></figure><p>There you go! We created our 1st private subnet in the us-east-1a Availability Zone. Doing the same procedures above let’s create the next 3 private subnets using the settings below and referring to our reference architecture:</p><p><strong>2nd Subnet</strong></p><p>VPC ID: Demo VPC</p><p>Subnet name: Private App Subnet AZ2</p><p>Availability Zone: us-east-1b</p><p>IPv4 CIDR block: 10.0.3.0/24</p><p><strong>3rd Subnet</strong></p><p>VPC ID: Demo VPC</p><p>Subnet name: Private Data Subnet AZ1</p><p>Availability Zone: us-east-1a</p><p>IPv4 CIDR block: 10.0.4.0/24</p><p><strong>4th Subnet</strong></p><p>VPC ID: Demo VPC</p><p>Subnet name: Private Data Subnet AZ2</p><p>Availability Zone: us-east-1b</p><p>IPv4 CIDR block: 10.0.5.0/24</p><p>We have successfully created all 4 subnets. To see these let’s click <strong>Clear filters </strong>and filter it by <strong>Demo VPC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tHN30jxjLG4f0Nye.png" /></figure><p>Before we proceed to Part 2 of our project, let’s review and confirm that we have correctly placed each subnet in the respective availability zones.</p><p>Additionally, it’s important to understand the distinction between public and private subnets. When we create a route table and configure it with a route to direct traffic to the internet, any subnet associated with that route table becomes a public subnet. In contrast, subnets without such routes remain private, typically used for resources that should not have direct internet access.</p><p>This differentiation is crucial for controlling network traffic and ensuring the appropriate level of security and access for your resources within the VPC.</p><p><em>To show you why these 2 subnets are public:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*QmXLjc0MLZR2O3Ya.png" /></figure><p><em>and these subnets are private</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*3iuKiVkPTDystCQa.png" /></figure><p>let’s look at the VPC we just created. To verify these, click on <strong>Route Tables and filter it by our VPC — Demo VPC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*K5GGI3eSwJZs1scU.png" /></figure><p>Let’s select <strong>Public Route Table </strong>and <strong>Routes </strong>tab, this route table is routing traffic to the internet. So any subnet we associate with this route table becomes public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*bkriGcGODYGNMbD-.png" /></figure><p>The <strong>Subnet associations</strong> tab shows that we associated both <strong>Public Subnet AZ1 and AZ2 </strong>to this route table. That is what makes these 2 subnets public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*cGKKJtHaT5JK5j2Y.png" /></figure><p>On the other hand, let’s select the main Route Table. Uncheck the <strong>Public Route Table </strong>and select the main <strong>Route table — </strong>this was created when we created the VPC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*BhuEUUvspa4aXfu6.png" /></figure><p>The main Route table is private by default it is only routing traffic locally in the VPC and it doesn’t have a route to the internet</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*5M_U0cbmq2-9cTcT.png" /></figure><p>Further, we created 4 private Subnets we did not associate them with any route tables. By default, they will be associated with the main Route table which is private. Going back to the main <strong>Route table </strong>under <strong>Subnet associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Uu6m8sL2OtS0HHwS.png" /></figure><p>Let’s scroll down to <strong>Subnets without explicit associations. </strong>It says <strong><em>The following subnets have not been explicitly associated with any route tables and are therefore associated with the main route table.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*c3fqrAcOwd63Jr8k.png" /></figure><p>On the next part of our project, we will create a NAT Gateway and private Route tables. We will explicitly associate our private subnet with our private Route tables but for now we will let the Private subnet be associated with the main Route table which is private by default.</p><h3>Part 2: Create NAT Gateways</h3><p>Certainly, before creating the NAT Gateway, it’s important to ensure that we are in the correct AWS region, which is N. Virginia (us-east-1), as this is the region where we previously created the VPC.</p><p>Once you have confirmed that you are in the correct region, we can proceed with the creation of the NAT Gateway in the first and second availability zones according to the reference architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*cQIld9DwTMGjlDWf.jpeg" /></figure><p>To proceed with creating the NAT Gateway, please click on “VPC” in the AWS Management Console. You can select “NAT Gateways” from the list of options within the VPC dashboard to begin the process of creating NAT Gateways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*OIGnKkmfVkt2QTrF.png" /></figure><p>We will create the first <strong>NAT gateway</strong> in the <strong>Public Subnet AZ1. </strong>We will call it <strong>NAT Gateway AZ1 </strong>and we will put this in the Public Subnet AZ1. We also need to click the <strong>Allocate Elastic IP button</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Y7tCCv6CQqMraxrk.png" /></figure><p>Now we are ready to click <strong>Create NAT gateway. </strong>It should bring us to the NAT gateway created successfully page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*kgInF8hcT9Xr6zwb.png" /></figure><p>Then we will follow the same step to create our <strong>NAT gateway AZ2 </strong>in the <strong>Public Subnet AZ2.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*XAo8WDvWEM8s6zKt.png" /></figure><p>Next is we need to create a route table. We will call it <strong>Private Route Table AZ1. </strong>Select <strong>Route tables</strong> at the left side and hit <strong>Create route table.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/239/0*mcRSlGwxVrCj2qE8.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tqgj9ZQ5lwASEsZ2.png" /></figure><p>We will call this <strong>Private Route Table AZ1</strong> in <strong>Demo VPC </strong>then hit <strong>Create route table</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ah7Vu4ahLP1S_K5v.png" /></figure><p>The next page should say <strong>Route table was created successfully.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*HLu1ZoEqEpG1q3Ui.png" /></figure><p>Let’s add a route to the <strong>Private Route Table AZ1 </strong>to route traffic to the internet through the <strong>NAT gateway</strong> in the <strong>Public Subnet AZ1</strong></p><p>Under <strong>Routes </strong>tab click <strong>Edit routes </strong>then <strong>Add route</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*OwNLbQordd0Yc9sQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*OrARKRH1mJmhN8J9.png" /></figure><p>Internet traffic is always <strong>0.0.0.0/0</strong> so we will select that as our <strong>Destination</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/399/0*gWHJL3bQkHxwc67G.png" /></figure><p>Our target will be <strong>NAT gateway</strong> and we need to select <strong>NAT gateway AZ1. </strong>We’re ready to click <strong>Save changes </strong>the next page shows <strong>Updated routes for Private Route Table AZ1 successfully</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*hLZiWDckhU1FLv4T.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*lJO8o-Qih83Akur7.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*sR11mdG2UvOBrctk.png" /></figure><p>Next we will associate <strong>Private Route Table AZ1</strong> with <strong>Private App Subnet AZ1</strong> and <strong>Private Data Subnet AZ1.</strong></p><p>Let’s click the <strong>Subnet associations</strong> tab and <strong>Edit subnet associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*MJtrz3YZi5PdlDlD.png" /></figure><p>From the list of available subnets below we need to select <strong>Private App Subnet AZ1</strong> and <strong>Private Data Subnet AZ1</strong> then click <strong>Save associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*KqltBoxZiOplRrik.png" /></figure><p>We have successfully associated <strong>Private App Subnet AZ1</strong> and <strong>Private Data Subnet AZ1 </strong>to the <strong>Private Route Table AZ1</strong> as shown under <strong>Explicit subnet associations</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*keYboHUgaO7ZoyOX.png" /></figure><p>and Explicit subnet associations under <strong>Subnet associations</strong> tab</p><p>Now we will follow the same steps to create<strong> Private Route Table AZ2 </strong>and then add our <strong>NAT gateway AZ2 </strong>to route traffic for the <strong>Private App Subnet AZ2</strong> and <strong>Private Data Subnet AZ2.</strong></p><p>Good work! This is how we create NAT gateways to allow resources in the private subnet to have access to the internet.</p><h3>Part 3: Create Security Groups</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*se0OXeJ0fMTzOcDrUuuUXg.jpeg" /></figure><h3>Security Group Reference Architecture</h3><p>These are the security groups that we need for this project.</p><p><strong>ALB Security Group</strong></p><ul><li>This is the security group that we will add to the application load balancer</li><li>Port: 80 and 443 with Source: 0.0.0.0/0</li></ul><p><strong>SSH Security Group — EICE</strong></p><ul><li>This is the security group that we will use to EICE to ssh into our EC2 instance in the private subnet</li><li>Port: Open outbound on 22 with Source: <strong>VPC cidr </strong>(10.0.0.0/16)</li></ul><p><strong>Webserver Security Group</strong></p><ul><li>This is the security group that we will add to the web servers in the private app subnets</li><li>Port: 80 and 443 with Source: ALB Security Group</li><li>Port: 22 with Source: SSH Security Group <strong>— EICE</strong></li></ul><p>Let’s head over to the console and create the security groups. We will use the information from the reference architecture above.</p><p>In the console home search and click VPC. At the left hand side click security groups</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*u3xIoJDgfK6L5UJp.png" /></figure><p>Click create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Tl_-sOjZqJOjzJR2.png" /></figure><p>Enter the following settings</p><p><strong>Basic details</strong></p><p>Security group name: ALB Security Group</p><p>Description: ALB Security Group</p><p>VPC: Demo VPC</p><p><strong>Inbound rules — we will add 2 rules</strong></p><p><strong>1st rule</strong></p><p>Type: HTTP</p><p>Protocol: TCP</p><p>Port range: 80</p><p>Source: 0.0.0.0/0</p><p><strong>2nd rule</strong></p><p>Type: HTTPS</p><p>Protocol: TCP</p><p>Port range: 443</p><p>Source: 0.0.0.0/0</p><p>Once we opened the ports let’s click Create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Y-j2LWeNHcwiIpur.png" /></figure><p>We successfully created the ALB security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*r0qpZz0pAriW8MOl.png" /></figure><p>Let’s create the SSH security group. Click security groups to go back one directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*ZFAAFPjhBbXYYOFz.png" /></figure><p>Click create security group and enter the following settings</p><p><strong>Basic details</strong></p><p>Security group name: SSH Security Group — <strong>EICE</strong></p><p>Description: SSH Security Group</p><p>VPC: Demo VPC</p><p><strong>Outbound rules</strong></p><p>Type: SSH</p><p>Protocol: TCP</p><p>Port range: 22</p><p>Source: <strong>VPC CIDR</strong></p><p>This is the only rule that we need to add to our SSH security group let’s click create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*vhvHWtS645u9MvkE.png" /></figure><p>We successfully created the SSH security group -EICE</p><p>The next security group that we will create is web server security group. Click security groups to go back one directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/551/0*7KaflwaJ3Yv5qEZ_.png" /></figure><p>Click create security group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*WbYi0k53KQlc8AmJ.png" /></figure><p>Click create security group and enter the following settings</p><p><strong>Basic details</strong></p><p>Security group name: Webserver Security Group</p><p>Description: Webserver Security Group</p><p>VPC: Demo VPC</p><p><strong>Inbound rules</strong></p><p><strong>1st rule</strong></p><p>Type: HTTP</p><p>Protocol: TCP</p><p>Port range: 80</p><p>Source: ALB Security Group — this is how we limit a traffic to a particular security group</p><p><strong>2nd rule</strong></p><p>Type: HTTPS</p><p>Protocol: TCP</p><p>Port range: 443 — this is an internet traffic that is encrypted</p><p>Source: ALB Security Group</p><p><strong>3rd rule</strong></p><p>Type: SSH</p><p>Protocol: TCP</p><p>Port range: 22</p><p>Source: SSH Security Group -<strong>EICE</strong></p><p>This completes the rules that we need for our webserver security group. Click create security group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Bvm31H1raTum3C5t.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*VtMkYGMx-FFDBRnd.png" /></figure><p>We have successfully created the web server security group. We also opened port 80 and 443 and limited the source to the application load balancer security group.</p><p>Alright, let’s create an application load balancer.</p><h3>Part 4: Application Load Balancer</h3><p>Let’s go to the <strong>Console Home. </strong>We will launch an EC2 instance in each of the private app subnet.</p><p>Click EC2 from the console home and select Launch Instance</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/0*KhBlsVyAj6keIxNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/0*wrIWQ6s70r1bQVHC.png" /></figure><p>Let’s add a tag to our EC2 instance. Click <strong>Add additional tags</strong> under N<strong>ame and tags </strong>and enter these settings</p><p><strong>Key:</strong> Name</p><p><strong>Value: </strong>Webserver AZ1</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*UQucM2i7E5oalh_K.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*59Ww55ISGMnQNncL.png" /></figure><p>On <strong>Application and OS Images (Amazon Machine Image) </strong>select <strong>Amazon Linux 2023 AMI</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/0*YzM4oTejAMNJPPRZ.png" /></figure><p>It’s going to be <strong>t2.micro</strong> under <strong>Instance type</strong></p><p>In Key pair (login) let’s select the proceed without a keypair</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*d5MI4pRRilBBk8mTO9JLEg.png" /></figure><p>Click <strong>Edit </strong>under <strong>Network settings </strong>and enter the following information</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*L1OHRIAGuSYKzi-Q.png" /></figure><p><strong>VPC:</strong> Demo VPC</p><p><strong>Subnet:</strong> Private App Subnet AZ1 (we are going to launch this EC2 instance in this subnet)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*2ASn9ZDB26St1P1DMdH5Vg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*yYNMQaUVWV_kHcVB.png" /></figure><p>We’re going to leave the storage to their default settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*WRcixYVP2-71NRD6.png" /></figure><p>These are the commands that we will need shortly</p><pre>#!/bin/bash<br>sudo su<br>yum update -y<br>yum install -y httpd<br>cd /var/www/html<br>wget https://github.com/werkmanne/ovo-bicycle-website/archive/refs/heads/main.zip<br>unzip main.zip<br>cp -r ovo-bicycle-website-main/* /var/www/html/<br>rm -rf ovo-bicycle-website-main main.zip<br>systemctl enable httpd <br>systemctl start httpd<br></pre><p><strong>Advance details — go to User data</strong></p><ul><li>This is where we are going to add our bash script to install the website. Remember to paste it as plain text</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*9XXtmR__NE5Z3nAVsIJ6kQ.png" /></figure><p>We are now ready to click <strong>Launch instance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/0*Ofk8VU50dPFdgI_v.jpg" /></figure><p>and we should get a <strong>Success</strong> page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*Z54BYFLRyeir5mi9.png" /></figure><p>Click <strong>View all instances</strong> at the bottom right and we have launched our first EC2 instance in the private app subnet AZ1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*jQHlByKa6u4tKZvc.png" /></figure><p>Let’s launch our second EC2 instance in the private app subnet AZ2. We will be doing similar steps we did previously so let’s click <strong>Launch instances</strong> again and enter the following information.</p><p><strong>Key:</strong> Name</p><p><strong>Value: </strong>Webserver AZ2</p><p><strong>Application and OS Images (Amazon Machine Image): </strong>Amazon Linux 2023 AMI</p><p><strong>Instance type:</strong> t2.micro</p><p><strong>Key pair: </strong>proceed without keypair</p><p><strong>VPC: </strong>Demo VPC</p><p><strong>Subnet: </strong>Private App Subnet AZ2</p><p><strong>Security Group: </strong>Webserver Security Group</p><p><strong>Storage: </strong>Default</p><p><strong>User data: </strong>Enter the same command shown below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*9XXtmR__NE5Z3nAVsIJ6kQ.png" /></figure><p>Once all settings are entered we can <strong>launch</strong> our second instance and select <strong>View all instances. </strong>Let’s wait and ensure that the <strong>Instance state</strong> is running and <strong>Status check</strong> says 2/2 checks passed</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*YIBpRjNaMhllI-91.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*qb8JUyO6_ujb3IaZ.png" /></figure><p>Now that we have successfully launched our EC2 instances in the private app AZ1 and private app AZ2, we are ready to create the <strong>Application Load Balancer </strong>that will route internet traffic to those EC2 instances.</p><p>Let’s click <strong>Create target group. </strong>A target group is how you specify the EC2 instances that you want your application load balancer to route traffic to.</p><p>On the <strong>Instances </strong>page at the left side scroll down to <strong>Target Groups </strong>and select <strong>Target Groups</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xdbuA8JwmB_JXN2ldw-TZg.png" /></figure><p><strong>Create Target Group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NBXbySuJy8wStprSA51Y-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*oTZZjP372WBBKkBy.png" /></figure><p>Choose a target a type: Instances</p><p>Target group name: Demo-TG</p><p>Protocol: HTTP</p><p>Port: 80</p><p>VPC: Demo VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XnK7mlKsVbEcxd0_SrKmCQ.png" /></figure><p>And let’s hit <strong>Next. </strong>Under <strong>Register targets</strong>, select both <strong>Instance ID </strong>and click <strong>Include as pending below</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lcnH3PzZ_lwXzvBsC7gRoA.png" /></figure><p>Click <strong>Create target group</strong> under <strong>Review targets</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Asj2Gbc44swSYLi1YWGs0Q.png" /></figure><p>And we get a successful message</p><p>Let’s create the<strong> Application load balancer</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*OC6vkX2lbAqUMjnJ.png" /></figure><p>Select <strong>Application Load Balancer</strong> and hit <strong>Create</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/404/0*6_e8cTPvJkq_gjkH.png" /></figure><p>Enter the information below. Let’s leave the settings that are not mentioned to default</p><p><strong>Load balancer name:</strong> Demo-ALB</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T6lYE47Bn3SxdOav0k0VOA.png" /></figure><p><strong>VPC:</strong> Demo VPC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjQ7pAbZRo0H57d_rLYO1A.png" /></figure><p><strong>Mappings:</strong> us-east-1a</p><p><strong>Subnet:</strong> Public Subnet AZ1 <em>*you always want to place your ALB in the public subnet</em></p><p><strong>Mappings:</strong> us-east-1b</p><p><strong>Subnet:</strong> Public Subnet AZ2</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eB7QHV4MgTbgTQxUwzQPBw.png" /></figure><p><strong>Security group :</strong> ALB Security Group <em>*remove the default security group</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*l1FIa0yYJAnGRvQD.png" /></figure><p><strong>Listeners and routing</strong></p><p><strong>Protocol:</strong> HTTP</p><p><strong>Port:</strong> 80</p><p><strong>Target group</strong>: Demo TG</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2aFQ9axsPxEJjQ9obOfdVw.png" /></figure><p>Click Create load balancer it will bring us to this page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FHovVK0Zf3exVTPlLPf7sw.png" /></figure><p>Let’s wait until the the <strong>State</strong> turns from <strong>Provisioning </strong>to <strong>Active. </strong>Afterwards, put a check beside our <strong>Demo-ALB</strong> and copy the <strong>DNS name</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAX8XSRWF1mU0-hnkNgkfg.png" /></figure><p>Open a new tab and paste the DNS name that we copied and it should bring us to this page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yaDm2kzjAiXMTWJnb3Vs4w.png" /></figure><p>Well done! The application load balancer is routing internet traffic to the EC2 instances in the private subnets and we can access the website using the DNS name of our application load balancer.</p><h3>Part 5: Register a New Domain Name in Route 53</h3><p>We will register a new domain name in Route 53. This will allow our end users to access our website using that domain name instead of the DNS name of our application load balancer. View Miguel (Colleague) tutorial <a href="https://medium.com/@e-miguel/egister-a-new-domain-name-in-route-53-f5f64b57bcb5">here</a>. Once you completed it we will go to the next part of this project</p><h3>Part 6: Create a Record Set in Route 53</h3><p>We will create a record set in Route 53 to access our website using our domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*uCzUUh6QHfQp4QVW.png" /></figure><p>To create a record set in Route 53, go to the <strong>Route 53</strong> dashboard. Select <strong>Hosted zones </strong>and click your <strong>Domain</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*LkTw5tHGEJFTtRPG.png" /></figure><p>Click <strong>Create record</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*3s8rJzXak15fhViH.png" /></figure><p>Enter the information below then hit <strong>Create records</strong></p><p>Record name: www</p><p>Route traffic to:</p><ul><li>Alias to Application and Classic Load Balancer</li><li>US East (N. Virginia) [us-east-1]</li><li>Demo ALB</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*sS8KAzraGbOyxhJi.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ftLghn7GzuYj3G5C.png" /></figure><p>We have successfully created a record set.</p><p>Select the <strong>Record name</strong> and copy the <strong>Record name</strong> to your right</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*XrEYY84jIVzP3KzP.png" /></figure><p>Open a new tab and paste the record name in the address bar. We can now access our website using the domain name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HpQY9oDDaMAcOgHQS8xJjA.png" /></figure><h3>Part 7: Register for an SSL Certificate in AWS Certificate Manager</h3><p>We will register for a free SSL certificate from the AWS certificate manager. We will use this to encrypt the communications between the web browser and our web servers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/0*HDlOefEehXxm30cQ.png" /></figure><p>For our website above, the communication between the web browser and our website is not secure. We will use this SSL certificate to secure all communications between the web browser and our website — also referred to as encryption in transit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*xlOj81EG05mpYy6l.png" /></figure><p>Go to <strong>AWS Certificate Manager</strong> and <strong>Request a certificate</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*qVkkuOdd2_Sgo8aP.png" /></figure><p>Choose <strong>Request a public certificate</strong> under <strong>Certificate type</strong></p><p>Enter your <strong>domain name</strong> and click <strong>Add another name to this certificate</strong></p><p>In the second certificate box, we are going to add a wildcard. Type <strong>*.</strong> followed by your domain name. We will leave the rest to their default settings then click <strong>Request</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ZtpAhP1n7E2tH8gk.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*pWBkb-T8jzAjQmuo.png" /></figure><p>Let’s <strong>View certificate</strong> after creating the request</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*uGK8tiaiyVSgg_oO.png" /></figure><p>If your status says <strong>Pending validation </strong>this means you need to create a record set in Route 53 to validate that this domain name belongs to you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*9GlggeSQ83C8WDB6.png" /></figure><p>You will see that the <strong>Status </strong>of the <strong>Certificate</strong> is <strong>Issued. </strong>For the 2 domain names we requested the certificate for is now showing <strong>Success.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*cYJwDV1zzrFzVqE0.png" /></figure><p>Good work! This is how you request a free certificate from <strong>AWS Certificate Manager.</strong></p><h3>Part 8: Create an HTTPS Listener for the Application Load Balancer</h3><p>We’re going to create an HTTPS listener for our ALB to secure our website. Let’s go to the <strong>EC2 dashboard</strong> and head over to <strong>Load balancer</strong></p><p>Ensure that your load balancer name is selected then click the <strong>Listener</strong> tab then Click <strong>Add listener</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*-Svam6H941MXOpBC.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*-ZdyM3D9C5zhidpd.png" /></figure><p>Switch the protocol to <strong>HTTPS </strong>this is always on port <strong>443, </strong>Select <strong>Forward </strong>under <strong>Default actions </strong>and<strong> Target group</strong> will be <strong>Demo-TG</strong></p><p>Select your <strong>Default SSL/TLS certificate</strong> and click <strong>Add </strong>at the bottom right part of your screen</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*YjcS8tC6qhDOu7ez.png" /></figure><p>The HTTPS listener is added. Let’s edit the HTTP listener to redirect HTTP traffic to HTTPS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*MhISCv_5yfg4SQbZ.png" /></figure><p>Select the <strong>HTTP </strong>listener and <strong>Edit, Remove </strong>the <strong>Default actions</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*43eBJcVhGDLJn5fJ.png" /></figure><p>Select <strong>Redirect </strong>under <strong>Default actions</strong></p><p>We are going to redirect it to <strong>HTTPS </strong>and enter <strong>Port 443. Save changes</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*F7xELJpfihfx7UtX.png" /></figure><p>We have successfully edited our HTTP listener to redirect traffic to HTTPS.</p><h3>Part 9: Create an Auto Scaling Group</h3><p>In this part of our project, we will create an auto scaling group to dynamically create and scale our EC2 instance in the private app subnets.</p><p>Before we do that, let’s head to the <strong>Console </strong>and terminate the EC2 instance that we manually created.</p><p>Select <strong>EC2</strong> from your recently visited</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*hR8xxb1ucL8Eyqq1.png" /></figure><p>Click <strong>Instances (running)</strong> under <strong>Resources</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*apmu-IbRvBSPFe0h.png" /></figure><p>Select both instances</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aqJXFvz1WewP2y64Bd3LoA.png" /></figure><p>Click <strong>Instance state</strong> and <strong>Terminate instance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TuefGiAxpy3-X9HuAkchnA.png" /></figure><p>Click <strong>Terminate </strong>in the prompt box</p><p>Before we create our auto scaling group we need to create a<strong> launch template</strong> — this contains the configuration of our EC2 instance that the auto scaling group will use to launch instances in the private app subnet.</p><p>Let’s select <strong>Launch Template</strong> under <strong>Instances </strong>and click <strong>Create launch template</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*UCRvpcbJ9xvmdz4o.png" /></figure><p>Enter the following information</p><p><strong>Launch template name:</strong> Demo-Launch-Template</p><p><strong>Template version description:</strong> Launch template for ASG</p><p><strong>Provide guidance to help me set up a template that I can use with EC2 Auto Scaling</strong> should be checked</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*kVIVZKmgnJWcD8PANZWw-w.png" /></figure><p>Select <strong>Quick Start </strong>in the <strong>Application and OS Images</strong> then choose <strong>Amazon Linux 2 AMI</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*JX4-w-TRpmxpZg_N.png" /></figure><p>Let’s use the following information below</p><p><strong>Instance type:</strong> t2 micro</p><p><strong>Key pair: </strong>Don’t include in launch template</p><p><strong>Network settings: </strong>Webserver Security Group</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tXlpBPeCr2WAt_Ol.png" /></figure><p>Click <strong>Advanced details</strong> and head to <strong>User data. </strong>We will use the bash script to install our website</p><pre>#!/bin/bash<br>sudo su<br>yum update -y<br>yum install -y httpd<br>cd /var/www/html<br>wget https://github.com/werkmanne/ovo-bicycle-website/archive/refs/heads/main.zip<br>unzip main.zip<br>cp -r ovo-bicycle-website-main/* /var/www/html/<br>rm -rf ovo-bicycle-website-main main.zip<br>systemctl enable httpd <br>systemctl start httpd</pre><p>And we are ready to click <strong>Create launch template. </strong>Click <strong>View launch templates</strong></p><p>We can start creating our auto scaling group. At the left menu click <strong>Auto Scaling Group</strong> under <strong>Auto Scaling</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/217/0*LmCL0b8yERqh1oer.png" /></figure><p>Select the <strong>Create Auto Scaling group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*gy52L02G3aOGdZbB.png" /></figure><p>Enter the following details</p><p>Enter the following details</p><p><strong>Name:</strong> Demo-ASG</p><p><strong>Launch template:</strong> Demo-Launch-Template</p><p>Hit the <strong>Next </strong>button</p><p><strong>VPC: </strong>Demo-VPC</p><p><strong>Availability Zones and subnets: </strong>Private App Subnet AZ1 and Private App Subnet AZ2</p><p>Hit <strong>Next. </strong>Under <strong>Load balancing </strong>we are going to attach our auto scaling group with the application load balancer we created earlier.</p><p><strong>Load Balancing:</strong> Attach to an existing load balancer</p><p><strong>Attach to an existing load balancer: </strong>Choose from your load balancer target groups</p><p><strong>Existing load balancer target groups:</strong> Demo-TG | HTTP</p><p>Enable<strong> Turn on Elastic Load Balancing health checks</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/0*uFMnjnKKbT5x5zBn.png" /></figure><p>Check <strong>Enable group metrics collection within CloudWatch </strong>and click <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/0*lHhvFYN_K2FFt-0c.png" /></figure><p>We want the auto scaling group to maintain 2 EC2 instances, it can scale down to a minimum of 1 instance or a maximum of 4 instances. Click <strong>Next</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/683/0*PMu6NM3Tn1dSU9a6.png" /></figure><p>On the next page hit <strong>Add notification. </strong>Under <strong>SNS Topic</strong> select the SNS topic that we created previously. If you don’t have a topic you can click <strong>Create a topic</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/0*jTnAjmeM42uuT0Sf.png" /></figure><p>Let’s click <strong>Next. </strong>Under <strong>Tags </strong>enter the details below</p><p>Key: <strong>Name</strong></p><p>Value: <strong>ASG-Webserver</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*QrNN9Y55Gme8BAgQ.png" /></figure><p>Hit <strong>Next. </strong>Under <strong>Review</strong> page check all the details of our launch template and click <strong>Create Auto Scaling group</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*rI_jTH3iUyz6jF5d.png" /></figure><p>We have successfully created our auto scaling group with the desired capacity of 2, minimum of 1, and maximum of 4. If we check our instances we should have 2 running. Let’s go back to <strong>EC2 Dashboard</strong> and view the 2 instances running</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*3TA-3ou5bN21A7E6.png" /></figure><p>We can say that these EC2instances are created by the auto scaling group because it shows the tag name that we created — ASG-Webserver</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/0*Wy9Chh0BkAWy2kaP.png" /></figure><p>We should be able to access our website. Let’s open a new window and type the domain name of your website</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g25r2K7vOyUz_QsaO8k0Ow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h577Ugw1vERg4lMQDnDjYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*om7BXn-_uwU05kgY7AiLSQ.png" /></figure><p>This is how we create an auto scaling group.</p><h3>Clean Up</h3><p>We have used all the resources on our reference architecture and completed this project. Let’s clean up our AWS accounts so that we don’t get charged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*pomVg4Y4Jwyf1O0Y" /></figure><p>Congratulations! Thank you for completing this project with me. Let me know if you have any questions and I look forward to see you on my next project.</p><p>Build real-world projects with me <a href="https://www.aosnote.com/a/2147524876/WLBooyWz">here</a>! Show your employers that you are the right person for the job and stand out from the crowd!</p><p>Connect with me on <a href="https://www.linkedin.com/in/bello-afeez/">LinkedIn</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0c2588b1765" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>