<?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 Adolphas Gwena on Medium]]></title>
        <description><![CDATA[Stories by Adolphas Gwena on Medium]]></description>
        <link>https://medium.com/@adolphasg?source=rss-4a804d4f2bb4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PjfDRnnCaZYHc6sCAudFIw.jpeg</url>
            <title>Stories by Adolphas Gwena on Medium</title>
            <link>https://medium.com/@adolphasg?source=rss-4a804d4f2bb4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 22:47:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adolphasg/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[✨Deploying a Highly Available 2-Tier AWS Architecture with Terraform Modules and Terraform Cloud✨]]></title>
            <link>https://medium.com/@adolphasg/deploying-a-highly-available-2-tier-aws-architecture-with-terraform-modules-and-terraform-cloud-45d288f351f4?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/45d288f351f4</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Sun, 24 Aug 2025 01:47:26 GMT</pubDate>
            <atom:updated>2025-08-24T01:47:26.043Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-_RHm8QP7Z6w_QqiBHf6yg.png" /></figure><p>This comprehensive guide demonstrates how to build a production-ready, highly available two-tier AWS infrastructure using custom Terraform modules, GitHub and Terraform Cloud for automated deployment and management.</p><p><strong>GITHUB REPO: </strong><a href="https://github.com/adolphasg/terraform-2tier">https://github.com/adolphasg/terraform-2tier</a></p><h3>Introduction</h3><p>Modern web applications require robust, scalable infrastructure that can handle traffic across multiple availability zones while maintaining security and cost efficiency. This project creates a complete two-tier architecture on AWS using Infrastructure as Code principles with Terraform, ensuring consistency and repeatability across deployments.</p><h3>Challenge</h3><p>Organizations often struggle with manual infrastructure provisioning, which leads to configuration drift, security vulnerabilities, and deployment inconsistencies. Traditional approaches lack version control, peer review processes, and automated testing capabilities. Additionally, creating reusable infrastructure components that can be shared across teams and environments remains a significant challenge for many development teams.</p><h3>Solution Approach</h3><p>This project addresses these challenges by implementing a modular Terraform architecture with the following approach:</p><ul><li>Custom reusable modules for VPC, web tier, and database components</li><li>Terraform Cloud integration for automated CI/CD pipeline</li><li>Security-first design with proper network segmentation</li><li>High availability across multiple AWS availability zones</li><li>Infrastructure as Code best practices with version control</li></ul><h3>Prerequisites</h3><p>Before starting this project, ensure you have:</p><ul><li>An active AWS account with administrative privileges</li><li>A Terraform Cloud account (free tier available)</li><li>Git repository hosting service (GitHub, GitLab, or Bitbucket)</li><li>Basic understanding of AWS networking concepts</li><li>Familiarity with command line operations</li><li>Text editor or IDE for code development</li></ul><p>This project leverages <strong>Terraform Modules</strong>, <strong>GitHub</strong>, and <strong>Terraform Cloud</strong> to build a robust and manageable AWS infrastructure. These tools are essential because they allow us to define our cloud setup as reusable code, track all changes, and automate deployments reliably, ensuring our infrastructure is consistent, version-controlled, and easy to manage.</p><h3>Terraform Modules</h3><p>Think of Terraform Modules as <strong>pre-built LEGO blocks</strong> for our cloud. Instead of building every single piece of our AWS setup (like a VPC or an EC2 server) from scratch every time, modules let us use ready-made, tested blueprints. This is important because it makes our code much <strong>simpler to read</strong>, <strong>easier to reuse</strong> for other projects, and <strong>less prone to errors</strong> since we’re using proven components. It saves us a lot of time and keeps our infrastructure consistent.</p><h3>GitHub</h3><p>GitHub acts as our project’s <strong>central brain and memory</strong>. It’s where all our Terraform code lives, and every change we make is recorded, like a detailed history book. This is important because it allows us to <strong>track who changed what and when</strong>, easily <strong>go back to previous versions</strong> if something breaks, and <strong>work together with others</strong> without stepping on each other’s toes. It ensures our infrastructure code is always backed up, organized, and transparent.</p><h3>Terraform Cloud</h3><p>Terraform Cloud is like our <strong>automated construction crew</strong> that works directly with AWS. Once we push our code to GitHub, Terraform Cloud automatically picks it up, figures out what needs to be built or changed in AWS, and then does the actual work. This is important because it <strong>automates the deployment process</strong>, keeps a <strong>secure record of our cloud’s current state</strong> (so it knows what’s already built), and ensures that our infrastructure is always deployed in a <strong>consistent and reliable way</strong>, without us having to run complex commands manually from our computer. It’s the glue that brings our code and our cloud together seamlessly.</p><h3>Step-by-Step Implementation</h3><h3>Step 1: Create Project Structure</h3><p>Create a new Git repository and establish the following directory structure:</p><pre>terraform-2tier/  <br>├── main.tf  <br>├── versions.tf  <br>├── variables.tf  <br>├── outputs.tf  <br>├── terraform.tfvars  <br>└── modules/  <br>    ├── vpc/  <br>    │   ├── main.tf  <br>    │   ├── variables.tf  <br>    │   └── outputs.tf  <br>    ├── web/  <br>    │   ├── main.tf  <br>    │   ├── variables.tf  <br>    │   └── outputs.tf  <br>    └── rds/  <br>        ├── main.tf  <br>        ├── variables.tf  <br>        └── outputs.tf</pre><h3>Step 2: Configure Terraform Cloud Backend</h3><p><strong>Terraform Cloud Backend</strong> is a secure online memory for our project, tracking all built cloud resources. It’s crucial for team collaboration, preventing conflicts, and keeping our infrastructure state safe and consistent.</p><p>The versions.tf file is our project&#39;s <strong>rulebook</strong>, specifying exact versions of Terraform and AWS tools to use. This ensures consistent behavior, prevents errors from version mismatches, and guarantees reliable deployments.</p><p>Create the versions.tf file in your project root:</p><pre># Root Terraform settings for this configuration<br>terraform { <br>  # Require Terraform CLI v1.6.0 or newer<br>  required_version = &quot;&gt;= 1.6.0&quot; <br><br>  # Use Terraform Cloud as the backend<br>  cloud { <br>    # Terraform Cloud organization name<br>    organization = &quot;two-tier-prod&quot; <br><br>    # Target workspace in Terraform Cloud<br>    workspaces {<br>      name = &quot;terraform-2tier&quot; <br>    }<br>  }<br><br>  # Required providers block<br>  required_providers {<br>    # Official AWS provider source<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot; <br>      version = &quot;~&gt; 5.50&quot;       <br>    }<br><br>    # Random provider for utilities (strings, IDs)<br>    random = {<br>      source  = &quot;hashicorp/random&quot; <br>      version = &quot;~&gt; 3.6&quot;           <br>    }<br>  }<br>}<br><br># AWS provider configuration<br>provider &quot;aws&quot; {<br>  # AWS region supplied via variable (e.g., &quot;us-east-1&quot;)<br>  region = var.aws_region <br>}</pre><h3>Step 3: Create Variables</h3><p>The variables.tf file is our project&#39;s <strong>customizable settings menu</strong>. It holds changeable details like regions or passwords, making our code flexible, reusable across environments, and safer by separating sensitive information.</p><p>Create variables.tf with all configurable parameters:</p><pre># Project name used as a prefix for resources<br>variable &quot;project_name&quot; {<br>  description = &quot;Project name&quot;<br>  type        = string<br>  default     = &quot;two-tier&quot;<br>}<br><br># AWS region where resources will be deployed<br>variable &quot;aws_region&quot; {<br>  description = &quot;AWS region&quot;<br>  type        = string<br>  default     = &quot;us-east-1&quot;<br>}<br><br># VPC CIDR block for the network<br>variable &quot;vpc_cidr&quot; {<br>  description = &quot;VPC CIDR block&quot;<br>  type        = string<br>  default     = &quot;10.0.0.0/16&quot;<br>}<br><br># CIDR blocks for the public subnets<br>variable &quot;public_subnet_cidrs&quot; {<br>  description = &quot;CIDRs for public subnets&quot;<br>  type        = list(string)<br>  default     = [&quot;10.0.1.0/24&quot;, &quot;10.0.3.0/24&quot;]<br>}<br><br># CIDR blocks for the private subnets<br>variable &quot;private_subnet_cidrs&quot; {<br>  description = &quot;CIDRs for private subnets&quot;<br>  type        = list(string)<br>  default     = [&quot;10.0.2.0/24&quot;, &quot;10.0.4.0/24&quot;]<br>}<br><br># EC2 instance type for web servers<br>variable &quot;web_instance_type&quot; {<br>  description = &quot;Instance type for web servers&quot;<br>  type        = string<br>  default     = &quot;t3.micro&quot;<br>}<br><br># Optional EC2 key pair name for SSH access<br>variable &quot;key_name&quot; {<br>  description = &quot;EC2 key pair name (optional)&quot;<br>  type        = string<br>  default     = &quot;&quot;<br>}<br><br># RDS database username<br>variable &quot;db_username&quot; {<br>  description = &quot;RDS username&quot;<br>  type        = string<br>  default     = &quot;admin&quot;<br>}<br><br># RDS database password (sensitive)<br>variable &quot;db_password&quot; {<br>  description = &quot;RDS password&quot;<br>  type        = string<br>  sensitive   = true<br>}<br><br># RDS database name<br>variable &quot;db_name&quot; {<br>  description = &quot;Database name&quot;<br>  type        = string<br>  default     = &quot;appdb&quot;<br>}<br><br># RDS instance type/class<br>variable &quot;db_instance_class&quot; {<br>  description = &quot;RDS instance class&quot;<br>  type        = string<br>  default     = &quot;db.t3.micro&quot;<br>}<br><br># CIDR range allowed for SSH access<br>variable &quot;allow_ssh_cidr&quot; {<br>  description = &quot;CIDR allowed SSH access&quot;<br>  type        = string<br>  default     = &quot;&quot;<br>}<br></pre><h3>Step 4: Create Main Configuration</h3><p>The main.tf file is the <strong>orchestra conductor</strong> of our project. It&#39;s where we tell Terraform <em>what</em> to build in our cloud, bringing together all the different parts (like VPCs, servers, and databases) defined in our modules and using the settings from our variables. This is important because it&#39;s the central script that defines our entire infrastructure, making it clear and organized how all the pieces fit together to create our desired cloud environment.</p><p>Create main.tf to orchestrate all modules:</p><pre># Define local values used across resources<br>locals {<br>  # Common tags applied to resources<br>  common_tags = {<br>    Project = var.project_name<br>    Managed = &quot;terraform&quot;<br>  }<br>}<br><br># Generate a random string to use as a suffix for unique naming<br>resource &quot;random_string&quot; &quot;suffix&quot; {<br>  length  = 6      # 6 characters long<br>  upper   = false  # no uppercase letters<br>  special = false  # no special characters<br>}<br><br># VPC module for networking setup<br>module &quot;vpc&quot; {<br>  source               = &quot;./modules/vpc&quot;  # Path to VPC module<br>  project_name         = var.project_name<br>  vpc_cidr             = var.vpc_cidr<br>  public_subnet_cidrs  = var.public_subnet_cidrs<br>  private_subnet_cidrs = var.private_subnet_cidrs<br>  tags                 = local.common_tags<br>}<br><br># Web module for EC2 web server provisioning<br>module &quot;web&quot; {<br>  source            = &quot;./modules/web&quot;  # Path to Web module<br>  project_name      = var.project_name<br>  vpc_id            = module.vpc.vpc_id<br>  public_subnet_ids = module.vpc.public_subnet_ids<br>  web_instance_type = var.web_instance_type<br>  key_name          = var.key_name<br>  allow_ssh_cidr    = var.allow_ssh_cidr<br>  tags              = local.common_tags<br>}<br><br># RDS module for relational database setup<br>module &quot;rds&quot; {<br>  source             = &quot;./modules/rds&quot;  # Path to RDS module<br>  project_name       = var.project_name<br>  vpc_id             = module.vpc.vpc_id<br>  private_subnet_ids = module.vpc.private_subnet_ids<br>  db_name            = var.db_name<br>  db_username        = var.db_username<br>  db_password        = var.db_password<br>  db_instance_class  = var.db_instance_class<br>  web_sg_id          = module.web.web_sg_id<br>  tags               = local.common_tags<br>}</pre><h3>Step 5: Configure Project Outputs</h3><p>The outputs.tf file is like our project&#39;s <strong>report card</strong>. After Terraform builds everything in our cloud, this file tells it what important information to show us, such as the website addresses, database connection details, or network IDs. This is important because it gives us immediate, easy access to the key details we need to use or connect to our newly built cloud resources, without having to dig through the AWS console.</p><p>Create outputs.tf to display important information after deployment:</p><pre># Output the public URLs of the web servers<br>output &quot;web_urls&quot; {<br>  description = &quot;Web server URLs&quot;<br>  value       = [for ip in module.web.public_ips : &quot;http://${ip}&quot;]<br>}<br><br># Output the RDS database endpoint<br>output &quot;rds_endpoint&quot; {<br>  description = &quot;Database endpoint&quot;<br>  value       = module.rds.endpoint<br>}<br><br># Output the VPC ID created by the VPC module<br>output &quot;vpc_id&quot; {<br>  description = &quot;VPC ID&quot;<br>  value       = module.vpc.vpc_id<br>}</pre><h3>Step 6: Build VPC Module</h3><p>Create the VPC module files in modules/vpc/:</p><p><strong>modules/vpc/variables.tf:</strong></p><pre># Project name used as a prefix for resources<br>variable &quot;project_name&quot; { type = string }<br><br># VPC CIDR block for the network<br>variable &quot;vpc_cidr&quot; { type = string }<br><br># CIDR blocks for the public subnets<br>variable &quot;public_subnet_cidrs&quot; { type = list(string) }<br><br># CIDR blocks for the private subnets<br>variable &quot;private_subnet_cidrs&quot; { type = list(string) }<br><br># Common tags to apply to all resources<br>variable &quot;tags&quot; { type = map(string) }</pre><p><strong>modules/vpc/main.tf:</strong></p><pre># Get all available AWS availability zones in the current region<br>data &quot;aws_availability_zones&quot; &quot;available&quot; {<br>  state = &quot;available&quot;<br>}<br><br># Create the main VPC with DNS support enabled<br>resource &quot;aws_vpc&quot; &quot;this&quot; {<br>  cidr_block           = var.vpc_cidr<br>  enable_dns_hostnames = true<br>  enable_dns_support   = true<br>  tags = merge(var.tags, { Name = &quot;${var.project_name}-vpc&quot; })<br>}<br><br># Create internet gateway for public subnet internet access<br>resource &quot;aws_internet_gateway&quot; &quot;igw&quot; {<br>  vpc_id = aws_vpc.this.id<br>  tags   = merge(var.tags, { Name = &quot;${var.project_name}-igw&quot; })<br>}<br><br># Create public subnets across multiple availability zones<br>resource &quot;aws_subnet&quot; &quot;public&quot; {<br>  for_each = { for idx, cidr in var.public_subnet_cidrs : idx =&gt; cidr }<br>  vpc_id   = aws_vpc.this.id<br>  cidr_block = each.value<br>  availability_zone = data.aws_availability_zones.available.names[tonumber(each.key)]<br>  map_public_ip_on_launch = true<br>  tags = merge(var.tags, { Name = &quot;${var.project_name}-public-${each.key}&quot;, Tier = &quot;public&quot; })<br>}<br><br># Create private subnets across multiple availability zones<br>resource &quot;aws_subnet&quot; &quot;private&quot; {<br>  for_each = { for idx, cidr in var.private_subnet_cidrs : idx =&gt; cidr }<br>  vpc_id   = aws_vpc.this.id<br>  cidr_block = each.value<br>  availability_zone = data.aws_availability_zones.available.names[tonumber(each.key)]<br>  tags = merge(var.tags, { Name = &quot;${var.project_name}-private-${each.key}&quot;, Tier = &quot;private&quot; })<br>}<br><br># Create route table for public subnets<br>resource &quot;aws_route_table&quot; &quot;public&quot; {<br>  vpc_id = aws_vpc.this.id<br>  tags   = merge(var.tags, { Name = &quot;${var.project_name}-public-rt&quot; })<br>}<br><br># Add default route to internet gateway for public subnets<br>resource &quot;aws_route&quot; &quot;public_default&quot; {<br>  route_table_id = aws_route_table.public.id<br>  destination_cidr_block = &quot;0.0.0.0/0&quot;<br>  gateway_id = aws_internet_gateway.igw.id<br>}<br><br># Associate public subnets with public route table<br>resource &quot;aws_route_table_association&quot; &quot;public&quot; {<br>  for_each = aws_subnet.public<br>  subnet_id = each.value.id<br>  route_table_id = aws_route_table.public.id<br>}<br><br># Create route table for private subnets<br>resource &quot;aws_route_table&quot; &quot;private&quot; {<br>  vpc_id = aws_vpc.this.id<br>  tags   = merge(var.tags, { Name = &quot;${var.project_name}-private-rt&quot; })<br>}<br><br># Associate private subnets with private route table<br>resource &quot;aws_route_table_association&quot; &quot;private&quot; {<br>  for_each = aws_subnet.private<br>  subnet_id = each.value.id<br>  route_table_id = aws_route_table.private.id<br>}</pre><p><strong>modules/vpc/outputs.tf:</strong></p><pre># Output the VPC ID created in this configuration<br>output &quot;vpc_id&quot; {<br>  value = aws_vpc.this.id<br>}<br><br># Output the list of public subnet IDs<br>output &quot;public_subnet_ids&quot; {<br>  value = [for s in aws_subnet.public : s.id]<br>}<br><br># Output the list of private subnet IDs<br>output &quot;private_subnet_ids&quot; {<br>  value = [for s in aws_subnet.private : s.id]<br>}</pre><h3>Step 7: Build Web Tier Module</h3><p>Create the web module files in modules/web/:</p><p><strong>modules/web/variables.tf:</strong></p><pre># Project name used as a prefix for resources<br>variable &quot;project_name&quot; { type = string }<br><br># VPC ID where web resources will be created<br>variable &quot;vpc_id&quot; { type = string }<br><br># List of public subnet IDs for web server placement<br>variable &quot;public_subnet_ids&quot; { type = list(string) }<br><br># EC2 instance type for web servers<br>variable &quot;web_instance_type&quot; { type = string }<br><br># EC2 key pair name for SSH access<br>variable &quot;key_name&quot; { type = string }<br><br># CIDR range allowed for SSH access to web servers<br>variable &quot;allow_ssh_cidr&quot; { type = string }<br><br># Common tags to apply to all web resources<br>variable &quot;tags&quot; { type = map(string) }</pre><p><strong>modules/web/main.tf:</strong></p><pre># Security group for web servers with HTTP/HTTPS and optional SSH access<br>resource &quot;aws_security_group&quot; &quot;web&quot; {<br>  name        = &quot;${var.project_name}-web-sg&quot;<br>  description = &quot;Security group for web servers&quot;<br>  vpc_id      = var.vpc_id<br><br>  # Allow HTTP traffic from anywhere<br>  ingress {<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  <br>  # Allow HTTPS traffic from anywhere<br>  ingress {<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>  <br>  # Conditionally allow SSH access if key pair and CIDR are provided<br>  dynamic &quot;ingress&quot; {<br>    for_each = (var.key_name != &quot;&quot; &amp;&amp; var.allow_ssh_cidr != &quot;&quot;) ? [1] : []<br>    content {<br>      from_port   = 22<br>      to_port     = 22<br>      protocol    = &quot;tcp&quot;<br>      cidr_blocks = [var.allow_ssh_cidr]<br>    }<br>  }<br>  <br>  # Allow all outbound traffic<br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br># Get the latest Amazon Linux 2 AMI<br>data &quot;aws_ami&quot; &quot;al2&quot; {<br>  most_recent = true<br>  owners      = [&quot;137112412989&quot;]<br>  filter {<br>    name   = &quot;name&quot;<br>    values = [&quot;amzn2-ami-hvm-*-x86_64-gp2&quot;]<br>  }<br>}<br><br># User data script to install and configure nginx<br>locals {<br>  user_data = &lt;&lt;-EOF<br>#!/bin/bash<br>set -eux<br>yum update -y<br>amazon-linux-extras install -y nginx1<br>systemctl enable nginx<br>echo &quot;&lt;h1&gt;${var.project_name} Web Server - $$(hostname)&lt;/h1&gt;&quot; &gt; /usr/share/nginx/html/index.html<br>systemctl start nginx<br>EOF<br>}<br><br># Create web server instances across public subnets<br>resource &quot;aws_instance&quot; &quot;web&quot; {<br>  for_each               = { for idx, subnet_id in var.public_subnet_ids : idx =&gt; subnet_id }<br>  ami                    = data.aws_ami.al2.id<br>  instance_type          = var.web_instance_type<br>  subnet_id              = each.value<br>  vpc_security_group_ids = [aws_security_group.web.id]<br>  user_data              = local.user_data<br>  associate_public_ip_address = true<br>  key_name               = var.key_name != &quot;&quot; ? var.key_name : null<br>}</pre><p><strong>modules/web/outputs.tf:</strong></p><pre># Output the ID of the web server security group<br>output &quot;web_sg_id&quot; {<br>  value = aws_security_group.web.id<br>}<br><br># Output the list of public IPs of the web server instances<br>output &quot;public_ips&quot; {<br>  value = [for i in aws_instance.web : i.public_ip]<br>}</pre><h3>Step 8: Build RDS Database Module</h3><p>Create the RDS module files in modules/rds/:</p><p><strong>modules/rds/variables.tf:</strong></p><pre># Project name used for resource naming<br>variable &quot;project_name&quot; {<br>  description = &quot;Project name for resource naming&quot;<br>  type        = string<br>}<br><br># ID of the VPC where database resources will be created<br>variable &quot;vpc_id&quot; {<br>  description = &quot;ID of the VPC where resources will be created&quot;<br>  type        = string<br>}<br><br># Private subnet IDs for placing the RDS instance<br>variable &quot;private_subnet_ids&quot; {<br>  description = &quot;List of private subnet IDs for database deployment&quot;<br>  type        = list(string)<br>}<br><br># Initial database name created inside RDS<br>variable &quot;db_name&quot; {<br>  description = &quot;Initial database name to create&quot;<br>  type        = string<br>}<br><br># Master username for RDS<br>variable &quot;db_username&quot; {<br>  description = &quot;Master username for RDS instance&quot;<br>  type        = string<br>}<br><br># Master password for RDS (sensitive)<br>variable &quot;db_password&quot; {<br>  description = &quot;Master password for RDS instance&quot;<br>  type        = string<br>  sensitive   = true<br>}<br><br># DB instance type/class (e.g., db.t3.micro)<br>variable &quot;db_instance_class&quot; {<br>  description = &quot;RDS instance class&quot;<br>  type        = string<br>}<br><br># Security group ID of the web tier to allow communication with DB<br>variable &quot;web_sg_id&quot; {<br>  description = &quot;Security group ID of the web tier&quot;<br>  type        = string<br>}<br><br># Common tags applied to database resources<br>variable &quot;tags&quot; {<br>  description = &quot;Common tags to apply to all resources&quot;<br>  type        = map(string)<br>}</pre><p><strong>modules/rds/main.tf:</strong></p><pre># Create a DB subnet group spanning the private subnets<br>resource &quot;aws_db_subnet_group&quot; &quot;this&quot; {<br>  name       = &quot;${var.project_name}-db-subnets&quot;<br>  subnet_ids = var.private_subnet_ids<br>}<br><br># Security group for the RDS database<br>resource &quot;aws_security_group&quot; &quot;db&quot; {<br>  name   = &quot;${var.project_name}-db-sg&quot;<br>  vpc_id = var.vpc_id<br><br>  # Allow MySQL traffic (port 3306) only from the web security group<br>  ingress {<br>    from_port       = 3306<br>    to_port         = 3306<br>    protocol        = &quot;tcp&quot;<br>    security_groups = [var.web_sg_id]<br>  }<br><br>  # Allow all outbound traffic<br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br>}<br><br># Create the RDS MySQL database instance<br>resource &quot;aws_db_instance&quot; &quot;mysql&quot; {<br>  identifier             = &quot;${var.project_name}-mysql&quot;<br>  engine                 = &quot;mysql&quot;<br>  engine_version         = &quot;8.0&quot;<br>  instance_class         = var.db_instance_class<br>  allocated_storage      = 20<br>  storage_type           = &quot;gp3&quot;<br>  db_name                = var.db_name<br>  username               = var.db_username<br>  password               = var.db_password<br>  db_subnet_group_name   = aws_db_subnet_group.this.name<br>  vpc_security_group_ids = [aws_security_group.db.id]<br>  multi_az               = false                 # Single AZ deployment<br>  publicly_accessible    = false                 # Private only, not internet-exposed<br>  skip_final_snapshot    = true                  # Delete without final backup<br>  deletion_protection    = false                 # Allow instance deletion<br>}</pre><p><strong>modules/rds/outputs.tf:</strong></p><pre># Output the RDS database endpoint address<br>output &quot;endpoint&quot; {<br>  value = aws_db_instance.mysql.address<br>}</pre><h3>Step 9: Set Up Terraform Cloud</h3><p>Navigate to Terraform Cloud and complete the following configuration:</p><ul><li><strong>Create Organization</strong>: Sign up for Terraform Cloud and create a new organization with a meaningful name.</li><li><strong>Create Workspace</strong>: Create a new workspace named “two-tier-prod” and connect it to your Git repository.</li><li><strong>Configure Environment Variables</strong>: In your workspace settings, add these environment variables:</li><li>AWS_ACCESS_KEY_ID: Your AWS access key (mark as sensitive)</li><li>AWS_SECRET_ACCESS_KEY: Your AWS secret key (mark as sensitive)</li><li>AWS_DEFAULT_REGION: Your preferred AWS region (e.g., us-east-1)</li><li><strong>Set Terraform Variables</strong>: Add these Terraform variables in your workspace:</li><li>db_password: A strong password for your MySQL database (mark as sensitive)</li><li>allow_ssh_cidr: Your public IP address with /32 suffix for SSH access (optional)</li><li>key_name: Name of an existing EC2 key pair for SSH access (optional)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X9aPJlUo8DCog3bCzb3iDw.png" /><figcaption><strong>Environment Variables &amp; Terraform Variables.</strong></figcaption></figure><h3>Step 10: Deploy Infrastructure</h3><ul><li><strong>Update Organization Name</strong>: Edit the versions.tf file and replace &quot;YOUR_TFC_ORG_NAME&quot; with your actual Terraform Cloud organization name.</li><li><strong>Commit and Push Code</strong>: Add all files to your Git repository, commit the changes, and push to your remote repository.</li><li><strong>Monitor Deployment</strong>: Terraform Cloud will automatically detect the changes and start a plan. Review the planned changes in the Terraform Cloud interface.</li><li><strong>Apply Changes</strong>: If the plan looks correct, approve and apply the changes to create your infrastructure.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mNjHvRo9pt4Ih6Axx7QoOg.png" /><figcaption><strong>Confirm &amp; Apply.</strong></figcaption></figure><ul><li><strong>Verify Deployment</strong>: After successful deployment, check the outputs section for web server URLs and database endpoint information.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2PeKgIwDjes_DivHOVqwXA.png" /><figcaption><strong>Outputs.</strong></figcaption></figure><h3>Step 11: Test Your Infrastructure</h3><ul><li><strong>Test Web Servers</strong>: Open the web URLs provided in the outputs. You should see NGINX welcome pages with server hostnames.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ruSqOUYrsZSu-E9tJmhQyw.png" /><figcaption><strong>NGINX Up &amp; Running.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*psOLF-dI1HKpyBoR6nvqEg.png" /><figcaption><strong>NGINX Up &amp; Running.</strong></figcaption></figure><ul><li><strong>Verify High Availability</strong>: Confirm that you have two web servers running in different availability zones.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q6nfRKowsciJqMhNu-KwWg.png" /><figcaption><strong>Our 2 Web Servers Are Running In Different Availability Zones.</strong></figcaption></figure><ul><li><strong>Check Database Connectivity</strong>: The RDS endpoint can be used by applications to connect to the MySQL database.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2mXuzl5yU8gEhxEdxCBdaw.png" /><figcaption><strong>Our Database Created.</strong></figcaption></figure><h3>Key Outcomes</h3><p>This project delivers these main results:</p><ul><li><strong>Highly Available Infrastructure</strong>: Two web servers deployed across different availability zones ensure continuous service availability even if one zone experiences issues.</li><li><strong>Secure Network Architecture</strong>: Private subnets isolate the database tier from direct internet access, while security groups enforce least-privilege access controls between tiers.</li><li><strong>Reusable Infrastructure Modules</strong>: Custom Terraform modules enable consistent deployment patterns that can be reused across multiple environments and projects.</li><li><strong>Automated CI/CD Pipeline</strong>: Terraform Cloud integration provides automated infrastructure deployment, version control, and collaborative infrastructure management capabilities.</li></ul><h3>Challenges and Solutions I Faced Whilst Working On This Project:</h3><ol><li><strong>Challenge</strong>: Terraform couldn’t connect to Terraform Cloud.<br> <strong>Solution</strong>: I ran terraform login to generate the API token and updated the workspace settings. <strong>Context:</strong> Because the project used Terraform Cloud as the backend, Terraform needed a token so it could authenticate with app.terraform.io. Without that token, terraform init/plan failed. Logging in creates a credentials file locally and lets Terraform communicate securely with the remote workspace so state and runs can be managed remotely.</li><li><strong>Challenge</strong>: AWS denied actions — Terraform reported unauthorized API calls.<br> <strong>Solution</strong>: I updated the IAM user permissions, attached a policy that allowed the required EC2, VPC, and RDS actions. <strong>Context:</strong> Terraform uses whatever AWS credentials you provide to read and create resources. If the IAM user is missing permissions like ec2:DescribeImages or ec2:DescribeAvailabilityZones, Terraform cannot even plan. Granting the minimal necessary permissions (or temporarily using broader privileges during testing) allowed Terraform to read AMIs, list AZs, create VPCs, launch EC2, and provision RDS.</li><li><strong>Challenge:</strong> Terraform Cloud wouldn’t allow terraform apply locally because the workspace was VCS‑connected.<br> <strong>Solution</strong>: I adopted the VCS workflow: push changes to GitHub, let Terraform Cloud plan, and then confirm &amp; apply from the UI. <strong>Context:</strong> A VCS‑connected workspace enforces the repository as the single source of truth; it denies local applies to avoid drift. Initially that felt restrictive, but it actually improved safety and traceability: every change is tied to a Git commit, plans are visible in Terraform Cloud, and approvals are auditable. Once I changed my workflow to commit → push → approve in Terraform Cloud, deployments became predictable.</li><li><strong>Challenge:</strong> I couldn’t see outputs (web URLs, DB endpoint) in Terraform Cloud.<br> <strong>Solution</strong>: I triggered a full apply (by making a small, safe change and pushing it) so Terraform Cloud would run an apply and populate outputs. <strong>Context:</strong> Outputs are stored after an apply. If only a plan ran (or if a run resulted in “no changes”), outputs might not be written or visible. Forcing a proper apply ensured the resources were created and the workspace stored the outputs, which made it easy to validate the deployment and retrieve operational values like public IPs and DB endpoints.</li><li><strong>Challenge:</strong> I didn’t understand how GitHub and Terraform Cloud communicate without GitHub Actions.<br> <strong>Solution</strong>: I learned about OAuth and webhooks: Terraform Cloud is authorized to read the repo, and GitHub sends webhook notifications when commits are pushed, which triggers Terraform Cloud runs. <strong>Context:</strong> It seemed like magic at first, but the integration is straightforward: when you connect the repo in Terraform Cloud, you grant it access (OAuth) and a webhook is created on the GitHub side. Every git push rings that webhook and tells Terraform Cloud to pull the latest code and start a plan. Understanding this removed confusion and clarified why no GitHub Actions workflow is required for Terraform Cloud VCS runs.</li></ol><h3>Project Summary</h3><p>This project successfully demonstrates the implementation of a production-ready, highly available two-tier AWS architecture using Infrastructure as Code principles. The solution provides a robust foundation for web applications with proper network segmentation, security controls, and automated deployment capabilities. The modular approach ensures code reusability and maintainability, while Terraform Cloud integration enables collaborative infrastructure management with version control and automated testing. This architecture serves as a solid starting point for scalable web applications that require high availability, security, and operational efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45d288f351f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ A Scalable AWS Auto Scaling Group with Terraform for High-Traffic Applications✨]]></title>
            <link>https://medium.com/@adolphasg/a-scalable-aws-auto-scaling-group-with-terraform-for-high-traffic-applications-8da2858d58da?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8da2858d58da</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 00:53:06 GMT</pubDate>
            <atom:updated>2025-08-10T03:02:14.912Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2TsfY5uQcqKKDHzdr-eYGw.jpeg" /></figure><p>This project demonstrates how to deploy a highly available web infrastructure on AWS using Terraform, featuring an Auto Scaling Group that automatically adjusts capacity based on demand while maintaining fault tolerance across multiple availability zones.</p><p><strong>GITHUB REPO: </strong><a href="https://github.com/adolphasg/aws-asg-terraform">https://github.com/adolphasg/aws-asg-terraform</a></p><h3>Introduction</h3><p>Modern web applications must handle unpredictable traffic patterns, especially during peak seasons or viral events. Traditional static server deployments often struggle with sudden traffic spikes, leading to poor user experience or complete service outages. This project creates a dynamic infrastructure that automatically scales web servers up or down based on real-time demand.</p><h3>Challenge</h3><p>E-commerce businesses and web applications face significant challenges during high-traffic periods such as holiday seasons, flash sales, or unexpected viral content. Static infrastructure either over-provisions resources (wasting money) or under-provisions (causing outages). Manual scaling is too slow and error-prone for modern applications that need instant responsiveness.</p><h3>Solution Approach</h3><p>I implemented an AWS Auto Scaling Group spanning multiple availability zones with automated scaling policies. The solution uses Terraform for infrastructure as code, ensuring reproducible deployments. Apache web servers are automatically configured on launch, and all infrastructure state is stored remotely in S3 for team collaboration and disaster recovery.</p><h3>Prerequisites</h3><p>Before starting this project, ensure you have:</p><ul><li>An active AWS account with administrative permissions</li><li>AWS CLI installed and configured with your credentials</li><li>Terraform version 1.5 or higher installed on your local machine</li><li>A default VPC in your chosen AWS region (most accounts have this by default)</li><li>Basic understanding of command line operations</li></ul><h3>Step-by-Step Implementation</h3><h3>Step 1: Create Project Structure</h3><p>Create a new directory for your project and navigate into it. You will need three Terraform configuration files to organize your infrastructure code properly.</p><p>Create variables.tf to define all configurable parameters:</p><pre># Project identification and AWS region configuration<br>variable &quot;project_name&quot; {<br>  description = &quot;A short name for tagging and resource naming&quot;<br>  type        = string<br>  default     = &quot;holiday-asg&quot;<br>}<br><br>variable &quot;aws_region&quot; {<br>  description = &quot;AWS region to deploy infrastructure&quot;<br>  type        = string<br>  default     = &quot;us-east-1&quot;<br>}<br><br># EC2 instance configuration<br>variable &quot;instance_type&quot; {<br>  description = &quot;EC2 instance type for Auto Scaling Group&quot;<br>  type        = string<br>  default     = &quot;t3.micro&quot;<br>}<br><br># Auto Scaling Group capacity settings<br>variable &quot;min_size&quot; {<br>  description = &quot;Minimum number of instances in the ASG&quot;<br>  type        = number<br>  default     = 2<br>}<br><br>variable &quot;desired_capacity&quot; {<br>  description = &quot;Desired number of instances in the ASG&quot;<br>  type        = number<br>  default     = 2<br>}<br><br>variable &quot;max_size&quot; {<br>  description = &quot;Maximum number of instances in the ASG&quot;<br>  type        = number<br>  default     = 5<br>}<br><br># Security configuration options<br>variable &quot;enable_ssh&quot; {<br>  description = &quot;Whether to allow SSH access to instances&quot;<br>  type        = bool<br>  default     = false<br>}<br><br>variable &quot;ssh_cidr&quot; {<br>  description = &quot;CIDR block allowed for SSH access if enabled&quot;<br>  type        = string<br>  default     = &quot;0.0.0.0/0&quot;<br>}<br><br>variable &quot;key_name&quot; {<br>  description = &quot;Optional EC2 key pair name for SSH access&quot;<br>  type        = string<br>  default     = &quot;&quot;<br>}<br><br># Scaling policy configuration<br>variable &quot;cpu_target_utilization&quot; {<br>  description = &quot;Target average CPU utilization for auto scaling&quot;<br>  type        = number<br>  default     = 50<br>}</pre><p>Create outputs.tf to display important information after deployment:</p><pre># Display Auto Scaling Group name for reference<br>output &quot;asg_name&quot; {<br>  description = &quot;Name of the Auto Scaling Group&quot;<br>  value       = aws_autoscaling_group.web_asg.name<br>}<br><br># Display security group ID for troubleshooting<br>output &quot;security_group_id&quot; {<br>  description = &quot;Security group ID attached to instances&quot;<br>  value       = aws_security_group.web_sg.id<br>}<br><br># Display subnet IDs used by the ASG<br>output &quot;selected_subnet_ids&quot; {<br>  description = &quot;The two subnets used by the ASG&quot;<br>  value       = local.selected_subnet_ids<br>}<br><br># Display S3 bucket name for state management<br>output &quot;s3_backend_bucket_name&quot; {<br>  description = &quot;S3 bucket created for Terraform state storage&quot;<br>  value       = aws_s3_bucket.tf_state_bucket.bucket<br>}</pre><h3>Step 2: Configure Main Infrastructure</h3><p>Create main.tf with the core infrastructure configuration:</p><pre># Terraform and provider version requirements<br>terraform {<br>  required_version = &quot;&gt;= 1.5.0&quot;<br><br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br><br>  # Initially commented out - will enable after S3 bucket creation<br>  # backend &quot;s3&quot; {}<br>}<br><br># Configure AWS provider with specified region<br>provider &quot;aws&quot; {<br>  region = var.aws_region<br>}<br><br># Data sources for dynamic resource naming and identification<br>data &quot;aws_caller_identity&quot; &quot;current&quot; {}<br>data &quot;aws_region&quot; &quot;current&quot; {}<br><br># Locate the default VPC in the current region<br>data &quot;aws_vpc&quot; &quot;default&quot; {<br>  default = true<br>}<br><br># Find all default subnets in the default VPC<br>data &quot;aws_subnets&quot; &quot;default&quot; {<br>  filter {<br>    name   = &quot;vpc-id&quot;<br>    values = [data.aws_vpc.default.id]<br>  }<br><br>  # Only select subnets that are default for their availability zone<br>  filter {<br>    name   = &quot;default-for-az&quot;<br>    values = [&quot;true&quot;]<br>  }<br>}<br><br># Local values for computed configurations<br>locals {<br>  # Select first two subnets for high availability deployment<br>  selected_subnet_ids = slice(data.aws_subnets.default.ids, 0, 2)<br><br>  # Generate unique S3 bucket name using account ID<br>  tf_state_bucket_name = &quot;${var.project_name}-tfstate-${data.aws_caller_identity.current.account_id}&quot;<br>}<br><br># S3 bucket for storing Terraform state remotely<br>resource &quot;aws_s3_bucket&quot; &quot;tf_state_bucket&quot; {<br>  bucket = local.tf_state_bucket_name<br>  tags = {<br>    Name        = &quot;${var.project_name}-tfstate&quot;<br>    Project     = var.project_name<br>    Environment = &quot;prod&quot;<br>  }<br>}<br><br># Enable versioning on the state bucket for rollback capability<br>resource &quot;aws_s3_bucket_versioning&quot; &quot;tf_state_bucket_versioning&quot; {<br>  bucket = aws_s3_bucket.tf_state_bucket.id<br>  versioning_configuration {<br>    status = &quot;Enabled&quot;<br>  }<br>}<br><br># Enable encryption for the state bucket<br>resource &quot;aws_s3_bucket_server_side_encryption_configuration&quot; &quot;tf_state_bucket_sse&quot; {<br>  bucket = aws_s3_bucket.tf_state_bucket.id<br>  rule {<br>    apply_server_side_encryption_by_default {<br>      sse_algorithm = &quot;AES256&quot;<br>    }<br>  }<br>}<br><br># Security group allowing web traffic from internet<br>resource &quot;aws_security_group&quot; &quot;web_sg&quot; {<br>  name        = &quot;${var.project_name}-web-sg&quot;<br>  description = &quot;Allow web traffic from the internet&quot;<br>  vpc_id      = data.aws_vpc.default.id<br><br>  # Allow HTTP traffic on port 80<br>  ingress {<br>    description = &quot;HTTP&quot;<br>    from_port   = 80<br>    to_port     = 80<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }<br><br>  # Allow HTTPS traffic on port 443<br>  ingress {<br>    description = &quot;HTTPS&quot;<br>    from_port   = 443<br>    to_port     = 443<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }<br><br>  # Conditionally allow SSH access if enabled<br>  dynamic &quot;ingress&quot; {<br>    for_each = var.enable_ssh ? [1] : []<br>    content {<br>      description = &quot;SSH&quot;<br>      from_port   = 22<br>      to_port     = 22<br>      protocol    = &quot;tcp&quot;<br>      cidr_blocks = [var.ssh_cidr]<br>    }<br>  }<br><br>  # Allow all outbound traffic for updates and dependencies<br>  egress {<br>    from_port        = 0<br>    to_port          = 0<br>    protocol         = &quot;-1&quot;<br>    cidr_blocks      = [&quot;0.0.0.0/0&quot;]<br>    ipv6_cidr_blocks = [&quot;::/0&quot;]<br>  }<br><br>  tags = {<br>    Name    = &quot;${var.project_name}-web-sg&quot;<br>    Project = var.project_name<br>  }<br>}<br><br># Find the latest Amazon Linux 2 AMI<br>data &quot;aws_ami&quot; &quot;al2&quot; {<br>  most_recent = true<br>  owners      = [&quot;amazon&quot;]<br><br>  filter {<br>    name   = &quot;name&quot;<br>    values = [&quot;amzn2-ami-hvm-*-x86_64-gp2&quot;]<br>  }<br>}<br><br># User data script to install and configure Apache web server<br>locals {<br>  user_data = &lt;&lt;-EOF<br>    #!/bin/bash<br>    set -euo pipefail<br>    <br>    # Update system packages<br>    yum update -y<br>    <br>    # Install Apache web server<br>    yum install -y httpd<br>    <br>    # Enable Apache to start on boot<br>    systemctl enable httpd<br>    systemctl start httpd<br><br>    # Get instance metadata for display<br>    INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id || echo &quot;unknown&quot;)<br>    AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone || echo &quot;unknown&quot;)<br><br>    # Create custom HTML page showing instance information<br>    cat &gt; /var/www/html/index.html &lt;&lt;EOT<br>    &lt;html&gt;<br>      &lt;head&gt;&lt;title&gt;${var.project_name} - Web Server&lt;/title&gt;&lt;/head&gt;<br>      &lt;body style=&quot;font-family: Arial; margin: 2rem;&quot;&gt;<br>        &lt;h1&gt;${var.project_name} - Auto Scaling Web Server&lt;/h1&gt;<br>        &lt;p&gt;Instance ID: $INSTANCE_ID&lt;/p&gt;<br>        &lt;p&gt;Availability Zone: $AZ&lt;/p&gt;<br>        &lt;p&gt;Deployed via Terraform Infrastructure as Code&lt;/p&gt;<br>      &lt;/body&gt;<br>    &lt;/html&gt;<br>    EOT<br>  EOF<br>}<br><br># Launch template defining instance configuration<br>resource &quot;aws_launch_template&quot; &quot;web_lt&quot; {<br>  name_prefix   = &quot;${var.project_name}-lt-&quot;<br>  image_id      = data.aws_ami.al2.id<br>  instance_type = var.instance_type<br><br>  # Conditionally set SSH key pair if provided<br>  key_name = var.key_name != &quot;&quot; ? var.key_name : null<br><br>  update_default_version = true<br><br>  # Network configuration for public access<br>  network_interfaces {<br>    associate_public_ip_address = true<br>    security_groups             = [aws_security_group.web_sg.id]<br>  }<br><br>  # Encode user data script for instance initialization<br>  user_data = base64encode(local.user_data)<br><br>  # Tags applied to launched instances<br>  tag_specifications {<br>    resource_type = &quot;instance&quot;<br>    tags = {<br>      Name        = &quot;${var.project_name}-web&quot;<br>      Project     = var.project_name<br>      Role        = &quot;web&quot;<br>      ManagedBy   = &quot;terraform&quot;<br>    }<br>  }<br><br>  tags = {<br>    Name    = &quot;${var.project_name}-lt&quot;<br>    Project = var.project_name<br>  }<br>}<br><br># Auto Scaling Group spanning multiple availability zones<br>resource &quot;aws_autoscaling_group&quot; &quot;web_asg&quot; {<br>  name                      = &quot;${var.project_name}-asg&quot;<br>  desired_capacity          = var.desired_capacity<br>  min_size                  = var.min_size<br>  max_size                  = var.max_size<br>  vpc_zone_identifier       = local.selected_subnet_ids<br>  health_check_type         = &quot;EC2&quot;<br>  health_check_grace_period = 60<br><br>  # Reference to launch template for instance configuration<br>  launch_template {<br>    id      = aws_launch_template.web_lt.id<br>    version = &quot;$Latest&quot;<br>  }<br><br>  # Configuration for smooth rolling updates<br>  min_elb_capacity           = 0<br>  force_delete               = true<br>  wait_for_capacity_timeout  = &quot;10m&quot;<br><br>  # Tags propagated to all instances<br>  tag {<br>    key                 = &quot;Name&quot;<br>    value               = &quot;${var.project_name}-web&quot;<br>    propagate_at_launch = true<br>  }<br><br>  tag {<br>    key                 = &quot;Project&quot;<br>    value               = var.project_name<br>    propagate_at_launch = true<br>  }<br><br>  # Ensure proper resource lifecycle management<br>  lifecycle {<br>    create_before_destroy = true<br>  }<br>}<br><br># Auto scaling policy based on CPU utilization<br>resource &quot;aws_autoscaling_policy&quot; &quot;cpu_target&quot; {<br>  name                   = &quot;${var.project_name}-cpu-target&quot;<br>  autoscaling_group_name = aws_autoscaling_group.web_asg.name<br>  policy_type            = &quot;TargetTrackingScaling&quot;<br><br>  # Scale based on average CPU utilization across all instances<br>  target_tracking_configuration {<br>    predefined_metric_specification {<br>      predefined_metric_type = &quot;ASGAverageCPUUtilization&quot;<br>    }<br>    target_value = var.cpu_target_utilization<br>  }<br>}</pre><h3>Step 3: Initialize and Deploy Infrastructure</h3><p>Navigate to your project directory and run the following commands to deploy your infrastructure:</p><p>Initialize Terraform and download required providers:</p><pre>terraform init</pre><p>Validate your configuration syntax:</p><pre>terraform validate</pre><p>Preview the infrastructure changes:</p><pre>terraform plan</pre><p>Apply the configuration to create resources:</p><pre>terraform apply -auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-otlfEhv1xbWjk4uqnPdjw.png" /><figcaption><strong>Resources Created Successfully.</strong></figcaption></figure><p>This process will create your S3 bucket, security group, launch template, and Auto Scaling Group with two running instances.</p><h3>Step 4: Verify Web Server Deployment</h3><p>After deployment completes, verify that your web servers are running and accessible. You can find the public IP addresses of your instances using the AWS Console or CLI.</p><p>Using AWS Console:</p><ol><li>Navigate to EC2 Dashboard</li><li>Click on Instances</li><li>Filter by tag Name containing your project name</li><li>Copy the Public IPv4 addresses</li><li>Open each IP address in your browser using <a href="http://public_ip/">http://PUBLIC_IP</a></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlarTMFYBhpk2_ZOeoW9dQ.png" /><figcaption><strong>Minimum 2 Instances Created As Per Our Script.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3abDm-9Dq5pywKE96Fs-A.png" /><figcaption><strong>Apache Web Server.</strong></figcaption></figure><p>Using AWS CLI:</p><pre>aws ec2 describe-instances --filters &quot;Name=tag:Name,Values=holiday-asg-web&quot; &quot;Name=instance-state-name,Values=running&quot; --query &quot;Reservations[].Instances[].PublicIpAddress&quot; --output text</pre><p>You should see a webpage displaying the instance ID and availability zone, confirming that Apache is running correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SLcBiz0KYBNtC-UQtxHT5g.png" /><figcaption><strong>Confirmation That Apache Is Running From The CLI.</strong></figcaption></figure><h3>Step 5: Test Auto Scaling and Fault Tolerance</h3><p>Test the fault tolerance by manually terminating one instance to verify that the Auto Scaling Group automatically replaces it.</p><p>Using AWS Console:</p><ol><li>Go to EC2 Instances</li><li>Select one of your web server instances</li><li>Choose Instance State &gt; Terminate</li><li>Monitor the Auto Scaling Group to see replacement instance launch</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D_-7b6ZBjwqJ0LszXhanpA.png" /><figcaption><strong>Terminated One Of Our Running Instance.</strong></figcaption></figure><p>The Auto Scaling Group will detect the capacity drop and launch a new instance within a few minutes to maintain the minimum of two instances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P2IyvwJBcGUuLm-39yZMyQ.png" /><figcaption><strong>ASG Launching A New Instance To Replace The Terminated One.</strong></figcaption></figure><h3>Step 6: Configure Remote State Storage</h3><p>Now that your S3 bucket exists, migrate your Terraform state from local storage to the S3 bucket for better collaboration and backup.</p><p>Edit the terraform block in main.tf to enable the S3 backend:</p><pre>terraform {<br>  required_version = &quot;&gt;= 1.5.0&quot;<br><br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 5.0&quot;<br>    }<br>  }<br><br>  backend &quot;s3&quot; {<br>    bucket = &quot;&lt;bucket_name&gt;&quot;<br>    key    = &quot;terraform.tfstate&quot;<br>    region = &quot;&lt;your_region&gt;&quot;<br>  }</pre><p>Get your S3 bucket name:</p><pre>terraform output -raw s3_backend_bucket_name</pre><p>Re-initialize Terraform with backend configuration:</p><pre>terraform init \<br>  -backend-config=&quot;bucket=$(terraform output -raw s3_backend_bucket_name)&quot; \<br>  -backend-config=&quot;key=terraform.tfstate&quot; \<br>  -backend-config=&quot;region=us-east-1&quot;</pre><p>Terraform will prompt you to migrate your existing state to S3. Type “yes” to confirm the migration.</p><h3>Step 7: Test Scaling Behavior</h3><p>Your Auto Scaling Group is now configured with CPU-based scaling. To test this behavior, you can generate load on your instances or modify the scaling parameters.</p><p>To change capacity during high-traffic periods, update the variables in variables.tf and reapply:</p><pre>terraform apply -auto-approve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7k7iDE8TLvX9cNo4gor6g.png" /><figcaption><strong>Changed Capacity &amp; Ran Terraform Apply.</strong></figcaption></figure><p>The scaling policy will automatically adjust the number of instances based on average CPU utilization across the group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UKsS302PK1ZdCE_C1qMjzA.png" /><figcaption><strong>Instances Adjusted to 4.</strong></figcaption></figure><h3>Key Outcomes</h3><p>This project delivers the following main results that provide significant value for web applications:</p><p><strong>Automatic High Availability</strong>: The infrastructure spans multiple availability zones, ensuring your application remains accessible even if an entire data center experiences issues. The Auto Scaling Group continuously monitors instance health and replaces failed instances automatically.</p><p><strong>Dynamic Cost Optimization</strong>: Resources scale up during high-traffic periods to maintain performance and scale down during quiet periods to minimize costs. This eliminates the need for over-provisioning static infrastructure that sits idle most of the time.</p><p><strong>Infrastructure as Code Management</strong>: All infrastructure is defined in version-controlled Terraform files, enabling consistent deployments, easy rollbacks, and collaborative development. The remote state storage in S3 provides team access and prevents configuration conflicts.</p><p><strong>Zero-Downtime Scaling</strong>: The system can handle traffic spikes without manual intervention or service interruption. New instances launch automatically with pre-configured Apache servers, and the launch template ensures consistent configuration across all instances.</p><h3>Common Challenges and Solutions I Faced Whilst Working On This Project:</h3><ul><li><strong>Challenge:</strong> Setting up the Auto Scaling Group across two subnets was confusing at first. <strong>Solution:</strong> I used the default VPC’s two public subnets and let Terraform pick them with data sources to keep it simple.</li><li><strong>Challenge:</strong> The launch template failed because I treated key_name as a block instead of a setting. <strong>Solution:</strong> I fixed it by setting key_name as a single argument (or null) instead of using a dynamic block.</li><li><strong>Challenge:</strong> Verifying the two running servers and replacements after termination was time-consuming. <strong>Solution:</strong> I used tags and a quick AWS CLI command to list public IPs and watched the ASG activity to confirm auto-healing.</li><li><strong>Challenge:</strong> Backend errors appeared after changing S3 settings. <strong>Solution:</strong> I re-initialized with terraform init -migrate-state (or -reconfigure when not moving the state) and passed bucket, key, and region explicitly.</li><li><strong>Challenge:</strong> Terraform couldn’t delete the S3 bucket during clean up, because it was versioned and not empty. <strong>Solution:</strong> I switched state to local, enabled force_destroy on the bucket, and then ran terraform destroy to remove all versions safely.</li></ul><h3>Project Summary</h3><p>This project successfully demonstrates how to build a production-ready, scalable web infrastructure using Terraform and AWS Auto Scaling Groups. The solution automatically handles traffic fluctuations while maintaining high availability across multiple availability zones. By implementing infrastructure as code practices with remote state management, the system provides a solid foundation for team collaboration and reliable deployments. The combination of automated scaling, fault tolerance, and cost optimization makes this approach ideal for modern web applications that need to handle unpredictable traffic patterns efficiently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8da2858d58da" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ Jenkins CI/CD Server on AWS Using Terraform Infrastructure as Code✨]]></title>
            <link>https://medium.com/@adolphasg/jenkins-ci-cd-server-on-aws-using-terraform-infrastructure-as-code-8fb73c53a330?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fb73c53a330</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Thu, 07 Aug 2025 04:13:06 GMT</pubDate>
            <atom:updated>2025-08-07T14:17:05.683Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dPjVJyV4aPuAXbrXPhc8Dw.jpeg" /></figure><p>Modern software development teams require automated build, test, and deployment processes to maintain code quality and accelerate delivery cycles. This project demonstrates how to provision a Jenkins server on Amazon Web Services using Terraform, creating a scalable and reproducible infrastructure foundation for continuous integration and continuous deployment workflows.</p><p><strong>GITHUB REPO:</strong> <a href="https://github.com/adolphasg/jenkins-terraform-aws">https://github.com/adolphasg/jenkins-terraform-aws</a></p><h3>Introduction</h3><p>Jenkins serves as a powerful automation server that enables development teams to implement CI/CD pipelines effectively. By deploying Jenkins on AWS infrastructure managed through Terraform, organizations can ensure consistent environments across development, staging, and production while maintaining complete control over their automation infrastructure.</p><h3>Challenge</h3><p>Traditional manual server provisioning creates several operational challenges including inconsistent environments, lengthy setup times, configuration drift, and difficulty in disaster recovery. Teams often struggle with maintaining identical Jenkins configurations across multiple environments, leading to deployment failures and reduced productivity. Additionally, manual infrastructure management lacks proper version control and audit trails.</p><h3>Solution Approach</h3><p>This project implements Infrastructure as Code principles using Terraform to automate Jenkins server deployment on AWS. The solution provisions an EC2 instance with automated Jenkins installation, configures appropriate security groups for controlled access, and creates an S3 bucket for artifact storage. All infrastructure components are defined in version-controlled Terraform files, ensuring reproducible deployments and proper change management.</p><h3>Prerequisites</h3><p>Before starting this project, ensure you have the following components ready:</p><ul><li>Active AWS account with administrative permissions for EC2, S3, and VPC services</li><li>Terraform version 1.0 or higher installed on your local machine</li><li>AWS CLI configured with valid credentials using aws configure command</li><li>Git installed for version control operations</li><li>Existing/ Create EC2 Key Pair in your target AWS region for SSH access</li></ul><h3>Step-by-Step Implementation</h3><h3>Step 1: Project Structure Setup</h3><p>Create a new directory for your Terraform project:</p><pre># Create project directory and navigate into it<br>mkdir jenkins-terraform-aws<br>cd jenkins-terraform-aws<br></pre><p>Your project structure should follow this organization:</p><pre>jenkins-terraform-aws/<br>├── main.tf              # Main infrastructure definitions<br>├── variables.tf         # Input variable declarations<br>├── providers.tf         # Provider configurations<br>├── outputs.tf          # Output value definitions<br>├── install_jenkins.sh  # Jenkins installation script<br>└── README.md           # Project documentation</pre><h3>Step 2: Provider Configuration</h3><p>Create the providers.tf file it tells Terraform <em>which cloud</em> (like AWS, Azure, or Google Cloud) we want to work with and how to connect to it, so Terraform knows where to create all our resources:</p><pre># providers.tf<br>terraform {<br>  required_providers {<br>    aws = {<br>      source  = &quot;hashicorp/aws&quot;<br>      version = &quot;~&gt; 6.0&quot;<br>    }<br>  }<br>}<br><br># Configure the AWS Provider<br>provider &quot;aws&quot; {<br>  region = &quot;us-east-1&quot;<br>}</pre><h3>Step 3: Variable Definitions</h3><p>Create the variables.tf file it lets us easily change settings (like the server size or bucket name) without directly editing the main code, making our project flexible and reusable for different situations:</p><pre># variables.tf<br>variable &quot;ami_id&quot; {<br>  description = &quot;AMI ID for the Jenkins server&quot;<br>  type        = string<br>  default     = null<br>}<br><br>variable &quot;instance_type&quot; {<br>  description = &quot;EC2 instance type for Jenkins server&quot;<br>  type        = string<br>  default     = &quot;t2.micro&quot;<br>}<br><br>variable &quot;user_data_file&quot; {<br>  description = &quot;Path to the user data script file&quot;<br>  type        = string<br>  default     = &quot;install_jenkins.sh&quot;<br>}<br><br>variable &quot;jenkins_sg_name&quot; {<br>  description = &quot;Name of the Jenkins security group&quot;<br>  type        = string<br>  default     = &quot;jenkins-security-group&quot;<br>}<br><br>variable &quot;jenkins_sg_description&quot; {<br>  description = &quot;Description for the Jenkins security group&quot;<br>  type        = string<br>  default     = &quot;Security group for Jenkins server with SSH and web access&quot;<br>}<br><br>variable &quot;ssh_port&quot; {<br>  description = &quot;SSH port number&quot;<br>  type        = number<br>  default     = 22<br>}<br><br>variable &quot;https_port&quot; {<br>  description = &quot;HTTPS port number&quot;<br>  type        = number<br>  default     = 443<br>}<br><br>variable &quot;jenkins_port&quot; {<br>  description = &quot;Jenkins web interface port&quot;<br>  type        = number<br>  default     = 8080<br>}<br><br>variable &quot;ssh_cidr_blocks&quot; {<br>  description = &quot;CIDR blocks allowed for SSH access&quot;<br>  type        = list(string)<br>  default     = [&quot;0.0.0.0/0&quot;]<br>}<br><br>variable &quot;https_cidr_blocks&quot; {<br>  description = &quot;CIDR blocks allowed for HTTPS access&quot;<br>  type        = list(string)<br>  default     = [&quot;0.0.0.0/0&quot;]<br>}<br><br>variable &quot;jenkins_web_cidr_blocks&quot; {<br>  description = &quot;CIDR blocks allowed for Jenkins web interface access&quot;<br>  type        = list(string)<br>  default     = [&quot;0.0.0.0/0&quot;]<br>}<br><br>variable &quot;egress_cidr_blocks&quot; {<br>  description = &quot;CIDR blocks for outbound traffic&quot;<br>  type        = list(string)<br>  default     = [&quot;0.0.0.0/0&quot;]<br>}<br><br>variable &quot;bucket_name&quot; {<br>  description = &quot;S3 bucket name for Jenkins artifacts (must be globally unique)&quot;<br>  type        = string<br>}<br><br>variable &quot;environment&quot; {<br>  description = &quot;Environment name (e.g., Development, Production, Staging)&quot;<br>  type        = string<br>  default     = &quot;Development&quot;<br>}<br><br>variable &quot;project_name&quot; {<br>  description = &quot;Project name for resource tagging&quot;<br>  type        = string<br>  default     = &quot;Jenkins-Terraform-Deployment&quot;<br>}<br><br>variable &quot;jenkins_server_name&quot; {<br>  description = &quot;Name tag for Jenkins server&quot;<br>  type        = string<br>  default     = &quot;Jenkins-Server&quot;<br>}<br><br>variable &quot;jenkins_sg_tag_name&quot; {<br>  description = &quot;Name tag for Jenkins security group&quot;<br>  type        = string<br>  default     = &quot;Jenkins-Security-Group&quot;<br>}<br><br>variable &quot;s3_bucket_tag_name&quot; {<br>  description = &quot;Name tag for S3 bucket&quot;<br>  type        = string<br>  default     = &quot;Jenkins-Build-Artifacts&quot;<br>}<br><br>variable &quot;block_public_acls&quot; {<br>  description = &quot;Whether to block public ACLs on S3 bucket&quot;<br>  type        = bool<br>  default     = true<br>}<br><br>variable &quot;block_public_policy&quot; {<br>  description = &quot;Whether to block public bucket policies on S3 bucket&quot;<br>  type        = bool<br>  default     = true<br>}<br><br>variable &quot;ignore_public_acls&quot; {<br>  description = &quot;Whether to ignore public ACLs on S3 bucket&quot;<br>  type        = bool<br>  default     = true<br>}<br><br>variable &quot;restrict_public_buckets&quot; {<br>  description = &quot;Whether to restrict public bucket policies on S3 bucket&quot;<br>  type        = bool<br>  default     = true<br>}<br><br>variable &quot;use_dynamic_ami&quot; {<br>  description = &quot;Whether to use dynamic AMI lookup instead of specified AMI ID&quot;<br>  type        = bool<br>  default     = false<br>}<br><br>variable &quot;ami_name_filter&quot; {<br>  description = &quot;Name filter for dynamic AMI lookup&quot;<br>  type        = list(string)<br>  default     = [&quot;amzn2-ami-hvm-*-x86_64-gp2&quot;]<br>}<br><br>variable &quot;ami_owners&quot; {<br>  description = &quot;Owners for dynamic AMI lookup&quot;<br>  type        = list(string)<br>  default     = [&quot;amazon&quot;]<br>}<br><br>variable &quot;common_tags&quot; {<br>  description = &quot;Common tags to apply to all resources&quot;<br>  type        = map(string)<br>  default     = {}<br>}</pre><h3>Step 4: Jenkins Installation Script</h3><p>Create the scripts/install_jenkins.sh we need a Jenkins installation script file because it bootstraps the EC2 server — meaning, as soon as the server launches, the script automatically installs and configures Jenkins for us. This ensures that every time we create a new server, Jenkins is set up the same way, without any manual work, making the process faster, more reliable, and consistent:</p><pre>#!/bin/bash<br><br># Update all system packages to the latest version<br>sudo yum update -y<br><br># Download the Jenkins repository file and save it to the yum repos directory<br>sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo<br><br># Import the Jenkins repository GPG key for package verification<br>sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key<br><br># Upgrade all packages to the latest version (again, in case new repos added updates)<br>sudo yum upgrade -y<br><br># Install Amazon Corretto 17 (OpenJDK 17) development kit, required for Jenkins<br>sudo yum install java-17-amazon-corretto-devel -y<br><br># Install Jenkins<br>sudo yum install jenkins -y<br><br># Enable Jenkins to start on system boot<br>sudo systemctl enable jenkins<br><br># Start the Jenkins service immediately<br>sudo systemctl start jenkinsStep 5: Main Infrastructure Configuration</pre><p>Create the main.tf file it’s the central blueprint where we describe all the cloud resources (like servers, security settings, and storage) that we want Terraform to create and manage for our project:</p><pre># main.tf<br><br># Data source for dynamic AMI lookup (optional)<br>data &quot;aws_ami&quot; &quot;jenkins&quot; {<br>  count       = var.use_dynamic_ami ? 1 : 0<br>  most_recent = true<br>  owners      = var.ami_owners<br><br>  filter {<br>    name   = &quot;name&quot;<br>    values = var.ami_name_filter<br>  }<br>}<br><br># Local values for computed tags and AMI selection<br>locals {<br>  ami_id = var.use_dynamic_ami ? data.aws_ami.jenkins[0].id : var.ami_id<br><br>  common_tags = merge(<br>    {<br>      Environment = var.environment<br>      Project     = var.project_name<br>    },<br>    var.common_tags<br>  )<br>}<br><br># Jenkins EC2 instance<br>resource &quot;aws_instance&quot; &quot;jenkins&quot; {<br>  ami           = local.ami_id<br>  instance_type = var.instance_type<br>  user_data     = file(var.user_data_file)<br><br>  vpc_security_group_ids = [aws_security_group.jenkins_sg.id]<br><br>  tags = merge(<br>    local.common_tags,<br>    {<br>      Name = var.jenkins_server_name<br>    }<br>  )<br>}<br><br># Security group for Jenkins server with controlled access<br>resource &quot;aws_security_group&quot; &quot;jenkins_sg&quot; {<br>  name        = var.jenkins_sg_name<br>  description = var.jenkins_sg_description<br><br>  # SSH access rule<br>  ingress {<br>    description = &quot;SSH access&quot;<br>    from_port   = var.ssh_port<br>    to_port     = var.ssh_port<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = var.ssh_cidr_blocks<br>  }<br><br>  # HTTPS access rule<br>  ingress {<br>    description = &quot;Allow HTTPS Traffic&quot;<br>    from_port   = var.https_port<br>    to_port     = var.https_port<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = var.https_cidr_blocks<br>  }<br><br>  # Jenkins web interface access rule<br>  ingress {<br>    description = &quot;Jenkins web interface access&quot;<br>    from_port   = var.jenkins_port<br>    to_port     = var.jenkins_port<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = var.jenkins_web_cidr_blocks<br>  }<br><br>  # Outbound traffic rule<br>  egress {<br>    description = &quot;All outbound traffic&quot;<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = var.egress_cidr_blocks<br>  }<br><br>  tags = merge(<br>    local.common_tags,<br>    {<br>      Name = var.jenkins_sg_tag_name<br>    }<br>  )<br>}<br><br># S3 bucket for storing Jenkins build artifacts<br>resource &quot;aws_s3_bucket&quot; &quot;jenkins_artifacts&quot; {<br>  bucket = var.bucket_name<br><br>  tags = merge(<br>    local.common_tags,<br>    {<br>      Name = var.s3_bucket_tag_name<br>    }<br>  )<br>}<br><br># S3 bucket public access block for security<br>resource &quot;aws_s3_bucket_public_access_block&quot; &quot;jenkins_artifacts_pab&quot; {<br>  bucket = aws_s3_bucket.jenkins_artifacts.id<br><br>  block_public_acls       = var.block_public_acls<br>  block_public_policy     = var.block_public_policy<br>  ignore_public_acls      = var.ignore_public_acls<br>  restrict_public_buckets = var.restrict_public_buckets<br>}</pre><h3>Step 6: Output Definitions</h3><p>Create the outputs.tf file it helps us easily grab important information about the things Terraform created, like the server’s address or the storage bucket’s name, so we can use them later or share them with others:</p><pre># outputs.tf<br><br>output &quot;jenkins_server_public_ip&quot; {<br>  description = &quot;The public IP address of the Jenkins EC2 instance&quot;<br>  value       = aws_instance.jenkins.public_ip<br>}<br><br>output &quot;jenkins_server_public_dns&quot; {<br>  description = &quot;The public DNS name of the Jenkins EC2 instance&quot;<br>  value       = aws_instance.jenkins.public_dns<br>}<br><br>output &quot;jenkins_web_url&quot; {<br>  description = &quot;The URL to access the Jenkins web interface&quot;<br>  value       = &quot;http://${aws_instance.jenkins.public_dns}:${var.jenkins_port}&quot;<br>}<br><br>output &quot;s3_bucket_name&quot; {<br>  description = &quot;The name of the S3 bucket for Jenkins artifacts&quot;<br>  value       = aws_s3_bucket.jenkins_artifacts.bucket<br>}<br><br>output &quot;s3_bucket_arn&quot; {<br>  description = &quot;The ARN of the S3 bucket for Jenkins artifacts&quot;<br>  value       = aws_s3_bucket.jenkins_artifacts.arn<br>}<br><br>output &quot;jenkins_security_group_id&quot; {<br>  description = &quot;The ID of the Jenkins security group&quot;<br>  value       = aws_security_group.jenkins_sg.id<br>}<br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhRCG7hGpuIoF983hkdQnA.png" /><figcaption><strong>After you run </strong><strong>terraform apply, Terraform will display values in your terminal or you can also retrieve them at any time.</strong></figcaption></figure><h3>Step 7: Terraform Initialization and Planning</h3><p>Initialize your Terraform working directory and review the planned changes:</p><pre># Initializes the working directory, downloads provider plugins, and sets up the backend<br>terraform init <br><br># Formats your Terraform code files to a standard style for readability and consistency     <br>terraform fmt <br><br># Validates the configuration files for syntax and internal consistency, but does not access any remote services     <br>terraform validate  <br><br># Creates an execution plan, showing what actions Terraform will take to achieve the desired state<br>terraform plan      </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0bgi9rO0rAXWh5wcnD9lmw.png" /><figcaption>Initialization and Planning</figcaption></figure><h3>Step 8: Infrastructure Deployment</h3><p>Deploy your Jenkins infrastructure to AWS:</p><pre># Applies the changes required to reach the desired state of the configuration (actually creates/updates/destroys resources)<br>terraform apply     <br><br># Type &#39;yes&#39; when prompted to confirm resource creation</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*melyJN0aR07I6xIjfz0pSg.png" /><figcaption><strong>Terraform Apply.</strong></figcaption></figure><p>The deployment process typically takes 3–5 minutes to complete. Terraform will display the output values.</p><h3>Step 9: Jenkins Initial Setup</h3><p>Access your newly deployed Jenkins server:</p><ol><li>Copy your EC2 public IP4 address:8080 into your web browser</li><li>Retrieve the initial administrator password from the server:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ObsrCqBCArCrOT73q0cpXw.png" /></figure><ol><li>Complete the Jenkins setup wizard in your browser using the retrieved password</li><li>Install suggested plugins or customize the plugin selection based on your needs</li><li>Create your first administrator user account</li></ol><h3>Step 10: Version Control and Documentation</h3><p>Commit your infrastructure code to version control, my github repo: <a href="https://github.com/adolphasg/jenkins-terraform-aws">https://github.com/adolphasg/jenkins-terraform-aws</a></p><h3>Key Outcomes</h3><p>This project delivers these primary results that establish a robust CI/CD foundation:</p><p><strong>Automated Infrastructure Provisioning</strong>: Complete Jenkins server deployment through code eliminates manual configuration steps and ensures consistent environments across different stages of development.</p><p><strong>Secure Access Configuration</strong>: Properly configured security groups restrict SSH access to authorized IP addresses while allowing controlled web interface access for team collaboration.</p><p><strong>Artifact Storage Solution</strong>: Dedicated S3 bucket with encryption and versioning provides secure, scalable storage for build artifacts and deployment packages.</p><p><strong>Version-Controlled Infrastructure</strong>: All infrastructure components are defined in Terraform files stored in Git, enabling change tracking, rollback capabilities, and collaborative infrastructure management.</p><h3>Challenges and Solutions I faced whilst working on this project:</h3><p><strong>Challenge: </strong>I needed a way to automatically install Jenkins every time a new EC2 instance was created.</p><p><strong>Solution: </strong>I created a Jenkins installation script and used the user_data argument in my EC2 resource, so the server would automatically set up Jenkins during its first boot.</p><p><strong>Challenge: </strong>I struggled with hardcoded values in my Terraform files, which made it difficult to reuse the code for different environments.</p><p><strong>Solution: </strong>I solved this by moving all configurable values into a variables.tf file, making my scripts flexible and easy to update for any situation.</p><p><strong>Challenge: </strong>My security group was not being attached to my instance.</p><p><strong>Solution: </strong>I fixed this by adding the vpc_security_group_ids = [aws_security_group.jenkins_sg.id] line to my EC2 resource block, which properly attaches the security group to the instance.</p><h3>Project Summary</h3><p>This project successfully demonstrates Infrastructure as Code principles by deploying a production-ready Jenkins CI/CD server on AWS using Terraform. The implementation provides automated server provisioning, secure access controls, and proper artifact storage while maintaining all infrastructure definitions in version-controlled code. The resulting setup enables development teams to implement consistent CI/CD pipelines across multiple environments with minimal manual intervention and maximum reproducibility.</p><h3>Cleanup</h3><p>To delete all resources created by this project, run:</p><pre>terraform destroy</pre><p>Type yes when prompted.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fb73c53a330" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨Step-by-Step Docker Swarm Setup for Reliable Shipping Applications✨]]></title>
            <link>https://medium.com/@adolphasg/step-by-step-docker-swarm-setup-for-reliable-shipping-applications-95dbe35fb58c?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/95dbe35fb58c</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Sun, 20 Jul 2025 16:23:50 GMT</pubDate>
            <atom:updated>2025-07-20T16:23:50.444Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VoTEElUzLErTsRYIj7bB9g.png" /></figure><h3>Introduction</h3><p>This project sets up a robust Docker Swarm cluster to run a global shipping application across multiple servers. The goal is to ensure that if any container fails, it is automatically rescheduled, minimizing downtime and data loss.</p><h3>The Challenge</h3><p>Our shipping application has experienced container failures, leading to service interruptions and potential data loss. Without an orchestration system, failed containers are not automatically restarted or rescheduled, putting business operations at risk.</p><h3>Solution Approach</h3><p>To address this, we are deploying Docker Swarm across three AWS EC2 Ubuntu 24.04 servers. Docker Swarm will orchestrate our containers, automatically reschedule failed workloads, and provide a scalable, highly available environment for our application.</p><h3>Prerequisites</h3><ul><li>Three AWS EC2 instances running Ubuntu 24.04, all in the same VPC and security group</li><li>Security group allows inbound traffic on ports 22 (SSH), 2377 (Swarm management), 7946 (communication), 4789 (overlay networking) and 80 (ngnix)</li><li>SSH access to all instances</li><li>Basic familiarity with the Linux command line</li></ul><h3>Why Docker Swam?</h3><p>Docker Swarm is like a conductor for your container “orchestra.” It lets you group several computers running Docker into one big “super-computer,” making it easy to manage all your application pieces. For our shipping app, it’s the best choice because it automatically fixes things if a container breaks down, preventing data loss and keeping our services running smoothly without us having to manually intervene.</p><h3>Step-by-Step Guide</h3><h3>1. Provision Three EC2 Instances</h3><ul><li>Launch three Ubuntu 24.04 EC2 instances in the same AWS region and VPC.</li><li>Ensure all instances are in the <strong>same VPC and security group</strong> to allow internal communication (open ports 2377, 7946, 4789 for Swarm, 22 for SSH and 80 for nginx).</li><li>As part of the setup, we will configure SSH access by creating a ~/.ssh/config file with separate entries for each of the three nodes, specifying their Host, HostName, User, and IdentityFile, enabling seamless connection through the VS Code Remote-SSH extension.</li></ul><pre># Docker EC2 <br>Host Manager<br>    #IPV4 Address will change with every restart<br>    HostName &lt;your ipv4&gt;<br>    User ubuntu<br>    IdentityFile &lt;your key pair&gt;<br><br>Host Worker 1<br>    #IPV4 Address will change with every restart<br>    HostName &lt;your ipv4&gt;<br>    User ubuntu<br>    IdentityFile &lt;your key pair&gt;<br><br>Host Worker 2<br>    #IPV4 Address will change with every restart<br>    HostName &lt;your ipv4&gt;<br>    User ubuntu<br>    IdentityFile &lt;your key pair&gt;</pre><h3>2. Set Hostnames for Each Node</h3><p>Set a unique hostname on each server for easy identification.</p><p>On the manager node:</p><pre>sudo hostnamectl set-hostname Manager</pre><p>On the first worker node:</p><pre>sudo hostnamectl set-hostname Worker1</pre><p>On the second worker node:</p><pre>sudo hostnamectl set-hostname Worker2</pre><p>Log out and back in to see the new hostname in your prompt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cGa0hleW1kW5KBsaQWCvNQ.png" /><figcaption><strong>You Can Split The Terminal In VS Code Into 3 If You Prefer To See All Your Nodes On One Screen Like Me.</strong></figcaption></figure><h3>3. Install Docker on All Hosts</h3><p>SSH into each instance and run the following commands:</p><pre><br># Update package list<br>sudo apt-get update<br><br># Download Docker’s official installation script<br>curl -fsSL https://get.docker.com -o get-docker.sh<br><br># Runs the script to install Docker Engine using Docker’s recommended method<br>sh get-docker.sh<br><br><br></pre><h3>4. Start and Enable Docker</h3><pre># Start Docker service<br>sudo systemctl start docker<br><br># Enable Docker to start on boot<br>sudo systemctl enable docker</pre><p>Check Docker status:</p><pre># Check if Docker is running<br>sudo systemctl status docker</pre><p>Look for “active (running)” in the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ssuj7kG00MS_QBKeBH-lMQ.png" /><figcaption><strong>Docker Running On All Three Nodes.</strong></figcaption></figure><h3>5. Add Your SSH Key to Each Node</h3><p>On your local machine, generate an SSH key if you don’t have one:</p><pre>ssh-keygen -t rsa -b 4096</pre><p>Copy your public key to each node:</p><pre>ssh-copy-id ubuntu@&lt;instance-public-ip&gt;</pre><p>Repeat for all three nodes.</p><h4>Why Add Your Own SSH Key?</h4><ul><li><strong>Convenience:</strong> You don’t have to keep using the AWS .pem file every time.</li><li><strong>Team Access:</strong> You can give access to other people by adding their public keys, without sharing your AWS key.</li><li><strong>Security:</strong> You can remove or rotate keys easily if someone leaves the team.</li></ul><h3>6. Validate Security Group Settings</h3><p>In the AWS Console, confirm all three instances are in the same security group. The group should allow inbound traffic on ports 22, 2377, 7946, 4789 and 80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ikbBT-FxZElRs9rk2Tvb1A.png" /><figcaption><strong>Security Group</strong></figcaption></figure><h3>7. Initialize Docker Swarm on the Manager Node</h3><p>SSH into the manager node and run:</p><pre># Initialize Docker Swarm and advertise the manager&#39;s private IP<br>sudo docker swarm init --advertise-addr &lt;manager-private-ip&gt;</pre><p>Copy the docker swarm join command from the output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W0OHpH3BNrwdgn0xby1w2g.png" /><figcaption><strong>Initialize Docker Swarm.</strong></figcaption></figure><h3>8. Join Worker Nodes to the Swarm</h3><p>SSH into each worker node and run the join command copied from the manager node:</p><pre># Join the Swarm as a worker node<br>sudo docker swarm join --token &lt;token&gt; &lt;manager-private-ip&gt;:2377</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w9EiiuqelXv23Z9C66I1ug.png" /><figcaption><strong>Both Worker Nodes Joined To Swam.</strong></figcaption></figure><h3>9. Verify Swarm Node Status</h3><p>On the manager node, check the status of all nodes:</p><pre># List all nodes in the Swarm<br>sudo docker node ls</pre><p>You should see all three nodes listed, with the manager as “Leader” and the others as “Worker”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*8D1RJn-oSZUQ3e6nA4qbpA.png" /><figcaption><strong>All 3 Nodes Listed.</strong></figcaption></figure><h3>10. Deploy an NGINX Service on the Swarm</h3><p>On the manager node, create a service with one replica:</p><pre># Create an NGINX service with one replica<br>sudo docker service create --name webserver --replicas 1 -p 80:80 nginx:latest</pre><p>Check the service status:</p><pre># List all services<br>sudo docker service ls<br><br># Show tasks for the webserver service<br>sudo docker service ps webserver</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*NCu7ostROfp6ILwhd3Ky0A.png" /><figcaption><strong>Verifying Service Status.</strong></figcaption></figure><h3>11. Scale the Service to Three Replicas</h3><p>Increase the number of running containers to three:</p><pre># Scale the webserver service to three replicas<br>sudo docker service scale webserver=3</pre><p>Verify scaling:</p><pre># Show tasks for the webserver service<br>sudo docker service ps webserver</pre><p>You should see three tasks running across your nodes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*FY1v7WeW22vOcX0wIefkBQ.png" /><figcaption><strong>Verifying Scaling.</strong></figcaption></figure><h3>12. (Optional) Deploy as a Global Service</h3><p>When you deploy a service in Docker Swarm as a <strong>global service</strong>, you are telling Docker to automatically run <strong>one container on every node</strong> in your cluster. So, if you have three servers (nodes), Docker will make sure there is exactly one NGINX container running on each one — no more, no less.</p><p>How to Do It:</p><pre># Deploy NGINX as a global service, one per node<br>sudo docker service create --name global-nginx --mode global -p 8080:80 nginx:latest</pre><p>Check status:</p><pre># Show tasks for the global-nginx service<br>sudo docker service ps global-nginx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*d8JzE7OIjftsXMdc0bMHPw.png" /><figcaption><strong>Deploy As A Global Service.</strong></figcaption></figure><h4>Why Is This Option Useful?</h4><p><strong>1. Automatic Coverage:</strong><br> With a global service, you don’t have to manually assign containers to each server. Docker does it for you, making sure every node is running the service.</p><p><strong>2. Consistency Across All Nodes:</strong><br> This is great for things like monitoring, logging, or proxy services (like NGINX), where you want the same tool running everywhere in your cluster.</p><p><strong>3. High Availability:</strong><br> If you add a new node to your Swarm, Docker will automatically start a container on that new node. If a node goes down, you know exactly which nodes are still running the service.</p><h3>13. Test the Application</h3><p>Visit the public IP of any node in your browser (port 80 or 8080, depending on your service). You should see the NGINX welcome page or your custom page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdkPrEM2cX7yOx1Ltv9vPQ.png" /><figcaption><strong>Nginx Welcome Page</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACq-6Xvf_sg-283mIm0-hw.png" /><figcaption><strong>Custom Page.</strong></figcaption></figure><h3>Key Outcomes</h3><p>Here are the main results of this project:</p><ul><li>Docker Swarm is set up across three networked hosts for high availability.</li><li>Containers are automatically rescheduled if they fail, reducing downtime.</li><li>The application can be scaled up or down easily using simple commands.</li><li>The system is ready for global deployment, supporting both replicated and global service modes.</li></ul><h3>Common Challenges and Solutions You Might Face Whilst Working On This Project</h3><ol><li><strong>Network Connectivity Issues:</strong><br> If nodes cannot join the Swarm, check that all required ports are open in the security group and that nodes are in the same VPC.</li><li><strong>Docker Not Starting:</strong><br> If Docker fails to start, ensure all dependencies are installed and the service is enabled and started.</li><li><strong>Service Not Scaling Properly:</strong><br> If scaling fails, verify that all nodes are healthy and have enough resources to run additional containers.</li><li><strong>Outdated Docker and System Packages:</strong><br> <em>Outdated Docker versions or system packages can cause compatibility issues or security vulnerabilities. </em><strong>Solution: </strong>Regularly update Docker and your system packages on all nodes. Schedule maintenance windows to apply updates and restart services as needed, ensuring minimal disruption to your application.</li></ol><h3>Summary</h3><p>By following these steps, you have set up a resilient Docker Swarm cluster on AWS EC2, ready to run and scale your global shipping application. This setup ensures high availability, automatic recovery from failures, and easy management of containerized workloads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95dbe35fb58c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ Building A Scalable CI/CD Pipeline With Docker And Jenkins✨]]></title>
            <link>https://medium.com/@adolphasg/building-a-scalable-ci-cd-pipeline-with-docker-and-jenkins-26d7cc8e5612?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/26d7cc8e5612</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Mon, 14 Jul 2025 00:12:25 GMT</pubDate>
            <atom:updated>2025-07-14T00:12:25.284Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eNE3LFxGXonuPSLNBWPE2Q.png" /></figure><p>Modern software development demands rapid, reliable deployment cycles. This project demonstrates how to establish a robust CI/CD pipeline using Docker containerization and Jenkins automation, ensuring consistent environments and persistent data management for enterprise-level development workflows.</p><h3>Introduction</h3><p>Organizations today face increasing pressure to deliver software updates quickly while maintaining quality and reliability. Traditional deployment methods often suffer from environment inconsistencies, manual configuration errors, and lengthy setup processes. This project addresses these challenges by implementing a containerized Jenkins environment that provides scalable, consistent, and automated continuous integration and deployment capabilities.</p><h3>Challenge</h3><p>Development teams frequently encounter several critical issues that slow down their delivery pipeline:</p><ul><li><strong>Environment Inconsistencies</strong>: Applications behave differently across development, testing, and production environments</li><li><strong>Manual Setup Overhead</strong>: Setting up Jenkins instances requires significant time and technical expertise</li><li><strong>Data Loss Risk</strong>: System updates or failures can result in loss of build history and job configurations</li><li><strong>Resource Inefficiency</strong>: Traditional installations consume excessive server resources and lack scalability</li><li><strong>Complex Maintenance</strong>: Updating and managing Jenkins installations across multiple environments becomes increasingly difficult</li></ul><h3>Solution Approach</h3><p>This project implements a Docker-based Jenkins solution that addresses these challenges through:</p><ul><li><strong>Containerization</strong>: Using Docker to create consistent, portable Jenkins environments</li><li><strong>Persistent Storage</strong>: Implementing Docker volumes to preserve critical data across container lifecycles</li><li><strong>Infrastructure as Code</strong>: Utilizing Docker Compose for reproducible, version-controlled deployments</li><li><strong>Scalable Architecture</strong>: Enabling easy horizontal scaling of Jenkins instances based on demand</li></ul><h3>Prerequisites</h3><p>Before beginning this project, ensure you have the following components installed and configured:</p><ul><li><strong>Docker Engine</strong>: Version 20.10 or higher installed on your system</li><li><strong>Docker Compose</strong>: Version 2.0 or higher for orchestration capabilities</li><li><strong>System Requirements</strong>: Minimum 4GB RAM and 10GB available disk space</li><li><strong>Network Access</strong>: Internet connectivity for downloading Docker images</li><li><strong>Administrative Privileges</strong>: Sudo or administrator access for Docker operations</li><li><strong>Basic Command Line Knowledge</strong>: Familiarity with terminal or command prompt operations</li></ul><h3>Why Docker and Jenkins?</h3><ul><li>**Docker** provides lightweight, consistent environments for applications, eliminating the “it works on my machine” problem.</li><li>- **Jenkins** is a leading automation server, perfect for orchestrating builds, tests, and deployments.</li></ul><p>Combining these tools allows Level Up Solutions to automate and scale its development workflow efficiently.</p><h3>Step-by-Step Implementation</h3><h3>Foundational Approach: Docker CLI Method</h3><h4>Step 1: Download Jenkins Docker Image</h4><pre># Pull the official Jenkins Long Term Support image from Docker Hub<br>docker pull jenkins/jenkins:lts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*tHHidtoe_J0BQnAoCJV34A.png" /><figcaption><strong>Pull Jenkins Image.</strong></figcaption></figure><h4>Step 2: Create Persistent Storage Volume</h4><pre># Create a named volume to store Jenkins data permanently<br>docker volume create &lt;volume_name&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*MzXntTeeU-JjV7a6xdTH5g.png" /><figcaption><strong>New Volume Created </strong><strong>jenkins_data</strong></figcaption></figure><h4>Step 3: Launch Jenkins Container</h4><pre># Run Jenkins container with port mapping and volume mounting<br>docker run -d \<br>  --name jenkins \<br>  -p 8080:8080 \<br>  -p 50000:50000 \<br>  -v jenkins_data:/var/jenkins_home \<br>  jenkins/jenkins:lts<br><br># -d: Run container in detached mode (background)<br># --name: Assign a custom name to the container<br># -p 8080:8080: Map host port 8080 to container port 8080 (web interface)<br># -p 50000:50000: Map port 50000 for Jenkins agent connections<br># -v: Mount the persistent volume to Jenkins home directory</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UKNjgOZZXC1E4j9tmoEDPg.png" /><figcaption><strong>Documentation For Jenkins Docker Image.</strong></figcaption></figure><h4>Step 4: Retrieve Initial Administrator Password</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLx99MeMJR5sVjGhx5h0ng.png" /><figcaption><strong>Ensure Your Security Group Is Open To Port 8080 and Port 50000.</strong></figcaption></figure><pre># Extract the auto-generated admin password from the container<br>docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword</pre><h4>Step 5: Complete Jenkins Initial Setup</h4><ol><li>Open web browser and navigate to <a href="http://localhost:8080/">http://&lt;your-ipv4&gt;:8080</a></li><li>Enter the administrator password retrieved in Step 4</li><li>Select “Install suggested plugins” when prompted</li><li>Create your first admin user account with username and password</li><li>Configure Jenkins URL (keep default: <a href="http://localhost:8080)">http://</a><a href="http://localhost:8080/">&lt;your-ipv4&gt;</a><a href="http://localhost:8080)">:8080)</a></li><li>Click “Start using Jenkins” to complete setup</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CkjmaOPunAlo9500NHH-Ew.png" /><figcaption><strong>Jenkins Initial Setup.</strong></figcaption></figure><h4>Step 6: Verify Data Persistence</h4><pre># Stop the running Jenkins container<br>docker stop jenkins<br><br># Remove the container completely<br>docker rm jenkins<br><br># Launch a new Jenkins container using the same persistent volume<br>docker run -d \<br>  --name jenkins \<br>  -p 8080:8080 \<br>  -p 50000:50000 \<br>  -v jenkins_data:/var/jenkins_home \<br>  jenkins/jenkins:lts</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/1*SVeAqtrMkKimCzHiUf_1IA.png" /><figcaption><strong>Container Completely Removed.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*FX5BvBXMiuO_Ob28nWmfkA.png" /><figcaption><strong>Launch A New Jenkins Container Using The Same Persistent Volume.</strong></figcaption></figure><p>Access http://<a href="http://localhost:8080/">&lt;your-ipv4&gt;</a>:8080 and log in with your previously created user credentials. All configurations and data should remain intact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zmXeqmafvNqQD2EZWrO2iA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wgrMrCpjBUYP3gbJYqwOvA.png" /><figcaption><strong>All Configurations And Data Remained Intact.</strong></figcaption></figure><h3>Advanced Approach: Docker Compose Method</h3><h4>Step 1: Create Project Directory Structure</h4><pre># Create a dedicated directory for the Jenkins project<br>mkdir jenkins-docker-project<br>cd jenkins-docker-project</pre><h4>Step 2: Create Docker Compose Configuration</h4><p>Create a file named docker-compose.yml with the following content:</p><pre># Docker Compose version specification<br>version: &#39;3.8&#39;<br><br># Define services (applications) to run<br>services:<br>  jenkins:<br>    # Use official Jenkins LTS image<br>    image: jenkins/jenkins:lts<br>    # Assign a custom container name<br>    container_name: jenkins2<br>    # Map ports from host to container<br>    ports:<br>      - &quot;8080:8080&quot;    # Web interface port<br>      - &quot;50000:50000&quot;  # Agent connection port<br>    # Mount persistent volume for data storage<br>    volumes:<br>      - jenkins_data:/var/jenkins_home<br>    # Restart policy for container resilience<br>    restart: unless-stopped<br><br># Define named volumes for persistent storage<br>volumes:<br>  jenkins_data:<br>    # Use default local driver for volume creation<br>    driver: local</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/572/1*gSWNBJkyZuFX8eo9wwAjDQ.png" /><figcaption><strong>Create A YML File With The Above Content.</strong></figcaption></figure><h4>Step 3: Deploy Jenkins Using Docker Compose</h4><pre># Start all services defined in docker-compose.yml<br>docker compose up -d<br><br># -d flag runs containers in detached mode (background)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*0ttQ4_ZtfvtGEBSAxA0PQw.png" /></figure><h4>Step 4: Retrieve Administrator Password</h4><pre># Get the initial admin password from the running container<br>docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword</pre><h4>Step 5: Complete Jenkins Configuration</h4><p>Follow the same setup process as described in the Foundational Approach Step 5.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hUAZIq_G2zRjJnxHLw3hKg.png" /><figcaption><strong>Configuring Jenkins.</strong></figcaption></figure><h4>Step 6: Test Persistence and Management</h4><pre># Stop all services defined in docker-compose.yml<br>docker compose down<br><br># Restart all services<br>docker compose up -d<br><br># View running containers and their status<br>docker compose ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*x9Y-HG6rMxrOC6EjiTT9hA.png" /><figcaption><strong>Test Persistence</strong></figcaption></figure><h3>Key Outcomes</h3><p>Here are the main results of this project:</p><h4>1. Automated Environment Provisioning</h4><p>The implementation provides instant Jenkins environment creation with a single command, reducing setup time from hours to minutes and eliminating manual configuration errors.</p><h4>2. Guaranteed Data Persistence</h4><p>All Jenkins configurations, job definitions, build histories, and user settings remain intact across container restarts, updates, and system maintenance operations.</p><h4>3. Scalable Infrastructure Management</h4><p>The Docker-based approach enables easy horizontal scaling of Jenkins instances and simplified resource allocation based on project demands.</p><h4>4. Simplified Maintenance and Updates</h4><p>Container-based deployment allows for seamless Jenkins version updates, easy rollbacks, and consistent environment replication across development stages.</p><h3>Challenges and Solutions I Faced Working On This Project:</h3><h4>Challenge 1: Port Conflicts</h4><p><strong>Issue</strong>: Default ports 8080 or 50000 were already in use by another container.</p><p><strong>Solution</strong>: I modified port mappings in docker-compose.yml file to use alternative ports like 8082:8080 or 50002:50000.</p><h4>Challenge 2: Warning About Version Attribute</h4><p><strong>Issue:</strong> A warning about the version attribute being obsolete in the docker-compose.yml file.</p><p><strong>Solution:</strong> I had to remove the version line from the file to prevent confusion and warnings.</p><h3>Project Summary</h3><p>This project successfully demonstrates the implementation of a robust, scalable CI/CD infrastructure using Docker and Jenkins. The containerized approach eliminates environment inconsistencies, ensures data persistence, and provides simplified management capabilities. Organizations can now deploy reliable Jenkins instances rapidly, maintain consistent development environments, and scale their CI/CD operations efficiently. The solution addresses critical challenges in modern software development while providing a foundation for advanced DevOps practices and automated deployment pipelines.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26d7cc8e5612" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ Web Application Deployment Using Docker✨]]></title>
            <link>https://medium.com/@adolphasg/web-application-deployment-using-docker-5d6b1eb86caf?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d6b1eb86caf</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Mon, 30 Jun 2025 02:47:25 GMT</pubDate>
            <atom:updated>2025-06-30T02:47:25.371Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQ-8_papOeBCqZttrKyAbw.png" /></figure><h3>Introduction</h3><p>Level Up Solutions is constantly innovating how it builds and deploys applications. In this project, I aimed to containerize a basic web application using Docker to make deployments faster, more consistent, and easier to scale.</p><h3>The Challenge</h3><p>Manually setting up environments for web applications can be time-consuming and error-prone. Differences between development and production systems often cause bugs and delays.</p><h3>The Solution</h3><p>To solve this, I containerized a simple Apache web server using Docker. This approach packages the application and its environment into one unit, ensuring it works the same everywhere. I also shared the image via Docker Hub so others can pull and run it anywhere with just one command.</p><h3>Prerequisites</h3><p>Before starting this project, make sure you have the following:</p><ul><li>Docker installed on your machine (macOS, Linux, or Windows)</li><li>A free Docker Hub account</li><li>Basic understanding of command line usage</li></ul><h3>Why Docker?</h3><p>Docker is useful because it lets you package apps with everything they need to run — like code, tools, and settings — into one portable unit called a container. This makes it easy to run the same app anywhere without worrying about setup issues, so it works the same on your computer, a server, or in the cloud.</p><h3>Why Docker Hub?</h3><p>Docker Hub is useful because it’s like an app store for Docker — it lets you find, share, and download ready-made container images, like Ubuntu or web servers, so you don’t have to build everything from scratch.</p><h3>Permission Issues Constraints (Pro Tip)</h3><p>sudo chmod 666 /var/run/docker.sock is the “doorbell” the Docker command-line uses to talk to the Docker engine.<br> If you’re not root (or in the <strong>docker</strong> user group), you’ll get “permission denied.”<br> Running sudo chmod 666 /var/run/docker.sock makes that doorbell ringable by <strong>anyone</strong> (read + write for all), so non-admin users can run Docker commands.</p><p>Use it <strong>only as a quick, temporary fix on a personal or throw-away dev machine</strong> — never on shared or production systems — because anyone who can access that socket can effectively gain root-level control of the host. A safer long-term solution is to add your user to the docker group instead of world-opening the socket.</p><h3>Step-by-Step Guide</h3><h3>Step 1: Pull and Run an Ubuntu Container</h3><p>First step is to pull a docker ubuntu image, which is a lightweight, ready-to-use version of the Ubuntu operating system packaged for Docker. We pull it to use Ubuntu in a container, allowing us to run and test software in a clean, isolated environment without installing Ubuntu on our actual computer. It’s like grabbing a fresh, portable copy of Ubuntu that runs anywhere Docker works.</p><pre># Pull Ubuntu image from Docker Hub<br>docker pull ubuntu:latest<br><br><br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*VxthkcNPqef6MuOJL31N5A.png" /><figcaption><strong>Pull A Docker Ubuntu Image.</strong></figcaption></figure><p>After pulling the image we are going to run it in detached mode on port 80:</p><pre># Run the container in detached mode and map port 80 on host to port 80 in container<br>docker run -d -p 80:80 --name luitsolutions ubuntu:latest</pre><p>This runs a container named luitsolutions, detached (-d) the -d flag runs the Docker container in the background, and maps port 80 -p flag connects your computer’s port to the container’s port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*ujRaU036fkswW1AsjD2DSw.png" /><figcaption><strong>Created Container.</strong></figcaption></figure><h3>Step 2: Access the Container and Update Packages</h3><p>Enter the container’s shell and update the package list.</p><pre># Access the container&#39;s shell<br>docker exec -it luitsolutions bash</pre><p>The above opens a terminal inside the running luitsolutions container so you can interact with it like you&#39;re using a regular Ubuntu system.</p><pre># Update and upgrade all packages inside the container<br>apt update &amp;&amp; apt upgrade -y</pre><p>The above updates the list of available software and then installs the latest versions automatically without asking for confirmation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*mKkMvc-UAML17b_AKr6LNg.png" /><figcaption><strong>Updating Packages.</strong></figcaption></figure><h3>Step 3: Install Apache Web Server</h3><p>Install and start the Apache web server within the container.</p><pre># Install Apache2 inside the Ubuntu container<br>apt install apache2 -y</pre><pre># Start the Apache service<br>service apache2 start</pre><h3>Step 4: Add a Custom Web Page</h3><p>Replace the default web page with a custom message.</p><pre># Add a simple HTML page to be served by Apache<br>echo &quot;&lt;h1&gt;Welcome to Level Up Solutions!&lt;/h1&gt;&quot; &gt; /var/www/html/index.html</pre><h3>Step 5: Test the Web Server in Your Browser</h3><p>On your local machine, open a browser and visit:</p><pre>&lt;your public ip4&gt;:&lt;your port&gt;</pre><p>You should see the custom welcome message served from your Docker container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VNjgnDPzjjybWK8_gxeJ4w.png" /></figure><h3>Step 6: Commit the Container as a Reusable Image</h3><p>Turn your configured container into a reusable Docker image.</p><pre># Commit the current container state as a new image<br>docker commit luitsolutions levelupsolutions/apache-web:v1</pre><p>This takes a snapshot of your current &lt;your container name&gt; and saves it as a reusable Docker image called &lt;your container name&gt;/apache-web with the version v1. You can now run new containers from this image without redoing all your setup.</p><pre>docker commit luitsolutions levelupsolutions/apache-web:v1</pre><p>This takes a snapshot of your current luitsolutions container and saves it as a reusable Docker image called levelupsolutions/apache-web with the version v1. You can now run new containers from this image without redoing all your setup.</p><h3>Step 7: Push the Image to Docker Hub</h3><p>Make the image accessible from anywhere by uploading it to Docker Hub.</p><ul><li><strong>Log in to Docker Hub:</strong></li></ul><pre># Log into Docker Hub<br>docker login</pre><ul><li><strong>Tag your local image with your Docker Hub username:</strong></li></ul><pre># Tag the image with your Docker Hub username<br>docker tag levelupsolutions/apache-web:v1 yourusername/apache-web:v1docker tag levelupsolutions/apache-web:v1 yourusername/apache-web:v1</pre><ul><li><strong>Push the tagged image to your Docker Hub repository:</strong></li></ul><pre># Push the image to your Docker Hub account<br>docker push yourusername/apache-web:v1</pre><ul><li><strong>Pull the image from anywhere to reuse it:</strong></li></ul><pre>docker pull yourusername/apache-web:v1</pre><ul><li><strong>View the image on Docker Hub:</strong><br> <a href="https://hub.docker.com/repository/docker/yourusername/apache-web">https://hub.docker.com/repository/docker/yourusername/apache-web</a></li><li><em>Replace </em><em>yourusername with your actual Docker Hub username.</em></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*73fCauo2OUKMRja6NQi3bw.png" /><figcaption><strong>Image Pushed To Docker Hub.</strong></figcaption></figure><h3>Step 8: Run the Image from Docker Hub on a Different Port</h3><p>Verify that the pushed image can be pulled and run on another port.</p><pre># Pull the image from Docker Hub<br>docker pull yourusername/apache-web:v1</pre><pre># Run the container with host port e.g. 8080 mapped to container port 80<br>docker run -d -p 8080:80 --name apache-clone yourusername/apache-web:v1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*GXaaTHB-IXvPa74S1MiDqg.png" /><figcaption><strong>Container From Docker Hub Image.</strong></figcaption></figure><p>Now, open a browser and go to:</p><pre>&lt;your public ip4&gt;:&lt;your port&gt;</pre><p>You’ll see the same custom webpage — proving the container is portable and fully functional across setups.</p><h3>Key Outcomes</h3><p>Here are the main results of this project:</p><ol><li>Created a portable and consistent Docker image running Ubuntu with Apache2.</li><li>Replaced Apache’s default page with a customized HTML welcome message.</li><li>Published the container image to Docker Hub for sharing and reuse.</li><li>Verified that the image can be deployed anywhere with a single pull command.</li></ol><h3>Challenges and Solutions you might face working on this project</h3><ul><li><strong>Challenge:</strong> Some Ubuntu images are very minimal and lack basic tools.<br> <strong>Solution:</strong> Use the Bash shell to manually install required packages like Apache2.</li><li><strong>Challenge:</strong> Apache doesn’t start automatically inside containers.<br> <strong>Solution:</strong> Manually run service apache2 start after installing it, or modify the Dockerfile to include it as a startup command for future builds.</li><li><strong>Challenge:</strong> Browser can’t access localhost on custom ports.<br> <strong>Solution:</strong> Always double-check the port mappings using docker ps, and make sure you’re using the host port in your browser (e.g., localhost:8080).</li></ul><h3>Summary</h3><p>This project was a great introduction to containerizing web applications using Docker. By packaging Ubuntu and Apache2 into a container and pushing it to Docker Hub, we created a reliable, reusable image that works the same across machines. This workflow eliminates common deployment issues and sets the stage for more advanced, scalable setups in future projects.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d6b1eb86caf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ Content Generation Using Amazon Bedrock and GitHub Actions✨]]></title>
            <link>https://medium.com/@adolphasg/content-generation-using-amazon-bedrock-and-github-actions-b4a94dc6e6a9?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4a94dc6e6a9</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Sat, 21 Jun 2025 23:04:08 GMT</pubDate>
            <atom:updated>2025-06-22T16:37:12.148Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XyNAtulKNAP01mBQ4UlfsA.png" /></figure><p><strong>GITHUB REPO FOR THIS PROJECT: </strong><a href="https://github.com/adolphasg/prompt-deployment-pipeline">https://github.com/adolphasg/prompt-deployment-pipeline</a></p><p>Pixel Learning Co. needed a faster and more reliable way to generate and publish AI-driven content. This project sets up a lightweight automation pipeline using Amazon Bedrock and GitHub Actions to turn prompt templates into live content hosted on static S3 websites.</p><h3>Introduction</h3><p>Pixel Learning Co. creates educational messages using AI prompts, such as onboarding emails and course summaries. These prompts were being handled manually, making the process slow and difficult to manage at scale.</p><h3>Challenge</h3><p>Creating and publishing content from AI prompts was time-consuming and error-prone. The content team had to copy and paste responses manually, making it difficult to track what was sent, by whom, and when.</p><h3>Solution</h3><p>A simple CI/CD pipeline was built using GitHub Actions and Amazon Bedrock. The team now stores prompt templates in GitHub, uses automation to generate responses using Bedrock, and publishes the outputs as HTML files to S3 static websites — automatically, every time a pull request or merge happens.</p><h3>Prerequisites</h3><ul><li>An AWS account with access to Amazon Bedrock</li><li>Two S3 buckets configured for static website hosting</li><li>An IAM user or role with access to S3 and Bedrock</li><li>GitHub repository and GitHub Actions enabled</li><li>Secrets configured in GitHub for AWS credentials and bucket names.</li></ul><p><strong>Why Amazon Bedrock?</strong></p><p>Using Amazon Bedrock allows Pixel Learning Co. to integrate powerful foundation models with zero infrastructure management:</p><ul><li><strong>Fast Prompt Execution</strong>: Run high-quality prompts using Titan, Claude, or other models without setting up or managing endpoints.</li><li><strong>Multi-Model Access</strong>: Easily switch between models depending on tone or task.</li><li><strong>Secure and Scalable</strong>: Fully managed service with IAM-based access control.</li><li><strong>No Deployment Overhead</strong>: Run real-time inference without worrying about model hosting or lifecycle.</li></ul><p><strong>Why Github Actions?</strong></p><ul><li><strong>Automation</strong>: Automatically detects new prompt configurations and generates content accordingly.</li><li><strong>Environment-Aware</strong>: Differentiates between beta and prod by branch, deploying previews and publishing content accordingly.</li><li><strong>Developer-Friendly</strong>: Allows prompt engineers and content teams to manage the full pipeline using GitHub without accessing the AWS Console.</li></ul><h3>Step-by-Step Guide</h3><h3>Step 1: Set up the S3 static website buckets</h3><pre>aws s3 mb s3://plc-content-beta<br>aws s3 mb s3://plc-content-prod<br>aws s3 website s3://plc-content-beta --index-document index.html<br>aws s3 website s3://plc-content-prod --index-document index.html</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*4I-OJ06rcNCzSLijfC4mrA.png" /><figcaption><strong>Created Buckets For Testing &amp; Production.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/1*d9RKC1KG6WwZDYEylJprUw.png" /><figcaption><strong>S3 Bucket Set Up For Static Website Hosting.</strong></figcaption></figure><p>Make sure your bucket policy allows public read access or connect it to CloudFront. Below, you can find an example of a bucket policy:</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;PublicReadGetObject&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: &quot;*&quot;,<br>            &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:s3:::your bucket name/*&quot;<br>        }<br>    ]<br>}</pre><h3>Step 2: Request Your Model From Bedrock.</h3><p>Why we need a Model from Amazon Bedrock</p><p>To generate personalized HTML content like welcome pages or announcements, we need a language model capable of understanding prompt templates and producing human-like text. Amazon Bedrock allows us to access large language models without needing to manage servers or infrastructure. We simply send a prompt and get back a generated response, which makes it ideal for automation pipelines.</p><p>Why I Chose Claude 3 Sonnet</p><p>I selected the model anthropic.claude-3-sonnet-20240229-v1:0 because it offers the right balance between performance, accuracy, and cost. Claude Sonnet is known for handling structured prompts well, producing clear and thoughtful completions. It also supports longer inputs, which was important for our full-page templates. Compared to other models, it was fast, reliable, and easy to integrate with our pipeline.</p><p>How to Request Access to Claude 3 Sonnet on Bedrock</p><ol><li>Sign in to the AWS Console and go to Amazon Bedrock in your chosen region (for example, us-east-1).</li><li>In the left menu, select “Model access.”</li><li>Find “Anthropic Claude 3 Sonnet” and enable access by toggling it on.</li><li>Accept the terms if prompted.</li><li>I will be using the following model ID in my script:</li></ol><ul><li>anthropic.claude-3-sonnet-20240229-v1:0</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RJ1oqPk3hdcQAiZJeQyBmA.png" /><figcaption><strong>Requested Model From Bedrock.</strong></figcaption></figure><p>I also ensured my IAM role or user has permission to invoke the model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I_JrrU71eoHgJgqbSGhDQQ.png" /><figcaption><strong>Permissions</strong></figcaption></figure><h3>Step 3: Set up the folder structure in your GitHub repo</h3><pre>.<br>├── prompts/<br>│   └── welcome_prompt.json<br>├── prompt_templates/<br>│   └── welcome_email.txt<br>├── outputs/<br>├── .github/<br>│   └── workflows/<br>│       ├── on_pull_request.yml<br>│       └── on_merge.yml<br>├── process_prompt.py<br>└── README.md</pre><h3>Step 4: Create a prompt template and variable file</h3><p><strong>prompt_templates/welcome.txt</strong></p><pre>Hi {{student_name}},<br><br>Welcome to Pixel Learning Co.! Here are three quick tips to get started:<br>1. {{tip1}}<br>2. {{tip2}}<br>3. {{tip3}}<br><br>Happy learning!</pre><p><strong>prompts/welcome_prompt.json</strong></p><pre>{<br>  &quot;output_file&quot;: &quot;welcome_{{student_name|lower}}.html&quot;,<br>  &quot;variables&quot;: {<br>    &quot;student_name&quot;: &quot;Jordan&quot;,<br>    &quot;tip1&quot;: &quot;Explore the course dashboard&quot;,<br>    &quot;tip2&quot;: &quot;Join the discussion forum&quot;,<br>    &quot;tip3&quot;: &quot;Set weekly study reminders&quot;<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/1*GTvSy0SDEoPB6pD-0vHsPw.png" /><figcaption><strong>Install Jinja2.</strong></figcaption></figure><p><strong>Jinja2 helps you automate writing personalized content by filling in templates with real data.</strong></p><h3>Step 5: Add the Python script to process the prompts</h3><p>The script automates a full “prompt-to-webpage” pipeline. It reads a small configuration file for each webpage, fills a text template with those values to create a custom prompt, sends that prompt to Amazon Bedrock (Claude 3 Sonnet) to generate finished HTML, then saves the HTML to a local outputs/ folder and uploads it to the proper S3 bucket so the page is instantly available on a static website. By looping through every config file in the prompts/ folder, the script can publish any number of pages—beta or production—in one run, with no manual copy-and-paste.</p><p>Three Python libraries make this possible. <strong>json</strong> loads the config files; without it the script would have no structured way to know what variables to insert or what each page should be called. <strong>pathlib</strong> provides clean, cross-platform file and folder handling; without it you would be hard-coding fragile string paths and writing extra code to join them safely. <strong>jinja2</strong> (and its Template helper) turns a plain text file into a smart template that can accept variables like {{ name }}; without it you would have to build your own string-replacement logic, which is error-prone and far less flexible. Removing any of these imports breaks a critical link in the chain: no configs, no reliable file access, or no templating—meaning the pipeline would stall before it ever reaches Bedrock.</p><p>The complete script is provided below:</p><p><strong>process_prompt.py</strong></p><pre># generate_and_upload.py<br>import boto3<br>import os<br>import json<br>import pathlib<br>import jinja2<br>from jinja2 import Template<br><br># ---------- Constants ----------<br>MODEL_ID = &quot;anthropic.claude-3-sonnet-20240229-v1:0&quot;<br>BETA_PREFIX = os.getenv(&quot;BETA_PREFIX&quot;, &quot;beta/&quot;)<br>PROD_PREFIX = os.getenv(&quot;PROD_PREFIX&quot;, &quot;prod/&quot;)<br><br># ---------- Helpers ----------<br><br>def get_region() -&gt; str:<br>    &quot;&quot;&quot;Return AWS region from env vars or raise a helpful error.&quot;&quot;&quot;<br>    region = os.getenv(&quot;AWS_REGION&quot;) or os.getenv(&quot;AWS_DEFAULT_REGION&quot;)<br>    if not region:<br>        raise ValueError(<br>            &quot;[❌] No AWS region specified.\n&quot;<br>            &quot;➡️  Set AWS_REGION or AWS_DEFAULT_REGION (e.g., &#39;us-east-1&#39;).&quot;<br>        )<br>    return region<br><br><br>def render_prompt(template_path: str, config: dict) -&gt; str:<br>    &quot;&quot;&quot;Render a Jinja2 prompt template with variables from config.&quot;&quot;&quot;<br>    template = jinja2.Template(pathlib.Path(template_path).read_text())<br>    return template.render(**config[&quot;variables&quot;])<br><br><br>def construct_body(prompt: str, max_tokens: int = 300) -&gt; dict:<br>    &quot;&quot;&quot;Create the invoke‑body expected by Amazon Bedrock.&quot;&quot;&quot;<br>    return {<br>        &quot;anthropic_version&quot;: &quot;bedrock-2023-05-31&quot;,<br>        &quot;max_tokens&quot;: max_tokens,<br>        &quot;messages&quot;: [<br>            {&quot;role&quot;: &quot;user&quot;, &quot;content&quot;: f&quot;Human: {prompt}&quot;}<br>        ],<br>    }<br><br><br>def call_bedrock(prompt: str, max_tokens: int, region: str) -&gt; str:<br>    &quot;&quot;&quot;Invoke Claude 3 via Bedrock and return the full text response.&quot;&quot;&quot;<br>    br = boto3.client(&quot;bedrock-runtime&quot;, region_name=region)<br>    resp = br.invoke_model(<br>        body=json.dumps(construct_body(prompt, max_tokens)),<br>        modelId=MODEL_ID,<br>    )<br>    result = json.loads(resp[&quot;body&quot;].read())<br>    return &quot;&quot;.join(chunk[&quot;text&quot;] for chunk in result[&quot;content&quot;])<br><br><br># ---------- Main workflow ----------<br>def main(env: str = &quot;beta&quot;) -&gt; None:<br>    &quot;&quot;&quot;Render prompts, get completions, and upload results to S3.&quot;&quot;&quot;<br>    region = get_region()<br>    s3 = boto3.client(&quot;s3&quot;, region_name=region)<br><br>    bucket = (<br>        os.getenv(&quot;S3_BUCKET_BETA&quot;)<br>        if env == &quot;beta&quot;<br>        else os.getenv(&quot;S3_BUCKET_PROD&quot;)<br>    )<br>    if not bucket:<br>        raise ValueError(<br>            f&quot;[❌] No S3 bucket defined for environment &#39;{env}&#39;.\n&quot;<br>            f&quot;➡️  Set {&#39;S3_BUCKET_BETA&#39; if env == &#39;beta&#39; else &#39;S3_BUCKET_PROD&#39;}.&quot;<br>        )<br><br>    prefix = BETA_PREFIX if env == &quot;beta&quot; else PROD_PREFIX<br>    pathlib.Path(&quot;outputs&quot;).mkdir(exist_ok=True)<br><br>    for config_path in pathlib.Path(&quot;prompts&quot;).glob(&quot;*.json&quot;):<br>        cfg = json.loads(config_path.read_text())<br><br>        # 1️⃣ Prompt text<br>        tmpl_file = f&quot;prompt_templates/{config_path.stem.replace(&#39;_prompt&#39;, &#39;&#39;)}.txt&quot;<br>        rendered_prompt = render_prompt(tmpl_file, cfg)<br><br>        # 2️⃣ Output filename (render placeholders)<br>        filename_rendered = Template(cfg[&quot;output_file&quot;]).render(**cfg[&quot;variables&quot;])<br><br>        # 3️⃣ Claude 3 completion<br>        completion = call_bedrock(rendered_prompt, max_tokens=300, region=region)<br><br>        # 4️⃣ Write local file<br>        out_file = pathlib.Path(&quot;outputs&quot;) / filename_rendered<br>        out_file.write_text(completion, encoding=&quot;utf-8&quot;)<br><br>        # 5️⃣ Upload original file<br>        s3_key = f&quot;{prefix}{filename_rendered}&quot;<br>        s3.upload_file(<br>            out_file.as_posix(),<br>            bucket,<br>            s3_key,<br>            ExtraArgs={&quot;ContentType&quot;: &quot;text/html&quot;}<br>        )<br>        print(f&quot;✅ Uploaded ➜  s3://{bucket}/{s3_key}&quot;)<br><br>        # 6️⃣ OPTIONAL: also publish as index.html when requested<br>        if cfg.get(&quot;make_index&quot;, False):<br>            index_key = f&quot;{prefix}index.html&quot;<br>            s3.upload_file(<br>                out_file.as_posix(),<br>                bucket,<br>                index_key,<br>                ExtraArgs={&quot;ContentType&quot;: &quot;text/html&quot;}<br>            )<br>            print(f&quot;   ↪️  Also published as s3://{bucket}/{index_key}&quot;)<br><br>if __name__ == &quot;__main__&quot;:<br>    main(os.getenv(&quot;DEPLOY_ENV&quot;, &quot;beta&quot;))<br><br></pre><h3>Step 6: Create GitHub workflow files</h3><p><strong>.github/workflows/on_pull_request.yml</strong></p><p>The .github/workflows/on_pull_request.yml file is a GitHub Actions workflow that automatically runs when someone opens a pull request. It acts like a checkpoint—it pulls the latest code, installs the required tools, and runs the script in a safe test environment (usually the beta setup) to make sure everything works correctly before any changes are merged into the main project. This helps catch errors early and keeps the production site stable.</p><pre>name: Beta Prompt Test<br>on:<br>  pull_request:<br>    branches: <br>    - main<br>    <br>jobs:<br>  beta-run:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with:<br>          python-version: &#39;3.x&#39;<br>      - run: pip install boto3 jinja2<br>      - name: Run prompt processor<br>        env:<br>          DEPLOY_ENV: beta<br>          AWS_REGION: ${{ secrets.AWS_REGION }}<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          S3_BUCKET_BETA: ${{ secrets.S3_BUCKET_BETA }}<br>        run: python process_prompt.py</pre><p><strong>.github/workflows/on_merge.yml</strong></p><p>The .github/workflows/on_merge.yml file is a GitHub Actions workflow that runs automatically whenever changes are merged into the main branch of the project. It sets up the environment, installs dependencies, connects securely to AWS, and runs the main Python script to generate HTML content using Amazon Bedrock. Once the content is created, it uploads the results to the production S3 bucket so the live website is updated without any manual steps.</p><pre>name: Prod Prompt Publish<br>on:<br>  push:<br>    branches: <br>    - main<br>    <br>jobs:<br>  prod-run:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v4<br>      - uses: actions/setup-python@v5<br>        with:<br>          python-version: &#39;3.x&#39;<br>      - run: pip install boto3 jinja2<br>      - name: Run prompt processor<br>        env:<br>          DEPLOY_ENV: prod<br>          AWS_REGION: ${{ secrets.AWS_REGION }}<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          S3_BUCKET_PROD: ${{ secrets.S3_BUCKET_PROD }}<br>        run: python process_prompt.py</pre><h3>Step 7: Add your GitHub Secrets</h3><p>Adding your GitHub Secrets securely stores sensitive information — like your AWS credentials, bucket names, or role ARNs — so your deployment workflow can access them without hardcoding anything into your scripts. This keeps your project safe while allowing GitHub Actions to automatically upload generated content to the correct S3 bucket or call Amazon Bedrock during each deployment.</p><p>Navigate to your repository’s <strong>Settings → Secrets → Actions</strong>, then add the following secrets:</p><ul><li>AWS_ACCESS_KEY_ID</li><li>AWS_SECRET_ACCESS_KEY</li><li>AWS_REGION</li><li>S3_BUCKET_BETA</li><li>S3_BUCKET_PROD</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*8TVe5TmcthoLaTPCkS1unw.png" /></figure><h3>Step 8: Test the Pipeline</h3><ol><li>Commit and push your prompt and template files.</li><li>Open a pull request to a new branch.</li><li>The Beta Prompt Test workflow will run and upload the generated file to the beta S3 site.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*47dIliMuiGPpmORG27IANQ.png" /><figcaption><strong>Pull Request Successful.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*lxDQUAFRhPZXjpTATZ0GTQ.png" /><figcaption><strong>File Uploaded To Beta.</strong></figcaption></figure><p>You can then access the published content using your S3 static (Beta) site URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DJl9hEsxrm4TB4iiJA34Ew.png" /><figcaption><strong>Static Website (Beta) URL.</strong></figcaption></figure><ol><li>Merge the PR to trigger Prod Prompt Publish, which uploads to the prod site.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KWxPwDPKMnOcx_aubryqgg.png" /><figcaption><strong>On Merge Successful.</strong></figcaption></figure><p>You can then access the published content using your S3 static (Prod) site URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KIo0KlWtHBPK9ngGEQSpVQ.png" /><figcaption><strong>Static Website (Prod) URL.</strong></figcaption></figure><h3>Step 9: Add Readme.md</h3><p>This README.md explains:</p><ul><li>How to set up required AWS resources (S3 static website hosting, IAM roles, Bedrock access)</li><li>How to configure GitHub secrets</li><li>How to create or modify prompt templates and variable configs</li><li>How to trigger the workflow via pull requests or merges</li><li>How to view output content in the S3 static website buckets</li></ul><p>The complete Readme.md file can be accessed from the link below: <a href="https://github.com/adolphasg/prompt-deployment-pipeline/blob/main/README.md?plain=1">https://github.com/adolphasg/prompt-deployment-pipeline/blob/main/README.md?plain=1</a></p><h3>Key Outcomes</h3><p>Here are the main results of this project:</p><ol><li>Prompt templates are automatically rendered and deployed with every GitHub commit.</li><li>Real-time content generation is powered by Amazon Bedrock with no infrastructure setup.</li><li>Static site URLs serve the final output instantly via S3.</li><li>Version control is maintained for every prompt, template, and result.</li></ol><h3>Challenges and Solutions I Faced Working On This Project:</h3><p><strong>Challenge 1: Managing Bedrock’s Response Formatting</strong><br> While integrating Amazon Bedrock, one issue I encountered was that the model sometimes returned output with extra wrapping text or inconsistent formatting that didn’t fit cleanly into an HTML structure.<br> <strong>Solution:</strong> I fine-tuned the prompt templates using Jinja2 to give the model clearer context and set a max_tokens limit to keep responses focused and predictable.</p><p><strong>Challenge 2: Filename Conflicts During Deployment</strong><br> During testing, generated HTML files were occasionally overwritten, especially when working with multiple prompts or running the script multiple times.<br> <strong>Solution:</strong> I introduced templated output filenames using variables from each prompt’s config (e.g., the student’s name or version label) to ensure each file had a unique, traceable name.</p><p><strong>Challenge 3: Publishing to the Wrong Environment</strong><br> It was easy to accidentally deploy test content to the production S3 bucket while experimenting locally or pushing to GitHub.<br> <strong>Solution:</strong> I implemented environment-aware logic in both the script and GitHub Actions workflows — automatically routing beta content from feature branches and production content only from the main branch, reducing human error.</p><h3>Summary</h3><p>This project helps Pixel Learning Co. automate their AI content publishing using Amazon Bedrock and GitHub Actions. By structuring prompts and templates inside a GitHub repo and running the entire deployment workflow with pull requests and merges, content generation is now version-controlled, efficient, and production-ready — with zero manual copying and pasting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4a94dc6e6a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨ Image Classification with Amazon Rekognition and GitHub Actions✨]]></title>
            <link>https://medium.com/@adolphasg/image-classification-with-amazon-rekognition-and-github-actions-3401541da498?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3401541da498</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Sat, 14 Jun 2025 07:19:47 GMT</pubDate>
            <atom:updated>2025-06-14T19:31:20.558Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LoowG1Sbvwre13lb1qTc3g.png" /></figure><p>Pixel Learning Co. wants to improve how it handles and organizes its growing collection of educational images. This project introduces a lightweight automation solution that uses Amazon Rekognition to analyze images and GitHub Actions to trigger that process automatically.</p><p><strong>GITHUB REPO FOR THIS PROJECT:</strong> <a href="https://github.com/adolphasg/rekognition-image-pipeline">https://github.com/adolphasg/rekognition-image-pipeline</a></p><h3>Introduction</h3><p>In a visual-first learning platform like Pixel Learning Co., images are used in everything from course content to marketing. To keep up with scale, the company needs a way to tag and categorize images without relying on manual effort.</p><h3>The Challenge</h3><p>Right now, tagging and organizing image content is done manually. It takes time, risks inconsistency, and slows down how fast new content can go live. Without automation, it’s hard to maintain quality and speed.</p><h3>The Solution Approach</h3><p>We are using Amazon Rekognition to detect labels in images automatically, S3 for image storage, DynamoDB to store results, and GitHub Actions to trigger the process. The setup is fully serverless and branch-aware — meaning PRs go to a test table (beta), and merges go to a production table (prod).</p><h3>Prerequisites</h3><p>Before we begin, if you want to create a similar project, make sure you have the following:</p><ul><li>An AWS account with permissions to create and access <strong>S3</strong>, <strong>Rekognition</strong>, and <strong>DynamoDB</strong></li><li>A GitHub repository to host your workflow and images</li><li>Basic understanding of Python and GitHub Actions</li><li>AWS CLI installed and configured (locally or in CloudShell)</li></ul><h3>Step-by-Step Implementation</h3><h3>Step 1: Create an S3 Bucket for Image Uploads</h3><pre>aws s3 mb s3://pixel-rekognition-bucket</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*3fuZ_Vd8x98b2xpC3F6LLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*kC430Rvna2nOBkFkBZuixA.png" /></figure><p>This is where your images will be uploaded for analysis.</p><h3>Step 2: Create Two DynamoDB Tables</h3><pre>aws dynamodb create-table \<br>  --table-name beta_results \<br>  --attribute-definitions AttributeName=filename,AttributeType=S \<br>  --key-schema AttributeName=filename,KeyType=HASH \<br>  --billing-mode PAY_PER_REQUEST</pre><pre>aws dynamodb create-table \<br>  --table-name prod_results \<br>  --attribute-definitions AttributeName=filename,AttributeType=S \<br>  --key-schema AttributeName=filename,KeyType=HASH \<br>  --billing-mode PAY_PER_REQUEST</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sFOrP1UjDzkOt139mKBzlA.png" /></figure><p>beta_results is used for pull requests. prod_results is for merged code.</p><h3>Step 3: Set IAM ROLE &amp; GitHub Repository Secrets</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*7QHkepi0y2wii7C65mAO6g.png" /><figcaption><strong>I’m Role Needed For This Project.</strong></figcaption></figure><p>In your GitHub repo, go to <strong>Settings &gt; Secrets and variables &gt; Actions</strong>, and add these:</p><p>Secret Name Example Value AWS_ACCESS_KEY_ID AKIA************* AWS_SECRET_ACCESS_KEY ************** AWS_REGION us-east-1 S3_BUCKET pixel-rekognition-bucket DYNAMODB_TABLE_BETA beta_results DYNAMODB_TABLE_PROD prod_results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*UiOT3Ly8wL0Q6aSwJVgc9w.png" /></figure><h3>Step 4: Add the Python Script</h3><p>I saved the following script as analyze_image.py in the root of my repository.</p><pre>import os<br>import sys<br>import boto3<br>from decimal import Decimal<br>from datetime import datetime<br><br># Get AWS region<br>region = os.environ.get(&#39;AWS_REGION&#39;, &#39;us-east-1&#39;)<br><br># Initialize AWS clients<br>s3 = boto3.client(&#39;s3&#39;, region_name=region)<br>rekognition = boto3.client(&#39;rekognition&#39;, region_name=region)<br>dynamodb = boto3.resource(&#39;dynamodb&#39;, region_name=region)<br><br># Analyze a single image<br>def analyze_image(file_path, branch):<br>    filename = os.path.basename(file_path)<br>    bucket = os.environ[&#39;S3_BUCKET&#39;]<br>    table_name = os.environ[&#39;DYNAMODB_TABLE_BETA&#39;] if branch == &#39;beta&#39; else os.environ[&#39;DYNAMODB_TABLE_PROD&#39;]<br>    table = dynamodb.Table(table_name)<br><br>    # Upload image to S3<br>    s3.upload_file(file_path, bucket, filename)<br><br>    # Detect labels with Rekognition<br>    with open(file_path, &#39;rb&#39;) as image:<br>        response = rekognition.detect_labels(Image={&#39;Bytes&#39;: image.read()})<br><br>    # Filter and format labels with confidence over 98%<br>    labels = {<br>        label[&#39;Name&#39;]: Decimal(str(label[&#39;Confidence&#39;]))<br>        for label in response[&#39;Labels&#39;]<br>        if label[&#39;Confidence&#39;] &gt;= 98.0<br>    }<br><br>    # Build item to store in DynamoDB<br>    item = {<br>        &#39;filename&#39;: filename,<br>        &#39;labels&#39;: labels,<br>        &#39;date&#39;: datetime.utcnow().strftime(&#39;%Y-%m-%d&#39;),<br>        &#39;time&#39;: datetime.utcnow().strftime(&#39;%H:%M:%S&#39;),<br>        &#39;branch&#39;: branch<br>    }<br><br>    # Write to DynamoDB<br>    table.put_item(Item=item)<br>    print(f&quot;✔ Processed: {filename}&quot;)<br><br># Main entry point<br>if __name__ == &quot;__main__&quot;:<br>    if len(sys.argv) != 2:<br>        print(&quot;Usage: python analyze_image.py &lt;branch&gt;&quot;)<br>        sys.exit(1)<br><br>    branch = sys.argv[1]<br>    image_folder = &quot;images&quot;<br>    supported_extensions = (&#39;.jpg&#39;, &#39;.jpeg&#39;, &#39;.png&#39;)<br><br>    # Loop through images in the folder<br>    for file in os.listdir(image_folder):<br>        if file.lower().endswith(supported_extensions):<br>            file_path = os.path.join(image_folder, file)<br>            analyze_image(file_path, branch)</pre><p><strong>This script:</strong></p><p>This Python script automates our image‑tagging workflow end‑to‑end. For every picture in an <strong>images</strong> folder, it uploads the file to an S3 bucket, asks Amazon Rekognition to identify what’s in the image, keeps only the tags that Rekognition is at least 98 % sure about, and then saves those high‑confidence labels — along with the filename, the deployment branch (beta or prod), and a timestamp — in a DynamoDB table. In short, it turns raw images into clean, trustworthy metadata you can query later, giving you a lightweight, serverless pipeline for accurate image classification and storage.</p><p><strong>Testing Rekognition: Why a Sample Image Matters</strong></p><p>It’s important to test your setup by uploading one of your own images to ensure Amazon Rekognition is correctly detecting and labeling content. This helps verify that your image format, resolution, and subject matter are compatible with Rekognition’s capabilities. Since Rekognition is a backend service, you won’t see visual results or image previews — everything is processed behind the scenes, and only the labels and confidence scores are returned. Testing early confirms that your pipeline is working before analyzing a full batch of images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ad99VvKGu3nPkQjNlKAfoA.png" /><figcaption><strong>Sample Image &amp; Results In Rekognition.</strong></figcaption></figure><h3>Step 5: Create GitHub Action for Pull Requests</h3><p>Create this file: .github/workflows/on_pull_request.yml</p><pre>name: Analyze Image on PR<br><br>on:<br>  pull_request:<br>    branches:<br>      - main<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout Code<br>        uses: actions/checkout@v3<br><br>      - name: Set up Python<br>        uses: actions/setup-python@v4<br>        with:<br>          python-version: &quot;3.10&quot;<br><br>      - name: Install dependencies<br>        run: |<br>          pip install --upgrade boto3 --quiet<br><br>      - name: Run image analysis for PR (Beta)<br>        env:<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          AWS_REGION: ${{ secrets.AWS_REGION }}<br>          S3_BUCKET: ${{ secrets.S3_BUCKET }}<br>          DYNAMODB_TABLE_BETA: ${{ secrets.DYNAMODB_TABLE_BETA }}<br>        run: |<br>           python analyze_image.py beta</pre><h3>Step 6: Create GitHub Action for Merge Events</h3><p>Create this file: .github/workflows/on_merge.yml</p><pre>name: Analyze Image on PROD<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout Code<br>        uses: actions/checkout@v3<br><br>      - name: Set up Python<br>        uses: actions/setup-python@v4<br>        with:<br>          python-version: &quot;3.10&quot;<br><br>      - name: Install dependencies<br>        run: |<br>          pip install --upgrade boto3 --quiet<br><br>      - name: Run image analysis for PR (Prod)<br>        env:<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          AWS_REGION: ${{ secrets.AWS_REGION }}<br>          S3_BUCKET: ${{ secrets.S3_BUCKET }}<br>          DYNAMODB_TABLE_PROD: ${{ secrets.DYNAMODB_TABLE_PROD }}<br>        run: |<br>           python analyze_image.py prod<br><br>           </pre><p>Add a .jpg, .jpegor .png image to the images/ folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*J3mW2hcxBrlo4b4bEi8F2w.png" /><figcaption><strong>Uploaded Different Image Extensions To Ensure Our Script Is Supporting .jpg , jpeg &amp; .png</strong></figcaption></figure><p>Open a pull request. This will trigger the PR workflow and write to beta_results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*g9Flu4Oo2n8RQhZ_kNPiFw.png" /><figcaption><strong>Pull Request.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g9OJ8oQbe3-wDOfzPg6j7Q.png" /><figcaption><strong>Results Written To beta_results in DynamoDB.</strong></figcaption></figure><p>Use the AWS Console, VS Code or CLI to confirm your data is being recorded in the correct DynamoDB table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/736/1*x0ML8_sV2cHD33yiFhVeqQ.png" /><figcaption><strong>Confirmed Data Is Being Recorded In Correct DynamoDB Table (BETA), From Terminal.</strong></figcaption></figure><p>Merge the pull request. This will trigger the merge workflow and write to prod_results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DN8D_jXMO7wCN2i16VigpA.png" /><figcaption><strong>Merge Workflow Triggered.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WuzLs6PdAeeTwqIpQOaIw.png" /><figcaption><strong>Results Written To prod_results in DynamoDB.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*8BntG9vr5A1QNBu9ip8MzA.png" /><figcaption><strong>Confirmed Data Is Being Recorded In Correct DynamoDB Table (PROD), From Terminal.</strong></figcaption></figure><h3>STEP 7: Add README.md</h3><p>This README.md explains:</p><ul><li>How to set up the required AWS resources (S3, Rekognition, DynamoDB tables)</li><li>How to configure GitHub secrets</li><li>How to add and analyze new images</li><li>How to verify that data is logged correctly in the appropriate DynamoDB table</li><li>How to verify that data results were correctly saved in the appropriate S3 folders</li></ul><pre># Pixel Learning - Image Recognition Pipeline<br><br>This project uses Amazon Rekognition to analyze image content, Amazon S3 to store image files, and Amazon DynamoDB to log analysis results. When you upload new images to your GitHub repository, an automated workflow uploads them to AWS, scans them for recognizable objects or scenes, and stores the results in a DynamoDB table.<br><br>---<br><br>## What This Project Does<br><br>1. You place images into the `images/` folder.<br>2. A GitHub Actions workflow is triggered on new commits.<br>3. The workflow runs a Python script that:<br>   - Uploads each image to your S3 bucket<br>   - Uses Rekognition to detect image labels and confidence scores<br>   - Writes those results into a DynamoDB table, along with the image name, upload time, and branch name<br><br>---<br><br>## AWS Setup Instructions<br><br>### 1. Set Up Your S3 Bucket<br><br>- Go to the AWS Management Console<br>- Navigate to **S3** and click **Create bucket**<br>- Give the bucket a unique name <br>- Leave all other settings as default or configure based on your security needs<br><br>### 2. Set Up Your DynamoDB Tables<br><br>You will need two tables—one for testing and one for production.<br><br>Create both tables in the DynamoDB console:<br><br>- Table 1: `beta_results`<br>  - Partition key: `filename` (String)<br><br>- Table 2: `prod_results`<br>  - Partition key: `filename` (String)<br><br>No sort key or secondary indexes are required.<br><br>---<br><br>## GitHub Secrets Configuration<br><br>In your GitHub repository, go to:<br><br>**Settings → Secrets and variables → Actions → New repository secret**<br><br>Add the following secrets:<br><br>| Name                  | Description                                  |<br>|-----------------------|----------------------------------------------|<br>| `AWS_ACCESS_KEY_ID`   | Your AWS access key                          |<br>| `AWS_SECRET_ACCESS_KEY` | Your AWS secret key                        |<br>| `AWS_REGION`          | Your AWS region (e.g., `us-east-1`)         |<br>| `S3_BUCKET`           | Your S3 bucket name                          |<br>| `DYNAMODB_TABLE_BETA` | Name of your beta DynamoDB table (`beta_results`) |<br>| `DYNAMODB_TABLE_PROD` | Name of your production DynamoDB table (`prod_results`) |<br><br>Ensure the secret names match exactly—case matters.<br><br>---<br><br>## How to Add and Analyze New Images<br><br>1. Add image files (JPG or PNG) to the `images/` directory in your repository.<br>2. Push your changes to a GitHub branch:<br>   - Use the `beta` branch to log to `beta_results`<br>   - Use the `main` or `prod` branch to log to `prod_results`<br>3. GitHub Actions will automatically run the analysis pipeline.<br><br>The workflow will:<br>- Upload the new images to your S3 bucket under `rekognition-input/`<br>- Detect the top 10 labels in each image (confidence &gt; 70%)<br>- Log the results in the appropriate DynamoDB table<br><br>---<br><br>## How to Verify Your Results<br><br>To check if everything worked:<br><br>1. Go to the AWS DynamoDB Console<br>2. Select either `beta_results` or `prod_results`<br>3. Click on **Explore Table Items**<br><br>Each entry should look like this:<br><br>```json<br>{<br>  &quot;filename&quot;: &quot;rekognition-input/image123.jpg&quot;,<br>  &quot;labels&quot;: [<br>    {&quot;Name&quot;: &quot;Balloon&quot;, &quot;Confidence&quot;: 98.49},<br>    {&quot;Name&quot;: &quot;Aircraft&quot;, &quot;Confidence&quot;: 98.46}<br>  ],<br>  &quot;timestamp&quot;: &quot;2025-06-01T14:55:32Z&quot;,<br>  &quot;branch&quot;: &quot;beta&quot;<br>}<br><br></pre><h3>Key Outcomes:</h3><p>Here are the main results of this project:</p><ol><li>Automated image classification using Amazon Rekognition without manual labeling.</li><li>GitHub-based CI/CD pipeline that reacts to PRs and merges.</li><li>Environment-aware result logging (beta vs prod) in separate DynamoDB tables.</li><li>Fully serverless architecture — no custom infrastructure or ML models needed.</li></ol><h3>Challenges and Solutions I Faced Working On This Project</h3><p><strong>Challenge 1</strong>: Images not uploading to S3.<br> <strong>Solution</strong>: Check IAM permissions for the GitHub credentials and confirm the bucket name is correct.</p><p><strong>Challenge:</strong> DynamoDB was storing too many label results from Rekognition, including low-confidence predictions that cluttered the data.<br> <strong>Solution:</strong> I added a confidence filter to store only labels with a confidence score above 98%, ensuring cleaner and more accurate results.</p><p><strong>Challenge:</strong> My script was only processing a single image instead of looping through all images in the folder.<br> <strong>Solution:</strong> I updated the script to iterate over each file in the images directory and analyze all supported image types.</p><h3>Project Summary</h3><p>This project introduces a scalable, low-maintenance solution for automating image classification at Pixel Learning Co. By combining Amazon Rekognition, S3, DynamoDB, and GitHub Actions, we’ve created a serverless CI/CD pipeline that improves content organization, reduces manual overhead, and keeps workflows developer-friendly.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3401541da498" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨AI-Powered Audio Course Creation with Amazon Polly and GitHub Actions✨]]></title>
            <link>https://medium.com/@adolphasg/ai-powered-audio-course-creation-with-amazon-polly-and-github-actions-18bf574a6baa?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/18bf574a6baa</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Sun, 01 Jun 2025 23:58:36 GMT</pubDate>
            <atom:updated>2025-06-09T00:59:14.957Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gqReVJOBnneU7MMLzKTCA.png" /></figure><p>This project helps streamline how Pixel Learning Co. delivers accessible audio content for its courses by using AWS services to automate the conversion of text-based content into speech, uploaded directly to an S3 bucket.</p><h3>Introduction</h3><p>Pixel Learning Co. is a digital-first education company committed to accessibility and modern learning solutions. A key focus is making course content more inclusive by offering it in both visual and audio formats.</p><h3>The Challenge</h3><p>Manually converting text to audio is time-consuming and inconsistent. Relying on human narration or uploading audio manually introduces delays and lacks scalability. The team needed a way to convert and upload audio versions of course content automatically.</p><h3>Solution Approach</h3><p>To solve this, we are using Amazon Polly — a text-to-speech (TTS) service — to generate realistic audio from text. A Python script handles conversion and uploads the audio file to Amazon S3. GitHub Actions is used to automate this process every time a developer creates or merges content updates in the repository. The setup requires no servers or manual processing, making it cost-effective and scalable.</p><h3>Prerequisites</h3><p>Before starting, ensure the following:</p><ul><li>An AWS account with permissions to use Polly and S3.</li><li>A GitHub repository to store course content and workflow files.</li><li>Python installed locally (optional for local testing).</li><li>Basic understanding of how GitHub Actions workflows are triggered.</li><li>AWS CLI or console access to set up IAM and S3.</li></ul><h3>Step-by-Step Implementation</h3><h3>Step 1: Create an S3 Bucket</h3><ol><li>Log into the AWS Console.</li><li>Go to the <strong>S3</strong> service.</li><li>Click <strong>Create bucket</strong>.</li><li>Name the bucket (e.g., pixel-learning-audio).</li><li>Keep all default settings or uncheck “Block all public access” if public access is required.</li><li>Click <strong>Create bucket</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*PLA7xiSYxNeC0SI80pT6tg.png" /></figure><h3>Step 2: Create an IAM User for GitHub Access</h3><ol><li>Go to the <strong>IAM</strong> section of the AWS Console.</li><li>Click <strong>Users &gt; Create user</strong>.</li><li>Name the user (e.g., github-polly-user) and select <strong>Programmatic access</strong>.</li><li>Attach the following AWS-managed policies:</li></ol><ul><li>AmazonPollyFullAccess</li><li>AmazonS3FullAccess (or a scoped policy for your bucket)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*-eJ9FnTQzAwrnJoMEafpYA.png" /></figure><p>After creation, save the <strong>Access Key ID</strong> and <strong>Secret Access Key</strong> securely.</p><h3>Step 3: Set Up Your GitHub Repository</h3><p>Create a new repository on GitHub (e.g., polly-audio-pipeline).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*1_PmYhwm4yd7jmVhmPATxw.png" /></figure><p>Clone it locally or use Visual Studio Code to add files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*9APWnvAtv3y7B5wB7jhmEQ.png" /></figure><p>To access my GitHub repository for this project, please click <a href="https://github.com/adolphasg/polly-audio-pipeline">here</a>.</p><h3>Step 4: Add the Text and Python Script</h3><p><strong>File: </strong><strong>speech.txt</strong></p><pre>Welcome to Pixel Learning! This is a demo of our audio course content.<br>We mainly focus on accessibility and automation, with an aim to deliver course content in audio format. <br>Our goal is to better serve users with visual impairments or those who prefer learning by listening.</pre><p><strong>File: </strong><strong>synthesize.py</strong></p><pre>import boto3<br>import os</pre><pre>def synthesize_speech():<br>    # Get AWS credentials and S3 configuration from environment variables<br>    aws_access_key = os.getenv(&quot;AWS_ACCESS_KEY_ID&quot;)<br>    aws_secret_key = os.getenv(&quot;AWS_SECRET_ACCESS_KEY&quot;)<br>    bucket_name = os.getenv(&quot;AWS_S3_BUCKET&quot;)<br>    upload_key = os.getenv(&quot;S3_UPLOAD_KEY&quot;)</pre><pre># Raise an error if any required environment variables are missing<br>    if not all([aws_access_key, aws_secret_key, bucket_name, upload_key]):<br>        raise EnvironmentError(&quot;Missing required environment variables.&quot;)</pre><pre># Create a Polly client for text-to-speech<br>    polly = boto3.client(&#39;polly&#39;, region_name=&#39;us-east-1&#39;,<br>                         aws_access_key_id=aws_access_key,<br>                         aws_secret_access_key=aws_secret_key)</pre><pre># Create an S3 client to upload the audio file<br>    s3 = boto3.client(&#39;s3&#39;,<br>                      aws_access_key_id=aws_access_key,<br>                      aws_secret_access_key=aws_secret_key)</pre><pre># Read the input text from a local file<br>    with open(&quot;speech.txt&quot;, &quot;r&quot;) as f:<br>        text = f.read()</pre><pre># Send text to Polly and get the synthesized speech in MP3 format<br>    response = polly.synthesize_speech(<br>        Text=text,<br>        OutputFormat=&quot;mp3&quot;,<br>        VoiceId=&quot;Joanna&quot;  # You can change the voice if desired<br>    )</pre><pre># Validate response before using it<br>    if &quot;AudioStream&quot; in response:<br>        output_file = &quot;output.mp3&quot;<br>        with open(output_file, &#39;wb&#39;) as f:<br>            f.write(response[&#39;AudioStream&#39;].read())</pre><pre># Upload the generated MP3 file to the specified S3 bucket<br>        s3.upload_file(<br>            Filename=output_file,<br>            Bucket=bucket_name,<br>            Key=upload_key<br>        )<br>    else:<br>        raise Exception(&quot;Polly did not return an audio stream.&quot;)</pre><pre># Run the function if this script is executed directly<br>if __name__ == &quot;__main__&quot;:<br>    synthesize_speech()</pre><h3>Step 5: Create GitHub Actions Workflows</h3><p><strong>File: </strong><strong>.github/workflows/on_pull_request.yml</strong></p><pre>name: On Pull Request</pre><pre>on:<br>  pull_request:<br>    branches:<br>      - main</pre><pre>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout Code<br>        uses: actions/checkout@v3</pre><pre>- name: Set up Python<br>        uses: actions/setup-python@v4<br>        with:<br>          python-version: &quot;3.10&quot;</pre><pre>- name: Install dependencies<br>        run: |<br>          pip install --upgrade boto3 --quiet</pre><pre>- name: Run Synthesis Script<br>        env:<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}<br>          S3_UPLOAD_KEY: polly-audio/beta.mp3<br>        run: |<br>          python synthesize.py</pre><p><strong>File: </strong><strong>.github/workflows/on_merge.yml</strong></p><pre>name: Polly Prod Workflow</pre><pre>on:<br>  push:<br>    branches:<br>      - main</pre><pre>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - name: Checkout Code<br>        uses: actions/checkout@v3</pre><pre>- name: Set up Python<br>        uses: actions/setup-python@v4<br>        with:<br>          python-version: &quot;3.10&quot;</pre><pre>- name: Install dependencies<br>        run: |<br>          pip install boto3</pre><pre>- name: Run Synthesis Script<br>        env:<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>          AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}<br>          S3_UPLOAD_KEY: polly-audio/prod.mp3<br>        run: |<br>          python synthesize.py</pre><h3>Step 6: Add GitHub Secrets</h3><p>In your GitHub repo:</p><ol><li>Navigate to <strong>Settings &gt; Secrets and Variables&gt; Actions</strong>.</li><li>Add the following secrets:</li></ol><p>Secret Name Value AWS_ACCESS_KEY_ID IAM user&#39;s access key AWS_SECRET_ACCESS_KEY IAM user&#39;s secret key S3_BUCKET_NAME Your bucket name and any other repository secrets you may require.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/1*t9F0aJ_GovOtR9hWZNc_bw.png" /><figcaption><strong>Repository Secrets.</strong></figcaption></figure><h3>STEP 7: Add README.md</h3><p>The readme.md below explains the following:</p><ul><li>How to set up AWS credentials and S3 bucket</li><li>How to modify the text</li><li>How to trigger the workflows</li><li>How to verify the uploaded .mp3 files</li></ul><pre># Pixel Learning Audio Pipeline<br><br>## What This Project Does<br><br>Automatically converts course text to speech and uploads it to Amazon S3 using AWS Polly.<br><br>## How to Use<br><br>### 1. Modify Text<br><br>Edit `speech.txt` with your course content.<br><br>### 2. Make a Pull Request<br><br>Create a branch and push your changes. Open a pull request.<br><br>- This will run the `on_pull_request.yml` workflow.<br>- Audio will be uploaded to: `s3://pixel-learning-audio/polly-audio/beta.mp3`<br><br>### 3. Merge to Main<br><br>After review, merge the PR.<br><br>- This runs `on_merge.yml`.<br>- Audio will be uploaded to: `s3://pixel-learning-audio/polly-audio/prod.mp3`<br><br>## AWS Setup<br><br>- Create an IAM user with `AmazonPollyFullAccess` and `AmazonS3FullAccess`.<br>- Create an S3 bucket and note its name.<br>- Save AWS keys as GitHub secrets.<br><br>## Verifying Audio Uploads<br><br>1. Go to your [S3 Console](https://s3.console.aws.amazon.com/s3).<br>2. Open your bucket.<br>3. Navigate to the `polly-audio/` folder.<br>4. Download and listen to `beta.mp3` or `prod.mp3`.   <br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*diU9zWMpXEhDnE_figRxEw.png" /><figcaption><strong>Workflow Successfully Executed.</strong></figcaption></figure><h3>STEP 8: Verifying Audio Uploads</h3><p>1. Go to your [S3 Console](<a href="https://s3.console.aws.amazon.com/s3">https://s3.console.aws.amazon.com/s3</a>).<br>2. Open your bucket.<br>3. Navigate to the `polly-audio/` folder.<br>4. Download and listen to `beta.mp3` or `prod.mp3`.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*bHsoOto3Zy5gkxdkhDUwDw.png" /><figcaption><strong>.mp3 File Created In The Console.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/353/1*g0z7apuEoLtvxWRUJnT6PQ.png" /><figcaption><strong>Screenshot Of The Downloaded .mp3 File.</strong></figcaption></figure><p>To listen to my .mp3 file click <a href="https://drive.google.com/file/d/1TeSubYwHf0Qkl2LjSDpDYImtx1qI74-E/view?usp=drive_link">here</a></p><h3>Key Outcomes</h3><ol><li><strong>Automated Audio Generation</strong>: No manual steps needed for converting text into audio.</li><li><strong>Environment-Specific Uploads</strong>: Beta and production versions are kept separate via workflow logic.</li><li><strong>Serverless &amp; Scalable</strong>: No infrastructure to manage or scale — AWS handles it.</li><li><strong>Improved Accessibility</strong>: Course content becomes instantly more inclusive for users who prefer audio.</li></ol><h3>Challenges and Solutions I faced working on this project</h3><p><strong>Challenge:</strong> My script kept failing because it couldn’t find the S3 bucket — the environment variable was empty due to a missing AWS_ prefix in the name.<br> <strong>Solution:</strong> I fixed it by correctly setting the secret as AWS_S3_BUCKET in GitHub, making sure the script could read the bucket name properly.</p><p><strong>Challenge:</strong> My pull request workflow wasn’t running because I forgot to include the on: trigger that tells GitHub when to start the action.<br> <strong>Solution:</strong> I fixed it by adding on: pull_request to the workflow file so GitHub knows to run the action whenever I open or update a pull request.</p><h3>Summary</h3><p>This project automates the delivery of audio course content by integrating Amazon Polly, S3, and GitHub Actions into a seamless workflow. By focusing on accessibility, automation, and cost-efficiency, it provides a scalable foundation for future expansion into multilingual or multi-voice audio generation — all without requiring manual intervention or infrastructure maintenance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18bf574a6baa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✨Zero Servers, Zero Hassle: Automated Web Deployments!✨]]></title>
            <link>https://medium.com/@adolphasg/zero-servers-zero-hassle-automated-web-deployments-3e1bd93774f5?source=rss-4a804d4f2bb4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e1bd93774f5</guid>
            <dc:creator><![CDATA[Adolphas Gwena]]></dc:creator>
            <pubDate>Tue, 27 May 2025 02:07:17 GMT</pubDate>
            <atom:updated>2025-05-27T02:07:17.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*NON3jeUGyCvT9tX3s0IVOg.png" /></figure><p>We collaborated as a team to complete this project, leveraging our diverse skills to deliver a scalable, serverless web solution with automated deployment and real-time user insights. The project was a joint effort by <a href="https://medium.com/u/df2b1e002ca8">Omawattee Rosario</a><strong>, </strong><a href="https://medium.com/u/76c4f961f214"><strong>Selina Loggins</strong></a><strong> , </strong><a href="https://medium.com/u/1a614bc062f1"><strong>Eric Francis</strong></a><strong> , </strong><a href="https://medium.com/u/c409c8ebe96f"><strong>Isaiah Snead</strong></a><strong> , </strong><a href="https://medium.com/u/c38de887a73e"><strong>Niyi Ayinde</strong></a><strong> , </strong><a href="https://medium.com/u/4a804d4f2bb4"><strong>Adolphas Gwena</strong></a><strong> , and </strong><a href="https://medium.com/u/01bddedaab09"><strong>RONAN LEANO</strong></a><strong>.</strong></p><p><strong>INTRODUCTION</strong></p><p>This project focuses on helping Vitality Sphere, a growing health and wellness company, modernize its website and backend systems using AWS. Our team migrated their website from a traditional server to a faster, more cost-effective solution using S3 and CloudFront. We also built a simple tracking system to monitor user visits and store the data in a secure database. To make future updates easier and more efficient, we implemented an automated deployment pipeline with a built-in approval process. These improvements ensure the website runs smoothly, loads quickly, and is easier to manage as the company grows.</p><p><strong>PROJECT OVERVIEW</strong></p><p>In this project, our team modernized the website infrastructure for Vitality Sphere, a growing health and wellness company, by moving their site from a traditional server setup to a faster, more cost-effective serverless solution using AWS. We migrated the site content to an S3 bucket for static hosting, improved global performance with CloudFront, and connected the company’s domain via Route 53. To help the company understand how users interact with the site, we built an API that logs visit times and pages viewed using Lambda and DynamoDB. Finally, we automated the entire deployment process using an automated script and GitHub repository, including a manual approval step to ensure secure and controlled releases.</p><p><strong>Let’s dive into our project!</strong></p><p>Most cloud projects, including ours, use two environments — <strong>development</strong> and <strong>production</strong> — to keep testing and live user activity separate. The development environment is where we safely build, test, and troubleshoot without affecting the real website. The production environment is the live version users interact with. This setup helps catch problems early and ensures smooth updates. In our project, we’ll use both environments, and while some tasks may be repeated in each, documenting the process once will be enough since the same steps apply to both.</p><p><strong>TASK 1: WEBSITE MIGRATION TO STATIC S3 HOSTING</strong></p><p><strong>Objectives:</strong></p><p>● <strong>Content Migration:</strong> Transfer all website assets — including HTML, CSS, JavaScript, and images — from the existing EC2 instance to an Amazon S3 bucket configured for static website hosting.</p><p>● <strong>CloudFront Integration:</strong> Set up an Amazon CloudFront distribution to deliver the static content, enhancing global performance and reducing latency for end users.</p><p>● <strong>DNS Configuration:</strong> Update DNS settings in Amazon Route 53 to direct the company’s domain to the CloudFront distribution, ensuring seamless access to the newly hosted website.</p><p><strong>CONTENT MIGRATION</strong></p><p>Content migration is the process of moving all website files — like text, images, and code — from one place to another. In our project, it means transferring the website from an old server to a faster, more reliable storage system. This step is important because it helps improve the website’s speed, reduces costs, and makes it easier to manage and update in the future.</p><p>Steps to migrate our content:</p><p>1. <strong>Set Up Permissions:</strong> We made sure our EC2 instance has an IAM role with permission to access the S3 bucket.</p><p>2. <strong>Connect via SSM:</strong> We used AWS Systems Manager Session Manager to open a secure terminal session to our EC2 instance — no need for SSH keys.</p><p>3. <strong>Copy Files:</strong> In the terminal, we ran a command to copy your website files from the EC2 storage to the S3 bucket using the AWS CLI, like:<br> <strong>aws s3 cp /path/to/files s3://your-bucket-name/ — recursive</strong></p><p>Here’s the command broken down simply:</p><p><strong>aws s3 cp /path/to/files s3://your-bucket-name/ — recursive</strong></p><p><strong>· aws s3 cp</strong> — This tells AWS to <strong>copy files</strong> using the S3 service.</p><p><strong>· /path/to/files</strong> — This is the folder on your EC2 instance where your website files are stored.</p><p><strong>· s3://your-bucket-name/</strong> — This is the address of your S3 bucket where you want to copy the files.</p><p><strong>· — recursive</strong> — This means <strong>copy everything inside the folder</strong>, including all subfolders and files.</p><p>So, the whole command says:</p><p>“Copy all files and folders from this location on the EC2 instance to this S3 bucket.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*1mnEgR6LzTnwZzZWZHfvwA.png" /></figure><p>4. <strong>Verify Transfer:</strong> We checked the S3 bucket in the AWS Console to confirm all files were uploaded successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*JPsaV0QeveChf9v4cnNOUw.png" /></figure><p><strong>STATIC WEBSITE HOSTING</strong></p><p><strong>1. Create an S3 Bucket</strong></p><p>● Named the bucket exactly like our subdomain (e.g., dev.yourdomain.com). In our case we had already created our buckets before we carried out content migration in the previous step.</p><p>● Enabled <strong>“Static website hosting”</strong> in the bucket settings.</p><p>● Uploaded our website files (HTML, CSS, images, etc.).</p><p><strong>2. Set Bucket Permissions</strong></p><p>● Added a <strong>bucket policy</strong> to allow the public to <strong>read</strong> the files (so the website is viewable).</p><p>● Example of a policy that allows everyone to view content:</p><pre>· {<br>· &quot;Effect&quot;: &quot;Allow&quot;,<br>· &quot;Principal&quot;: &quot;*&quot;,<br>· &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>· &quot;Resource&quot;: &quot;arn:aws:s3:::dev.yourdomain.com/*&quot;<br>· }</pre><p><strong>3. Created a Record in Route 53</strong></p><h4>Created a Hosted Zone</h4><p>1. Accessed <strong>Route 53</strong> in the AWS Console.</p><p>2. Clicked <strong>Hosted Zones</strong> from the menu.</p><p>3. Clicked <strong>Create Hosted Zone</strong>.</p><p>4. Entered our <strong>domain name</strong> (e.g., dev.yourdomain.com).</p><p>5. Chose a <strong>Public Hosted Zone</strong>.</p><p>6. Clicked <strong>Create Hosted Zone</strong>.</p><h4>How we Created a Record for our S3 Website</h4><p>1. In the new hosted zone, click <strong>“Create record”</strong>.</p><p>2. <strong>Leave the name blank</strong> (uses the zone’s root name).</p><p>3. Set <strong>Record Type</strong> to <strong>A — Routes traffic to IPv4 address</strong>.</p><p>4. <strong>Turn on Alias</strong> (toggle it to “Yes”).</p><p>5. For <strong>Alias Target</strong>, choose <strong>Alias to S3 website endpoint</strong>.</p><p>6. Choose the <strong>AWS Region</strong> where your S3 bucket was created.</p><p>7. Pick the <strong>S3 website endpoint</strong> from the list.</p><p>8. Use <strong>Simple Routing Policy</strong>.</p><p>9. Turn on <strong>Evaluate Target Health</strong> (toggle to “Yes”).</p><p>10. Click <strong>Create Record</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Q2S31i9-uyRUKc1Fg2lc7A.png" /></figure><p>Now, our domain points to our static website hosted on S3!</p><p><strong>4. Testing our Website</strong></p><p>● Go to<strong> </strong><a href="http://dev.yourdomain.com/"><strong>http://dev.yourdomain.com</strong></a> in the browser.</p><p>● Your static website should now load using the AWS-provided URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*SEU4p5rIs0dz4UcZ6gmLIQ.png" /></figure><p><strong>CLOUDFRONT INTEGRATION</strong></p><p>Connecting CloudFront to Route 53 in our project ensures users are directed to the nearest AWS edge location, which means faster load times and a better experience when accessing the website. It also improves security by making the S3 bucket private and only accessible through CloudFront, reducing the risk of unauthorized access. Additionally, this setup simplifies domain management and makes the infrastructure more reliable and scalable as traffic grows.</p><h4>Integrate S3 with CloudFront</h4><p><strong>Go to CloudFront<br> </strong>Open CloudFront in the AWS Console and click <strong>“Create Distribution”</strong>.</p><p><strong>Choose S3 as Origin<br> </strong>In the “Origin domain” field, select your <strong>S3 bucket</strong> (the one with your website content).</p><p><strong>Set Up Secure Access (OAC)</strong></p><p>○ Choose <strong>Origin Access Control (OAC)</strong> to keep your bucket private.</p><p>○ Click <strong>“Create new OAC”</strong>, leave settings as is, and <strong>create it</strong>.</p><p>○ <strong>Important:</strong> You’ll get a <strong>bucket policy</strong> from CloudFront — copy and <strong>add it to your S3 bucket permissions</strong> later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Dbpnb7OEDd1oCbNiMZ5p3A.png" /></figure><p><strong>Redirect HTTP to HTTPS<br> </strong>Under Default Cache Behavior, choose <strong>“Redirect HTTP to HTTPS”</strong> to force secure connections.</p><p><strong>Use Default Caching Settings<br> </strong>Keep <strong>“Cache key and origin requests”</strong> as recommended.<br> <em>(Tip: If testing updates, you can temporarily set caching to “Disabled” later.)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*x56QIiakIfu7O42ePW6tlQ.png" /></figure><p><strong>Skip WAF for Now<br> </strong>Leave <strong>Web Application Firewall (WAF)</strong> disabled for now.</p><p><strong>Set Best Performance Option<br> </strong>In the settings, choose <strong>“Use all edge locations”</strong> for best global performance.</p><p><strong>Add Custom Domain (Optional)</strong></p><p>○ Add your domain (e.g., <a href="http://www.vitalitysphere.com)/">www.vitalitysphere.com)</a> as an <strong>Alternate Domain Name</strong>.</p><p>○ Choose your <strong>SSL certificate</strong> for HTTPS (must be requested in <strong>AWS Certificate Manager</strong> beforehand).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*kWu1PjqaSqYWdVroFtMynA.png" /></figure><p><strong>Set Default Page<br> </strong>Enter index.html as the <strong>Default Root Object</strong> so it shows when users visit the homepage.</p><p><strong>Create the Distribution<br> </strong>Click <strong>“Create Distribution”</strong>.<br> It will take a few minutes to deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*BAvkPXojx1m_-VQevus2fA.png" /></figure><p><strong>Test Your Website<br> </strong>Once deployed, open the <strong>CloudFront domain name</strong> in your browser. Your site should load faster and more securely!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*cM9AhT2-bcCHdNcj74niVg.png" /></figure><p>This setup helps deliver your website faster to users around the world by caching it in <strong>CloudFront edge locations</strong> closest to them.</p><p><strong>DNS CONFIGURATION</strong></p><p>DNS configuration is important for this project because it makes sure that when users type in the website’s name, they’re automatically directed to the correct location — like our CloudFront distribution or S3-hosted site. This setup ensures the website is easy to access, loads quickly, and works reliably, while also allowing us to control and update where traffic goes without changing the domain name users see.</p><p><strong>Steps</strong> to update our DNS in <strong>Route 53</strong> and point our domain to our <strong>CloudFront distribution</strong>, while meeting security best practices:</p><h4>Connect Domain to CloudFront Using Route 53</h4><p>1. <strong>Go to Route 53<br> — </strong>In the AWS Console, open <strong>Route 53</strong>.</p><p>2. <strong>Open Hosted Zones<br> — </strong>Click on <strong>“Hosted zones”</strong>, then select your domain (e.g., <a href="http://pod-milestone2-stack-1747065639.vitality.luitprojects.com/">pod-milestone2-stack-1747065639.vitality.luitprojects.com</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*azBX1rVDOhYVv492BA83MQ.png" /></figure><p>3. <strong>Create a New Record<br> — </strong>Click <strong>“Create record”</strong>.</p><p>4. <strong>Set Record Type to A (Alias)</strong></p><p>- Leave the <strong>Record name</strong> blank (it points to the root domain).</p><p>- Choose <strong>Type: A — IPv4 address</strong>.</p><p>- Set <strong>Alias: Yes</strong>.</p><p>5. <strong>Route to CloudFront</strong></p><p>- For <strong>“Route traffic to”</strong>, select <strong>Alias to CloudFront distribution</strong>.</p><p>- Choose your CloudFront domain (e.g., d25wzsuphpaywt.cloudfront.net).</p><p>6. <strong>Save the Record<br> — </strong>Click <strong>“Create records”</strong> to finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Vx-kf5m1iJZNXRKj9M5qiQ.png" /></figure><p>This step ensures that users visiting our production domain are routed through <strong>CloudFront</strong> for faster, more secure content delivery, while our S3 bucket stays private and protected.</p><h4>Task 2: Created an API for User Interaction Tracking</h4><h4>Objective</h4><h4>To track user interactions on the website by creating an API that triggers a Lambda function. Create an API using Amazon API Gateway that triggers an AWS Lambda function each time a user visits a page.</h4><p>This function records the <strong>timestamp</strong> and <strong>page</strong> visited by users, and stores the information in a <strong>DynamoDB table</strong>.</p><h4>What Was Implemented?</h4><h4>1. Lambda Function</h4><p>● <strong>Function Name:</strong> vitalityspherelambdaweb</p><p>● <strong>Purpose:</strong> Captures the page visited and the current timestamp, then stores this data in DynamoDB.</p><p>● <strong>Technologies Used:</strong> Python, Boto3, UUID, AWS Lambda</p><p><strong>Function Configuration Overview:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*6P9s_Wg9YjC-k1pYwAJ8fg.png" /><figcaption><em>Figure 1.1: Lambda Function Configuration (vitalityspherelambdaweb)</em></figcaption></figure><p><strong>Ensured the Lambda Handler is set correctly.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*00GG7cf9Kyq6HkuaquCUVw.png" /></figure><p>When we created a Lambda function, AWS Lambda needs to know where to start execution. It looks for a handler function, which is the first function Lambda should call when it is invoked.</p><p>● <strong>Filename</strong>: This tells AWS Lambda which file contains the code that should be executed.</p><p>● <strong>Handler Function</strong>: This tells Lambda exactly which function within the file should be executed first.</p><p>By configuring the handler in the format <strong>&lt;filename&gt;.&lt;handler-function&gt;</strong>, we are telling AWS Lambda exactly where to find your code’s entry point. So in our case we configured the handler to be <strong>vitality_sphere.lambda_handler.</strong></p><p><strong>Lambda Handler Function Code:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*oiLxBPS0arntw-g0Y6f9KQ.png" /><figcaption><em>Figure 1.2: Documents the actual logic that posts timestamp and page data to DynamoDB</em></figcaption></figure><p>When working in a team or deploying code across different environments (development, staging, production), this explicit configuration of the handler ensures everyone knows exactly where to look for the Lambda entry point. It makes it easier to understand the architecture, especially in larger projects.</p><h4>User Interaction API — Lambda Function</h4><p><strong>Objective:</strong></p><p>Capture and store timestamp and page visit data whenever a user interacts with the website.</p><p><strong>What We Did:</strong></p><p>We developed an AWS Lambda function named vitalityspherelambdaweb using Python. The function is triggered by an API Gateway POST request. When a user visits a page, the frontend sends a request to the API, which invokes this Lambda function. The function:</p><ol><li>Parses the JSON body of the request.</li><li>Extracts the page field.</li><li>Generates a UTC timestamp.</li><li>Writes both values to a DynamoDB table named vitalitysphere-visitor-data.</li></ol><p>This allows us to track user interactions (what page they visited and when) in real time and store them reliably for analytics and auditing purposes.</p><h4>2. API Gateway</h4><p>● <strong>Resource Path:</strong> /visitor</p><p>● <strong>Method:</strong> POST</p><p>● <strong>Integration:</strong> Directly triggers the Lambda function</p><p>● <strong>CORS Enabled:</strong> Yes (to allow browser-based interaction)</p><h4>Figure 2.1: API Gateway /production POST Method Integration with Lambda</h4><p>This screenshot illustrates how the <strong>API Gateway</strong> is configured to handle <strong>POST</strong> requests on the /production route. These requests are passed as Lambda proxy integrations to the vitalityspherelambdaweb function in <strong>us-east-2</strong>.</p><p><strong>What this shows</strong>:</p><p>● The integration type is Lambda.</p><p>● Lambda proxy integration is enabled.</p><p>● The flow is: <strong>Client ➝ Method Request ➝ Integration Request ➝ Lambda ➝ Integration Response ➝ Method Response ➝ Client</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Fq6jk6ubG8HL7Eo_RVrMcA.png" /><figcaption>Figure 2.1: API Gateway /production POST Method Integration with Lambda</figcaption></figure><h4>API Gateway POST Method Response Configuration</h4><p>This screenshot shows the method response setup for the POST route. It confirms that:</p><p>● A 200 OK status is configured.</p><p>● The response body returns a Content-Type of application/json.</p><p>● No additional headers are defined.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*Kk1HvM_0w1KfHkr5Pxhbsg.png" /><figcaption><em>Figure 2.2 API Gateway /visitor POST method integration with Lambda</em></figcaption></figure><p><strong>API Post Test</strong></p><p>Using the <strong>curl</strong> command in terminal we tested the API invoke URL to see if it would successfully record the TimeStamp and Page data to our DynamoDB table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*a7oNNTLup96iSEJThJmNvQ.png" /><figcaption><em>Figure 2.3 API Post tests to retrieve data and ensure it is posting to DynamoDB</em></figcaption></figure><p>_________________________________________________________________</p><p><strong>Data Storage:</strong> Capture and store user interaction data — specifically, the timestamp and page URL — in a <strong>DynamoDB Table</strong> for future analysis and insight into user behavior.</p><p>We created a DynamoDB table as specified to show <strong>Partition Key: TimeStamp (String Value) and Sort Key: Page (String Value) </strong>to support efficient data retrieval and scaling capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*zdDKGxoooZZu_nVYpPXfeg.png" /><figcaption><em>Figure 1 vitalitysphere-visitor-data table created.</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*CcXGctTBU7-8spgQd1VqlA.png" /><figcaption><em>Figure 1.1 output to the DynamoDB table after running the API test.</em></figcaption></figure><p>In the above image you can see that the returned data time and page matched the API tests we ran in the terminal. This means that the API is sending back data to our DynamoDB table successfully.</p><p><strong>TASK 3: Implement an automated script for Automated Deployment.</strong></p><p><strong>Objectives:</strong></p><p>● <strong>Source Code Management:</strong> Utilized Github as the centralized repository for managing and version-controlling the website’s source code.</p><p>● <strong>Build and Deployment Automation:</strong> Configured automated script to automate the building, testing, and deployment of website updates.</p><p>● <strong>Approval Workflow:</strong> A manual approval step in the deployment pipeline to ensure changes are reviewed and authorized before reaching the production environment via GitHub workflow.</p><p>To begin the process of configuring for automated deployment we started by creating a<em> </em><strong><em>GitHub</em></strong><em> </em><strong><em>Repository</em></strong>, which is a secure and scalable way for us to store and manage our source code for files for the website. Once the repository is created we created a specific .sh file, in this case it was <strong><em>deploy.sh</em></strong>, which we used to create a new Git commit and push it to the centralized Git repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*GsAgnpiavneb6kyc-QLTDA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*idydo3zm2MFpjPloer_Z5Q.png" /></figure><p>Once the repository wss set up, we added the CloudFront ARN to the scripts, both the Dev and Prod., so the script knows where to point to for the website.</p><p>We manually added our files that are located in the S3 bucket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*fkgLTR-nXqw6i4XGsbr6Mw.png" /></figure><p>Although we did not use CodePipeline, CodeCommit, or CodeBuild, we successfully created a serverless website for our client by using a deployment script and storing our code in a GitHub repository as the source for our dev environment.</p><p><strong>Task 4: Security and Compliance</strong></p><p><strong>We conducted a detailed security review of this project’s AWS Configurations, focusing on the following, please see below:</strong></p><p><strong>When using my AWS user account, we did not have Permissions because we tried to review and save the defined policies attached to the user, and got Access denied; this happens when we hit the Review and save button. See below:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*uzrPlQ4W64NAHZE5z9Pvlw.png" /></figure><p><strong>My AWS user could NOT update any policy, see the screenshot below:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*DouReTlB43W_5ihDpISQ8Q.png" /></figure><p><strong>IAM Access Analyzer is not available for the AWS user, see below screenshot:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*mnE3OCl8wl1wE58wQ5acWA.png" /></figure><p><strong>AWS CloudTrail is not available for the user:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*h3SpFQ3GrHt4z559zx0eAg.png" /></figure><p><strong>My AWS user does not have access to the AWS Config. See below:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*fkBMJRhHF2hAtuYJ9JQg_g.png" /></figure><p><strong>Amazon S3 Bucket</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*cjY8Si-ZqIWbu5U420-Yqg.png" /></figure><p><strong>The policy above is a good example of implementing least privilege by carefully restricting access to the Amazon S3 bucket. Here’s a clear breakdown of what this policy does:</strong></p><p><strong>Policy Analysis:</strong></p><p><strong>Purpose: </strong>Allows CloudFront to access specific objects within our S3 bucket.</p><p><strong>Actions Permitted:</strong></p><p>Only allows the s3:GetObject action, meaning CloudFront can only read objects from our bucket. No other operations (like modifying or deleting objects) are permitted.</p><p><strong>Resources Affected:</strong></p><p>Restricts access exclusively to objects (/*) within the specified bucket:</p><p>arn:aws:s3:::pod-milestone2-stack-1747065639.vitality.luitprojects.com/*</p><p><strong>Principal:</strong></p><p>Access is explicitly limited to AWS CloudFront service:</p><p>cloudfront.amazonaws.com</p><p><strong>Condition </strong>(Additional Restriction):</p><p>Further limits requests to come only from the specified CloudFront distribution:</p><p>arn:aws:cloudfront::440744217842:distribution/E1WKZR1LGS2JKL</p><p><strong>Security Implications</strong> (Least Privilege):</p><p><strong>Highly Restrictive:</strong> This policy strictly limits who (CloudFront) can access our bucket, what they can do (only GetObject), and from where (only a specified CloudFront distribution).</p><p><strong>Prevents Unauthorized Access:</strong> Blocks unauthorized services or users from directly accessing the bucket or performing unintended actions.</p><p><strong>Reduces Risk Exposure:</strong> Significantly decreases the likelihood of data breaches or misconfiguration incidents.</p><p><strong>Recommendations:</strong></p><p><strong>Maintain and Regularly Review: </strong>Periodically verify and audit the CloudFront distribution and S3 bucket configurations to ensure accuracy and security.</p><p><strong>Logging and Monitoring:</strong> Enable CloudFront and S3 access logs for additional monitoring and troubleshooting capabilities.</p><p><strong>Version Control:</strong> Store IAM policies like this in version control systems for tracking, auditing, and rollback purposes.</p><p>Overall, the policy above effectively implements the principle of least privilege, aligning with AWS security best practices.</p><p><strong>Least Privilege in AWS</strong></p><p>The principle of least privilege is a critical security practice in AWS that involves granting users, applications, or services only the minimum permissions necessary to perform their tasks. This approach minimizes potential security risks by reducing the chance that sensitive resources are accidentally or maliciously accessed or modified.</p><p><strong>Key Concepts:</strong></p><p><strong>Limit Permissions:</strong> Assigns only permissions needed to perform a specific task.</p><p><strong>Fine-Grained Access Control:</strong> Uses AWS Identity and Access Management (IAM) policies to precisely control what actions users and services can perform.</p><p><strong>Role-Based Access:</strong> Uses IAM roles instead of directly granting permissions to users or services, making permission management more manageable and secure.</p><p><strong>Best Practices in AWS:</strong></p><p><strong>Start with Minimal Permissions:</strong> Gradually expand permissions only as needed.</p><p><strong>Regularly Review Permissions:</strong> Periodically audit IAM policies to remove unnecessary permissions.</p><p><strong>Utilize AWS Managed Policies Wisely:</strong> Prefer custom policies tailored to your specific requirements over overly permissive AWS-managed policies.</p><p><strong>Use IAM Roles for Applications:</strong> Avoid embedding AWS credentials in application code; instead, assign roles with appropriate permissions.</p><p><strong>AWS Tools Supporting Least Privilege:</strong></p><p><strong>IAM Access Analyzer:</strong> Identifies permissions that are overly permissive or unused.</p><p><strong>AWS CloudTrail:</strong> Monitors AWS activity, helping identify required permissions.</p><p><strong>AWS Config:</strong> Tracks configuration changes and helps maintain compliance.</p><p>Implementing least privilege enhances security, reduces risks, and supports compliance with industry standards and regulatory requirements.</p><p><strong>Compliance:</strong></p><p>Adheres to the predefined naming conventions and standards for all AWS resources to ensure consistency, traceability, and compliance with internal policies.</p><p>See below:</p><p><strong>Vitality Sphere AWS Resource Naming Convention Format:<br> All AWS resources must adhere to the following naming convention format:</strong></p><p>&lt;VitalitySphere&gt;-&lt;Environment&gt;-&lt;ResourceType&gt;-&lt;UniqueID&gt;-&lt;FunctionalDescriptio&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*fdPMe_dwCh00TiENX8hf6A.png" /></figure><p><strong>FINAL STEP:</strong></p><p><strong>Decommissioning EC2 Instance<br> </strong>After making the modifications to DNS to have the web traffic pointed to the CloudFront distribution instead of the S3 bucket or the EC2 instance, the next step was to decommission the EC2 instance by stopping the EC2 instance, not terminating.</p><p>Once the EC2 instance has been stopped, we would have to make sure that the website is still functional. If it is shown that the website is down after the server has been stopped, then immediately restore it to a functional state.</p><p>As an industry standard, it would be advisable to keep the server powered off at least for a period of 60 days to ensure that no files or settings are needing to be retrieved from it. If after that period of time there have been no activity or requests made of that server, selecting that instance and terminating it, or there could be a case to keep it as a backup in the event that something happens with the serverless deployment.</p><p><strong>SUMMARY</strong></p><p>By completing these tasks, Vitality Sphere will transition to a modern, cloud-native infrastructure that is not only more scalable and cost-effective but also optimized for performance and future growth. Hosting the website on Amazon S3 and delivering content via CloudFront will significantly reduce load times and operational costs, while eliminating the need to maintain traditional server infrastructure. The integration of a user interaction API provides real-time insights into how users engage with the website, enabling data-driven improvements to content and services.</p><p>Finally, the use of an automated script streamlines the deployment process by reducing manual effort, minimizing errors, and ensuring consistent and repeatable updates across environments. Together, these improvements position Vitality Sphere for long-term success in a competitive digital landscape.</p><p><strong>FINAL DELIVERABLES</strong></p><p>● <strong>Static Website Hosting:</strong> A fully migrated and operational website hosted on Amazon S3, distributed globally via CloudFront, and accessible through a custom domain configured in Route 53.</p><p>● <strong>User Interaction Tracking:</strong> A functioning API that captures and stores user interaction data in DynamoDB via a Lambda function.</p><p>● <strong>Automated Script:</strong>An automated script that simplifies deployment by reducing manual effort, minimizing errors, and ensuring consistent updates across environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e1bd93774f5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>